Skip to content

Commit 545e3e8

Browse files
authored
Merge branch 'andrewyng:main' into main
2 parents fde02b2 + 793b386 commit 545e3e8

32 files changed

Lines changed: 8727 additions & 193 deletions

README.md

Lines changed: 111 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,53 @@
1-
# aisuite
1+
# aisuite
22

33
[![PyPI](https://img.shields.io/pypi/v/aisuite)](https://pypi.org/project/aisuite/)
44
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
55

6-
Simple, unified interface to multiple Generative AI providers.
6+
`aisuite` is a lightweight Python library that provides a **unified API for working with multiple Generative AI providers**.
7+
It offers a consistent interface for models from *OpenAI, Anthropic, Google, Hugging Face, AWS, Cohere, Mistral, Ollama*, and others—abstracting away SDK differences, authentication details, and parameter variations.
8+
Its design is modeled after OpenAI’s API style, making it instantly familiar and easy to adopt.
79

8-
`aisuite` makes it easy for developers to interact with multiple Gen-AI services through a standardized interface. Using an interface similar to OpenAI's, `aisuite` supports **chat completions** and **audio transcription**, making it easy to work with the most popular AI providers and compare results. It is a thin wrapper around python client libraries, and allows creators to seamlessly swap out and test different providers without changing their code.
10+
`aisuite` lets developers build and **run LLM-based or agentic applications across providers** with minimal setup.
11+
While it’s not a full-blown agents framework, it includes simple abstractions for creating standalone, lightweight agents.
12+
It’s designed for low learning curve — so you can focus on building AI systems, not integrating APIs.
913

10-
All of the top providers are supported.
11-
Sample list of supported providers include - Anthropic, AWS, Azure, Cerebras, Cohere, Google, Groq, HuggingFace, Ollama, Mistral, OpenAI, Sambanova, Watsonx and others.
14+
---
1215

13-
To maximize stability, `aisuite` uses either the HTTP endpoint or the SDK for making calls to the provider.
16+
## Key Features
17+
18+
`aisuite` is designed to eliminate the complexity of working with multiple LLM providers while keeping your code simple and portable. Whether you're building a chatbot, an agentic application, or experimenting with different models, `aisuite` provides the abstractions you need without getting in your way.
19+
20+
* **Unified API for multiple model providers** – Write your code once and run it with any supported provider. Switch between OpenAI, Anthropic, Google, and others with a single parameter change.
21+
* **Easy agentic app or agent creation** – Build multi-turn agentic applications using a single parameter `max_turns`. No need to manually manage tool execution loops.
22+
* **Pass Tool calls easily** – Pass real Python functions instead of JSON specs; aisuite handles schema generation and execution automatically.
23+
* **MCP tools** – Connect to MCP-based tools without writing boilerplate; aisuite handles connection, schema and execution seamlessly.
24+
* **Modular and extensible provider architecture** – Add support for new providers with minimal code. The plugin-style architecture makes extensions straightforward.
25+
26+
---
1427

1528
## Installation
1629

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

19-
This installs just the base package without installing any provider's SDK.
32+
Install just the base package without any provider SDKs:
2033

2134
```shell
2235
pip install aisuite
2336
```
2437

25-
This installs aisuite along with anthropic's library.
38+
Install aisuite with a specific provider (e.g., Anthropic):
2639

2740
```shell
2841
pip install 'aisuite[anthropic]'
2942
```
3043

31-
This installs all the provider-specific libraries
44+
Install aisuite with all provider libraries:
3245

3346
```shell
3447
pip install 'aisuite[all]'
3548
```
3649

37-
## Set up
50+
## Setup
3851

3952
To get started, you will need API Keys for the providers you intend to use. You'll need to
4053
install the provider-specific library either separately or when installing aisuite.
@@ -76,52 +89,44 @@ for model in models:
7689

7790
Note that the model name in the create() call uses the format - `<provider>:<model-name>`.
7891
`aisuite` will call the appropriate provider with the right parameters based on the provider value.
79-
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.
92+
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 to add support to this library by adding an implementation file in this directory. Please see section below for how to contribute.
8093

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

83-
## Adding support for a provider
84-
85-
We have made easy for a provider or volunteer to add support for a new platform.
86-
87-
### Naming Convention for Provider Modules
88-
89-
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`.
90-
91-
- The provider's module file must be named in the format `<provider>_provider.py`.
92-
- The class inside this module must follow the format: the provider name with the first letter capitalized, followed by the suffix `Provider`.
93-
94-
#### Examples
96+
---
9597

96-
- **Hugging Face**:
97-
The provider class should be defined as:
98+
## Chat Completions
9899

99-
```python
100-
class HuggingfaceProvider(BaseProvider)
101-
```
100+
The chat API provides a high-level abstraction for model interactions. It supports all core parameters (`temperature`, `max_tokens`, `tools`, etc.) in a provider-agnostic way.
102101

103-
in providers/huggingface_provider.py.
104-
105-
- **OpenAI**:
106-
The provider class should be defined as:
107-
108-
```python
109-
class OpenaiProvider(BaseProvider)
110-
```
102+
```python
103+
response = client.chat.completions.create(
104+
model="google:gemini-pro",
105+
messages=[{"role": "user", "content": "Summarize this paragraph."}],
106+
)
107+
print(response.choices[0].message.content)
108+
```
111109

112-
in providers/openai_provider.py
110+
`aisuite` standardizes request and response structures so you can focus on logic rather than SDK differences.
113111

114-
This convention simplifies the addition of new providers and ensures consistency across provider implementations.
112+
---
115113

116-
## Tool Calling
114+
## Tool Calling & Agentic apps
117115

118116
`aisuite` provides a simple abstraction for tool/function calling that works across supported providers. This is in addition to the regular abstraction of passing JSON spec of the tool to the `tools` parameter. The tool calling abstraction makes it easy to use tools with different LLMs without changing your code.
119117

120118
There are two ways to use tools with `aisuite`:
121119

122120
### 1. Manual Tool Handling
123121

124-
This is the default behavior when `max_turns` is not specified.
122+
This is the default behavior when `max_turns` is not specified. In this mode, you have full control over the tool execution flow. You pass tools using the standard OpenAI JSON schema format, and `aisuite` returns the LLM's tool call requests in the response. You're then responsible for executing the tools, processing results, and sending them back to the model in subsequent requests.
123+
124+
This approach is useful when you need:
125+
- Fine-grained control over tool execution logic
126+
- Custom error handling or validation before executing tools
127+
- The ability to selectively execute or skip certain tool calls
128+
- Integration with existing tool execution pipelines
129+
125130
You can pass tools in the OpenAI tool format:
126131

127132
```python
@@ -200,156 +205,108 @@ When `max_turns` is specified, `aisuite` will:
200205
3. Send the tool results back to the LLM
201206
4. Repeat until the conversation is complete or max_turns is reached
202207

203-
In addition to `response.choices[0].message`, there is an additional field `response.choices[0].intermediate_messages`: which contains the list of all messages including tool interactions used. This can be used to continue the conversation with the model.
208+
In addition to `response.choices[0].message`, there is an additional field `response.choices[0].intermediate_messages` which contains the list of all messages including tool interactions used. This can be used to continue the conversation with the model.
204209
For more detailed examples of tool calling, check out the `examples/tool_calling_abstraction.ipynb` notebook.
205210

206-
## Audio Transcription
211+
### Model Context Protocol (MCP) Integration
207212

208-
> **Note:** Audio transcription support is currently under development. The API and features described below are subject to change.
213+
`aisuite` natively supports **MCP**, a standard protocol that allows LLMs to securely call external tools and access data. You can connect to MCP servers—such as a filesystem or database—and expose their tools directly to your model.
214+
Read more about MCP here - https://modelcontextprotocol.io/docs/getting-started/intro
209215

210-
`aisuite` provides audio transcription (speech-to-text) with the same unified interface pattern used for chat completions. Transcribe audio files across multiple providers with consistent code.
216+
Install aisuite with MCP support:
211217

212-
### Basic Usage
213-
214-
```python
215-
import aisuite as ai
216-
client = ai.Client()
218+
```shell
219+
pip install 'aisuite[mcp]'
220+
```
217221

218-
# Transcribe an audio file
219-
result = client.audio.transcriptions.create(
220-
model="openai:whisper-1",
221-
file="meeting.mp3"
222-
)
223-
print(result.text)
222+
You'll also need an MCP server. For example, to use the filesystem server:
224223

225-
# Switch providers without changing your code
226-
result = client.audio.transcriptions.create(
227-
model="deepgram:nova-2",
228-
file="meeting.mp3"
229-
)
230-
print(result.text)
224+
```shell
225+
npm install -g @modelcontextprotocol/server-filesystem
231226
```
232227

233-
### Common Parameters
228+
There are two ways to use MCP tools with aisuite:
234229

235-
Use OpenAI-style parameters that work across all providers:
230+
#### Option 1: Config Dict Format (Recommended for Simple Use Cases)
236231

237232
```python
238-
result = client.audio.transcriptions.create(
239-
model="openai:whisper-1",
240-
file="interview.mp3",
241-
language="en", # Specify audio language
242-
prompt="Technical discussion about AI", # Context hints
243-
temperature=0.2 # Sampling temperature (where supported)
244-
)
245-
```
233+
import aisuite as ai
246234

247-
These parameters are automatically mapped to each provider's native format.
235+
client = ai.Client()
236+
response = client.chat.completions.create(
237+
model="openai:gpt-4o",
238+
messages=[{"role": "user", "content": "List the files in the current directory"}],
239+
tools=[{
240+
"type": "mcp",
241+
"name": "filesystem",
242+
"command": "npx",
243+
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/directory"]
244+
}],
245+
max_turns=3
246+
)
248247

249-
### Provider-Specific Features
248+
print(response.choices[0].message.content)
249+
```
250250

251-
Each provider offers unique capabilities you can access directly:
251+
#### Option 2: Explicit MCPClient (Recommended for Advanced Use Cases)
252252

253-
**OpenAI Whisper:**
254253
```python
255-
result = client.audio.transcriptions.create(
256-
model="openai:whisper-1",
257-
file="speech.mp3",
258-
response_format="verbose_json", # Get detailed metadata
259-
timestamp_granularities=["word"] # Word-level timestamps
260-
)
261-
```
254+
import aisuite as ai
255+
from aisuite.mcp import MCPClient
262256

263-
**Deepgram:**
264-
```python
265-
result = client.audio.transcriptions.create(
266-
model="deepgram:nova-2",
267-
file="meeting.mp3",
268-
punctuate=True, # Auto-add punctuation
269-
diarize=True, # Identify speakers
270-
sentiment=True, # Sentiment analysis
271-
summarize=True # Auto-summarization
257+
# Create MCP client once, reuse across requests
258+
mcp = MCPClient(
259+
command="npx",
260+
args=["-y", "@modelcontextprotocol/server-filesystem", "/path/to/directory"]
272261
)
273-
```
274262

275-
**Google Speech-to-Text:**
276-
```python
277-
result = client.audio.transcriptions.create(
278-
model="google:default",
279-
file="call.mp3",
280-
enable_automatic_punctuation=True,
281-
enable_speaker_diarization=True,
282-
diarization_speaker_count=2
263+
# Use with aisuite
264+
client = ai.Client()
265+
response = client.chat.completions.create(
266+
model="openai:gpt-4o",
267+
messages=[{"role": "user", "content": "List the files"}],
268+
tools=mcp.get_callable_tools(),
269+
max_turns=3
283270
)
284-
```
285271

286-
**Hugging Face:**
287-
```python
288-
result = client.audio.transcriptions.create(
289-
model="huggingface:openai/whisper-large-v3",
290-
file="presentation.mp3",
291-
return_timestamps="word" # Word-level timestamps
292-
)
272+
print(response.choices[0].message.content)
273+
mcp.close() # Clean up
293274
```
294275

295-
### Streaming Transcription
276+
For detailed usage (security filters, tool prefixing, and `MCPClient` management), see [docs/mcp-tools.md](docs/mcp-tools.md).
277+
For detailed examples, see `examples/mcp_tools_example.ipynb`.
296278

297-
For real-time or large audio files, use streaming:
279+
---
298280

299-
```python
300-
async def transcribe_stream():
301-
stream = client.audio.transcriptions.create_stream_output(
302-
model="deepgram:nova-2",
303-
file="long_recording.mp3"
304-
)
305-
306-
async for chunk in stream:
307-
print(chunk.text, end="", flush=True)
308-
if chunk.is_final:
309-
print() # New line for final results
281+
## Extending aisuite: Adding a Provider
310282

311-
# Run the async function
312-
import asyncio
313-
asyncio.run(transcribe_stream())
314-
```
283+
New providers can be added by implementing a lightweight adapter. The system uses a naming convention for discovery:
315284

316-
### Supported Providers
285+
| Element | Convention |
286+
| --------------- | ---------------------------------- |
287+
| **Module file** | `<provider>_provider.py` |
288+
| **Class name** | `<Provider>Provider` (capitalized) |
317289

318-
- **OpenAI**: `whisper-1`
319-
- **Deepgram**: `nova-2`, `nova`, `enhanced`, `base`
320-
- **Google**: `default`, `latest_long`, `latest_short`
321-
- **Hugging Face**: `openai/whisper-large-v3`, `openai/whisper-tiny`, `facebook/wav2vec2-base-960h`, `facebook/wav2vec2-large-xlsr-53`
290+
Example:
322291

323-
### Installation
292+
```python
293+
# providers/openai_provider.py
294+
class OpenaiProvider(BaseProvider):
295+
...
296+
```
324297

325-
Install transcription providers:
298+
This convention ensures consistency and enables automatic loading of new integrations.
326299

327-
```shell
328-
# Install with specific provider
329-
pip install 'aisuite[openai]' # For OpenAI Whisper
330-
pip install 'aisuite[deepgram]' # For Deepgram
331-
pip install 'aisuite[google]' # For Google Speech-to-Text
332-
pip install 'aisuite[huggingface]' # For Hugging Face models
300+
---
333301

334-
# Install all providers
335-
pip install 'aisuite[all]'
336-
```
302+
## Contributing
337303

338-
Set API keys:
304+
Contributions are welcome. Please review the [Contributing Guide](https://github.com/andrewyng/aisuite/blob/main/CONTRIBUTING.md) and join our [Discord](https://discord.gg/T6Nvn8ExSb) for discussions.
339305

340-
```shell
341-
export OPENAI_API_KEY="your-openai-api-key"
342-
export DEEPGRAM_API_KEY="your-deepgram-api-key"
343-
export GOOGLE_APPLICATION_CREDENTIALS="path/to/credentials.json"
344-
export HF_TOKEN="your-huggingface-token"
345-
```
346-
347-
For more examples and advanced usage, check out `examples/asr_example.ipynb`.
306+
---
348307

349308
## License
350309

351-
aisuite is released under the MIT License. You are free to use, modify, and distribute the code for both commercial and non-commercial purposes.
352-
353-
## Contributing
310+
Released under the **MIT License** — free for commercial and non-commercial use.
354311

355-
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!
312+
---

0 commit comments

Comments
 (0)