Run two API requests asynchronously, but display results one at a time #1957
-
Hello community, I'm hoping you can help me understand how to adapt my code. I am working on a chatbot in Flask using the OpenAI API. Because of speed issues, I wanted to use websockets and gevent to run two API requests in parallel, rather than one after the oher.
What happens now: What I want to happen: Here are some snippets of my code to show you how it looks now. I tried to leave out anything irrelevant:
# In my routes.py
Finally, the html that receives the emits
Thank you in advance for any advice that you have for me! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You are using a test request context, which only makes sense in unit tests. Probably not what's causing your problem, but that needs to be removed.
You also need to make sure you don't block when you connect to these 3rd party APIs. Besides that I'm not sure what else to suggest. |
Beta Was this translation helpful? Give feedback.
You are using a test request context, which only makes sense in unit tests. Probably not what's causing your problem, but that needs to be removed.
You also need to make sure you don't block when you connect to these 3rd party APIs.
Besides that I'm not sure what else to suggest.