Find answers from the community

Updated 3 months ago

What type is returned for:

What type is returned for:

Plain Text
res = query_engine.query("My foobar?")


As a non-python dev, decided to do a quick restfyk API for llama index using fastapi.

Plain Text
def query(question: Union[str, None] = None):
  ...

  return { "answer": res }


πŸ‘† This causes an error ERROR: Exception in ASGI application, which I believe is related to the fn query return type as tested by hard typing "some random text" as res.

Did a quick check by doing a print for res

Plain Text
print(res)


Where I can assert a valid text response. Does anyone know what I need to look at?
L
P
4 comments
The Response object is returned

Or if you've enabled streaming, a StreamingResponse
You probably meant to do this

return { "answer": str(res) }
@Logan M Got it! Thanks a lot for your time and my apologies as I'd have to learn python to avoid question like these, but picked this stack just for helping out knowing some other programming languages. Thank you!
Worked indeed! Much appreciated!
Add a reply
Sign up and join the conversation on Discord