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

support for async dspy.LM #1786

Open
JacksonCakes opened this issue Nov 11, 2024 · 6 comments
Open

support for async dspy.LM #1786

JacksonCakes opened this issue Nov 11, 2024 · 6 comments

Comments

@JacksonCakes
Copy link

Hi, does Dspy currently support the asynchronous version of dspy.LM?
which might be equivalent to the following:

async def call_llm(prompt: str,file:str, cur_type: str):
    headers = {"Content-Type": "application/json"}
    res_args = {
        "model": LLM_NAME,
        "messages": [
            {
                "role": "user",
                "content": prompt,
            },
        ],
        "temperature": 0,
    }
    async with httpx.AsyncClient(timeout=httpx.Timeout(LLM_TIMEOUT)) as client:
        response = await client.post(LLM_URL, json=res_args, headers=headers)
    response = response.json()["choices"][0]["message"]["content"].strip()
    
task = [call_llm(x) for x in item] 
result = asyncio.gather(*task)
@okhat
Copy link
Collaborator

okhat commented Nov 11, 2024

Hey @JacksonCakes ! See #1734 and let us know what you think!

@JacksonCakes
Copy link
Author

Thanks!! That's exact what I am looking for!

@okhat
Copy link
Collaborator

okhat commented Nov 12, 2024

Wonderful. May I ask what you need async for? We're considering the right form of async to merge.

@JacksonCakes
Copy link
Author

Any LLM call that can be run in parallel would be super useful here! A great use case from my side is finding the right SQL table based on user queries from a huge database. With so many tables, compress every table metadata into single prompt or doing this sequentially just isn't practical

@okhat
Copy link
Collaborator

okhat commented Nov 13, 2024

Would you find this #1690 useful? We're probably going to go with that.

@JacksonCakes
Copy link
Author

Yup, I think that would work too! But I am just curious why multi-threaded is preferred over #1734 ?

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

No branches or pull requests

2 participants