Skip to content

Async version in aisuite.AsyncClient class #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

kapulkin
Copy link

@kapulkin kapulkin commented Feb 4, 2025

Async LLM calls support proposal

Description

I added aisuite.AsyncClient interface with async version of llm calls and implemented support for a few providers: OpenAI, Anthropic, Mistral, Fireworks. Async tests for supported providers are written.

Demand

Async calls are necessary for industrial development and have huge adoption in python libraries like FastAPI. It is easy and popular way to run llm calls in parallel with asyncio.gather() function.

The PR addresses request #61

Changes Made

Class aisuite.AsyncClient is added. The new method def chat_completions_create_async(self, model, messages) is added into Provider class. Default implementation throws NotImplementedError.

Checklist

  • Tests are written
  • Pre-commit hooks pass

@kapulkin
Copy link
Author

kapulkin commented Feb 5, 2025

@ksolo @foxty @jeffxtang @joaomdmoura can you, please, review the PR?

@kapulkin
Copy link
Author

I synchronized async client version by adding tool and thinking support.

@rohitprasad15, review, please, the PR.

@antoniomuzzolini
Copy link

Hey, found a bug! If you try to set providers

import aisuite_async as ai
providers = {"openai": {"api_key": custom_api_key}}
llm = ai.AsyncClient(provider_configs=providers)

the provider is istantiated by Client, thus not async, and then throws error 'cause chat_completions_create_async method doesn't exists.

I think that overriding the _initialize_providers method setting is_async=True should be enough.

@kapulkin
Copy link
Author

kapulkin commented Apr 4, 2025

@antoniomuzzolini Thank you for the report!

I made more general update by introducing BaseClient class which avoids copying and pasting. Check, please, the new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants