Skip to content
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

AsyncLM #2004

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

AsyncLM #2004

wants to merge 4 commits into from

Conversation

itay1542
Copy link
Contributor

@itay1542 itay1542 commented Jan 1, 2025

Hey @okhat, thanks for this repository its really super.

One step towards proper async functionality is having an AsyncLM, similar to how OpenAI has their Client and AsyncClient.
I know this PR has some code duplication issues, however I think its better to have a separate async LM rather than handling both sync and async in the LM's __call__.

This PR complements #1988 and lays a foundation for async modules to use async lm client

from dspy.utils import with_callbacks


class AsyncLM(LM):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add ABC and decorate?


class AsyncLM(LM):
@with_callbacks
def __call__(self, prompt=None, messages=None, **kwargs) -> Awaitable:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be async to allow for the caller to use this in an async fashion, no?

async def __call__(...)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, and callbacks should be handled async. Check out #1734 if you need something that works for you in the meantime

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.

4 participants