Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Exchange - a uniform python SDK for message generation with LLMs
[!NOTE] Before you can run this example, you need to setup an API key with
export OPENAI_API_KEY=your-key-here
from exchange import Exchange, Message, Tool
from exchange.providers import OpenAiProvider
def word_count(text: str):
"""Get the count of words in text
Args:
text (str): The text with words to count
"""
return len(text.split(" "))
ex = Exchange(
provider=OpenAiProvider.from_env(),
model="gpt-4o",
system="You are a helpful assistant.",
tools=[Tool.from_function(word_count)],
)
ex.add(Message.user("Count the number of words in this current message"))
# The model sees it has a word count tool, and should use it along the way to answer
# This will call all the tools as needed until the model replies with the final result
reply = ex.reply()
print(reply.text)
# you can see all the tool calls in the message history
print(ex.messages)
exchange has a plugin mechanism to add support for additional providers and moderators. If you need a provider not supported here, we'd be happy to review contributions. But you can also consider building and using your own plugin.
To create a Provider
plugin, subclass exchange.provider.Provider
. You will need to
implement the complete
method. For example this is what we use as a mock in our tests.
You can see a full implementation example of the OpenAiProvider. We
also generally recommend implementing a from_env
classmethod to instantiate the provider.
class MockProvider(Provider):
def __init__(self, sequence: List[Message]):
# We'll use init to provide a preplanned reply sequence
self.sequence = sequence
self.call_count = 0
def complete(
self, model: str, system: str, messages: List[Message], tools: List[Tool]
) -> Message:
output = self.sequence[self.call_count]
self.call_count += 1
return output
Then use python packaging's entrypoints to register your plugin.
[project.entry-points.'exchange.provider']
example = 'path.to.plugin:ExampleProvider'
Your plugin will then be available in your application or other applications built on exchange through:
from exchange.providers import get_provider
provider = get_provider('example').from_env()
FAQs
a uniform python SDK for message generation with LLMs
We found that ai-exchange demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.