AI Personal Learning
and practical guidance

Aisuite: Unified OpenAI interface style calls multiple big models, fast model switching and comparison testing

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.


aisuite: unified interface to invoke multiple generative AI models, convenient model switching and comparison testing-1

 

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.

AI Easy Learning

The layman's guide to getting started with AI

Help you learn how to utilize AI tools at a low cost and from a zero base.AI, like office software, is an essential skill for everyone. Mastering AI will give you an edge in your job search and half the effort in your future work and studies.

View Details>
May not be reproduced without permission:Chief AI Sharing Circle " Aisuite: Unified OpenAI interface style calls multiple big models, fast model switching and comparison testing

Chief AI Sharing Circle

Chief AI Sharing Circle specializes in AI learning, providing comprehensive AI learning content, AI tools and hands-on guidance. Our goal is to help users master AI technology and explore the unlimited potential of AI together through high-quality content and practical experience sharing. Whether you are an AI beginner or a senior expert, this is the ideal place for you to gain knowledge, improve your skills and realize innovation.

Contact Us
en_USEnglish