General Introduction
aisuite is a simple, unified interface designed to make it easy for developers to invoke services from multiple generative AI providers. With an interface similar to OpenAI, aisuite makes it easier to interact with the most popular LLMs (Large Language Models) and seamlessly switch and test responses from different providers without changing code. Currently supported providers include OpenAI, Anthropic, Azure, Google, AWS, Groq, Mistral, HuggingFace and Ollama.
Aisuite allows you to select a "provider: model" by simply changing a string, e.g. openai:gpt-4o, anthropic:claude-3-5-sonnet-20241022, ollama:ollama3.1:8b, etc.
Function List
- Unified interface: invoke multiple generative AI providers through a standardized interface.
- Multi-provider support: OpenAI, Anthropic, Azure, Google, AWS, Groq, Mistral, HuggingFace and Ollama are supported.
- Easy to install: Provides simple installation commands with the option to install the base package or packages that include specific providers.
- Environment Variable Configuration: Supports configuring API keys via environment variables for easy management and use.
- Sample Code: Provide rich sample code to help users get started quickly.
- Open source project: the code is open source, allowing users to freely use, modify and distribute.
Using Help
mounting
To install aisuite, you have the option of installing just the base package, or installing a package that includes a specific provider. Below are the installation commands:
- Install the base package:
pip install aisuite
- Install the package containing the Anthropic library:
pip install 'aisuite[anthropic]'
- Install all provider libraries:
pip install 'aisuite[all]'
configure
To start using aisuite, you need to set the API key for the provider you intend to use. The API key can be set via an environment variable, or the configuration can be passed in the aisuite client constructor. The following is an example of setting an environment variable:
export OPENAI_API_KEY="your-openai-api-key"
export ANTHROPIC_API_KEY="your-anthropic-api-key"
usage example
Below is a short example of using aisuite to generate a chat completion response:
import aisuite as ai
client = ai.Client()
models = ["openai:gpt-4o", "anthropic:claude-3-5-sonnet"]
messages = [
{"role": "system", "content": "Respond in Pirate English."}, {"role": "user".
{"role": "user", "content": "Tell me a joke."}, ]
}, {"role": "user", "content": "Tell me a joke.
for model in models: response = client.chat.completions
response = client.chat.completions.create(
model=model, messages=messages, temperature=0.75
)
print(response.choices[0].message.content)
In the above example, the model name uses the format :
aisuite will call the appropriate provider based on the provider value, passing the correct parameters.