-
Notifications
You must be signed in to change notification settings - Fork 53
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
async function call not working (uvicorn, fastapi) #71
Comments
it works without |
Hello @ccomkhj, thank you for your interest in our work! If this is a bug report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you. |
@ccomkhj thanks! I had some issues also running sync client in async context, I'll try to investigate this, in the meantime prefer using the async client in async context: from embedbase_client.client import EmbedbaseAsyncClient
import yaml
from fastapi import FastAPI
with open("credential/embedbase.yaml", "r") as f:
API = yaml.safe_load(f)
embedbase_key = API['EMBEDBASE_KEY']
embedbase_url = API['EMBEDBASE_URL']
app = FastAPI()
@app.get("/")
async def root():
client = EmbedbaseAsyncClient(embedbase_url, embedbase_key)
await client.dataset('basil_greenhouse').search(
'how to grow basil?', limit=5)
return {"message": "Hello World"} If this does not work, feel free to use the REST API directly: import requests
top_k = limit or 5
search_url = f"https://api.embedbase.xyz/v1/basil_greenhouse/search"
data = requests.post(
search_url, headers={"Authorization": f"Bearer {embedbase_key}"}, json={"query": "how to grow basil", "top_k": 5}
)
data = res.json() Please let me know if it solves your issue :) |
thanks for the quick response! it works! 👍 |
I want to combine multiple results. This works with sync
error with async at
Is there a feature to search from multiple dataset? |
Hey 👋 You need to use async def foo()
return "bar"
print(foo())
# coroutine
print(await foo())
# bar So in your context: results_recipe = await client.dataset(recipe_id).search(
question, limit=6
)
results_farm = await client.dataset(farm_id).search(
question, limit=1
)
results = results_recipe + results_farm An optimization allowed by async would be to run requests in parallel using [results_recipe, results_farm] = await asyncio.gather(
*[
client.dataset(recipe_id).search(
question, limit=6
) ,
client.dataset(farm_id).search(
question, limit=1
)
]
)
# ... This way the code would be twice faster. Would you use a simpler API, like: results = await client.dataset(recipe_id, farm_id).search(question, limit=6) ? I guess here it does not make sense because you want a limit of |
Thank you for the ready-to run example. @louis030195 It would be so helpful in my use-case
max_token of 2100, 300, 300, 300 are applied to each dataset. |
Curious, why you're using multiple datasets? Is there a reason you didn't put everything in a single dataset? |
Two reasons. @hotkartoffel
|
@ccomkhj I see, makes sense! |
🐛 Bug Report
async function call not working (uvicorn, fastapi)
Code sample
Environment
Screenshots
📈 Expected behavior
Return list of datasets
📎 Additional context
Using FastAPI
The text was updated successfully, but these errors were encountered: