Skip to content

Commit

Permalink
Merge branch 'main' into Shulin-Zhang/add-tongyi
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangshulin committed Jan 28, 2025
2 parents 714317a + bd6b23f commit cdf9ff4
Show file tree
Hide file tree
Showing 60 changed files with 5,521 additions and 2,071 deletions.
13 changes: 12 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,21 @@ GOOGLE_REGION=
GOOGLE_PROJECT_ID=

# Hugging Face token
HUGGINGFACE_TOKEN=
HF_TOKEN=

# Fireworks
FIREWORKS_API_KEY=

# Together AI
TOGETHER_API_KEY=

# WatsonX
WATSONX_SERVICE_URL=
WATSONX_API_KEY=
WATSONX_PROJECT_ID=

# xAI
XAI_API_KEY=

# Sambanova
SAMBANOVA_API_KEY=
4 changes: 2 additions & 2 deletions .github/workflows/run_pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install
poetry install --all-extras --with test
- name: Test with pytest
run: poetry run pytest
run: poetry run pytest -m "not integration"

9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@ __pycache__/
env/
.env
.google-adc

# Testing
.coverage

# pyenv
.python-version

.DS_Store
**/.DS_Store
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# aisuite

[![PyPI](https://img.shields.io/pypi/v/aisuite)](https://pypi.org/project/aisuite/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/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.
OpenAI, Anthropic, Azure, Google, AWS, Groq, Mistral, HuggingFace Ollama, Sambanova and Watsonx.
To maximize stability, `aisuite` uses either the HTTP endpoint or the SDK for making calls to the provider.

## Installation
Expand All @@ -21,11 +22,13 @@ pip install aisuite
```

This installs aisuite along with anthropic's library.

```shell
pip install 'aisuite[anthropic]'
```

This installs all the provider-specific libraries

```shell
pip install 'aisuite[all]'
```
Expand All @@ -41,12 +44,14 @@ You can use tools like [`python-dotenv`](https://pypi.org/project/python-dotenv/
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.

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

Use the python client.

```python
import aisuite as ai
client = ai.Client()
Expand All @@ -67,6 +72,7 @@ for model in models:
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.
Expand All @@ -82,6 +88,7 @@ aisuite is released under the MIT License. You are free to use, modify, and dist
If you would like to contribute, please read our [Contributing Guide](https://github.com/andrewyng/aisuite/blob/main/CONTRIBUTING.md) and join our [Discord](https://discord.gg/T6Nvn8ExSb) 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
Expand All @@ -91,20 +98,24 @@ We follow a convention-based approach for loading providers, which relies on str
- 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:
#### Examples

- **Hugging Face**:
The provider class should be defined as:

```python
class HuggingfaceProvider(BaseProvider)
```

in providers/huggingface_provider.py.

- **OpenAI**:
The provider class should be defined as:

```python
class OpenaiProvider(BaseProvider)
```

in providers/openai_provider.py

This convention simplifies the addition of new providers and ensures consistency across provider implementations.
2 changes: 2 additions & 0 deletions aisuite/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .client import Client
from .framework.message import Message
from .utils.tool_manager import Tools
1 change: 1 addition & 0 deletions aisuite/framework/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .provider_interface import ProviderInterface
from .chat_completion_response import ChatCompletionResponse
from .message import Message
6 changes: 5 additions & 1 deletion aisuite/framework/choice.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from aisuite.framework.message import Message
from typing import Literal, Optional


class Choice:
def __init__(self):
self.message = Message()
self.finish_reason: Optional[Literal["stop", "tool_calls"]] = None
self.message = Message(
content=None, tool_calls=None, role="assistant", refusal=None
)
24 changes: 20 additions & 4 deletions aisuite/framework/message.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
"""Interface to hold contents of api responses when they do not conform to the OpenAI style response"""
"""Interface to hold contents of api responses when they do not confirm to the OpenAI style response"""

from pydantic import BaseModel
from typing import Literal, Optional

class Message:
def __init__(self):
self.content = None

class Function(BaseModel):
arguments: str
name: str


class ChatCompletionMessageToolCall(BaseModel):
id: str
function: Function
type: Literal["function"]


class Message(BaseModel):
content: Optional[str]
tool_calls: Optional[list[ChatCompletionMessageToolCall]]
role: Optional[Literal["user", "assistant", "system"]]
refusal: Optional[str]
Loading

0 comments on commit cdf9ff4

Please sign in to comment.