gpt-computer-assistant icon indicating copy to clipboard operation
gpt-computer-assistant copied to clipboard

[BUG] web api example with agent in document doesn't work

Open gaord opened this issue 9 months ago • 4 comments

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:

Image

Desktop (please complete the following information):

  • OS: [macOS 13]
  • Upsonic Version [0.49.0]
  • Python Version [3.12]

gaord avatar Mar 24 '25 15:03 gaord

Hey it seems working right now. Can you try with our latest version:

https://github.com/Upsonic/Upsonic/releases/tag/v0.50.5

onuratakan avatar Apr 02 '25 12:04 onuratakan

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

gaord avatar Apr 03 '25 11:04 gaord

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}

onuratakan avatar Apr 03 '25 12:04 onuratakan

Can you verify?

onuratakan avatar Apr 03 '25 12:04 onuratakan