Skip to main content

Uniform access layer for LLMs

Project description

aisuite

Code style: black

Simple, unified interface to multiple Generative AI providers.

aisuite makes it easy for developers to use multiple LLM through a standardized interface. Using an interface similar to OpenAI's, aisuite makes it easy to interact with the most popular LLMs and compare the results. It is a thin wrapper around python client libraries, and allows creators to seamlessly swap out and test responses from different LLM providers without changing their code. Today, the library is primarily focussed on chat completions. We will expand it cover more use cases in near future.

Currently supported providers are - OpenAI, Anthropic, Azure, Google, AWS, Groq, Mistral, HuggingFace and Ollama. To maximize stability, aisuite uses either the HTTP endpoint or the SDK for making calls to the provider.

Installation

You can install just the base aisuite package, or install a provider's package along with aisuite.

This installs just the base package without installing any provider's SDK.

pip install aisuite

This installs aisuite along with anthropic's library.

pip install aisuite[anthropic]

This installs all the provider-specific libraries

pip install aisuite[all]

Set up

To get started, you will need API Keys for the providers you intend to use. You'll need to install the provider-specific library either separately or when installing aisuite.

The API Keys can be set as environment variables, or can be passed as config to the aisuite Client constructor. You can use tools like python-dotenv or direnv to set the environment variables manually. Please take a look at the examples folder to see usage.

Here is a short example of using aisuite to generate chat completion responses from gpt-4o and claude-3-5-sonnet.

Set the API keys.

export OPENAI_API_KEY="your-openai-api-key"
export ANTHROPIC_API_KEY="your-anthropic-api-key"

Use the python client.

import aisuite as ai
client = ai.Client()

models = ["openai:gpt-4o", "anthropic:claude-3-5-sonnet-20240620"]

messages = [
    {"role": "system", "content": "Respond in Pirate English."},
    {"role": "user", "content": "Tell me a joke."},
]

for model in models:
    response = client.chat.completions.create(
        model=model,
        messages=messages,
        temperature=0.75
    )
    print(response.choices[0].message.content)

Note that the model name in the create() call uses the format - <provider>:<model-name>. aisuite will call the appropriate provider with the right parameters based on the provider value. For a list of provider values, you can look at the directory - aisuite/providers/. The list of supported providers are of the format - <provider>_provider.py in that directory. We welcome providers adding support to this library by adding an implementation file in this directory. Please see section below for how to contribute.

For more examples, check out the examples directory where you will find several notebooks that you can run to experiment with the interface.

License

aisuite is released under the MIT License. You are free to use, modify, and distribute the code for both commercial and non-commercial purposes.

Contributing

If you would like to contribute, please read our Contributing Guide and join our Discord server!

Adding support for a provider

We have made easy for a provider or volunteer to add support for a new platform.

Naming Convention for Provider Modules

We follow a convention-based approach for loading providers, which relies on strict naming conventions for both the module name and the class name. The format is based on the model identifier in the form provider:model.

  • The provider's module file must be named in the format <provider>_provider.py.
  • The class inside this module must follow the format: the provider name with the first letter capitalized, followed by the suffix Provider.

Examples:

  • Hugging Face: The provider class should be defined as:

    class HuggingfaceProvider(BaseProvider)
    

    in providers/huggingface_provider.py.

  • OpenAI: The provider class should be defined as:

    class OpenaiProvider(BaseProvider)
    

    in providers/openai_provider.py

This convention simplifies the addition of new providers and ensures consistency across provider implementations.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aisuite-0.1.6.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aisuite-0.1.6-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file aisuite-0.1.6.tar.gz.

File metadata

  • Download URL: aisuite-0.1.6.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for aisuite-0.1.6.tar.gz
Algorithm Hash digest
SHA256 0937372a4aa369ad63fa2350cf58780fdad6914e651e97ca7f6192a517e933b7
MD5 b52eefcdedc8f2ef0b39477ebf3c3ce0
BLAKE2b-256 39cf3eebce1294ed5b20bb824e6a4089be5f0b81d1f37299a2119dfc03f0340b

See more details on using hashes here.

File details

Details for the file aisuite-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: aisuite-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for aisuite-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 d564a6dc4b7e8dd1d2c86f38331e41ef30b9a2adce9e13640232aed5ea049673
MD5 e9f1c50c83bce90ae05fb8008829205b
BLAKE2b-256 6267a9a13cb66991e15fd9c3505b6b85cab775e60a40124221484dc1b4628556

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page