return fucntion in streaming #28930
Replies: 1 comment
-
I found two similar unsolved discussions that might be relevant to your question:
Regarding your question, in Python, you cannot use Here's a modified version of your function that accumulates the response and returns it after streaming: async def generate_chat_responses(message):
full_response = ""
async for chunk in llm.astream(message):
full_response += chunk.content # Accumulate the chunk content into the full response
yield f"{full_response}\n\n"
return full_response # This line will not be reached if using yield If you need to return the accumulated response after streaming, you might need to call the generator and collect the results separately. To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
async def generate_chat_responses(message):
full_response = " "
async for chunk in llm.astream(message):
full_response += chunk.content # Accumulate the chunk content into the full response
yield f"{full_response}\n\n"
Beta Was this translation helpful? Give feedback.
All reactions