Skip to content

Allow tool async to sync conversion #8332

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 1 commit into
base: main
Choose a base branch
from

Conversation

chenmoneygithub
Copy link
Collaborator

Because DSPy evaluator and optimizer doesn't support async yet, we provide a backdoor to execute async tools in sync mode so that optimizer and evaluator can still work.

We make a specific flag allow_tool_async_sync_conversion to enable the conversion to avoid unintended conversion happens for the user.

With this PR the following code works:

import asyncio

import dspy
from dspy.datasets import HotPotQA

dspy.configure(lm=dspy.LM("openai/gpt-4o-mini"), allow_tool_async_sync_conversion=True)


async def search_wikipedia(query: str) -> list[str]:
    await asyncio.sleep(0.01)
    results = dspy.ColBERTv2(url="http://20.102.90.50:2017/wiki17_abstracts")(query, k=3)
    return [x["text"] for x in results]


trainset = [x.with_inputs("question") for x in HotPotQA(train_seed=2024, train_size=500).train]
react = dspy.ReAct("question -> answer", tools=[search_wikipedia])

tp = dspy.MIPROv2(metric=dspy.evaluate.answer_exact_match, auto="light", num_threads=24)
optimized_react = tp.compile(react, trainset=trainset)

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.

1 participant