[BUG] web api example with agent in document doesn't work
Describe the bug send request to web api as example in document hang forever:
from fastapi import FastAPI
from upsonic import Agent, Task
from upsonic.client.tools import Search
app = FastAPI()
agent = Agent(
"Customer Support",
company_url="https://your-company.com",
company_objective="To provide excellent customer service and support",
)
@app.get("/ask")
async def ask(query: str):
task = Task(query, tools=[Search])
response = agent.do(task)
return {"response": response}
Screenshots hang like this:
Desktop (please complete the following information):
- OS: [macOS 13]
- Upsonic Version [0.49.0]
- Python Version [3.12]
Hey it seems working right now. Can you try with our latest version:
https://github.com/Upsonic/Upsonic/releases/tag/v0.50.5
just checked, not fixed yet. Anyway the following code change can work to fix the hang:
response = await asyncio.wait_for(
asyncio.to_thread(lambda: agent.do(task)),
timeout=60.0 # 30 seconds timeout
)
hope it helps
Okkkey, ı found it.
We need to run do_async and await at async fastapi servers. The problem is our default approach. Our defaults are base on sync calls. I will think about it.
from fastapi import FastAPI
from upsonic import Agent, Task
from upsonic.client.tools import Search
app = FastAPI()
agent = Agent(
"Customer Support",
company_url="https://your-company.com",
company_objective="To provide excellent customer service and support",
)
@app.get("/ask")
async def ask(query: str):
task = Task(query, tools=[Search])
response = await agent.do_async(task)
return {"response": response}
Can you verify?