You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
Please do not modify this template :) and fill in all the required fields.
Dify version
latest
Cloud or Self Hosted
Self Hosted (Docker), Self Hosted (Source)
Steps to reproduce
I have Streaming responce now i want to convert into 'AppGenerateService.generate() --> response' generator to that i can pass to return helper.compact_generate_response(response)
response=AppGenerateService.generate(
app_model=app_model,
user=end_user,
args=args,
invoke_from=InvokeFrom.WEB_APP,
streaming=streaming
)
#Streaming should be similar to response generator
✔️ Expected Behavior
No response
❌ Actual Behavior
No response
The text was updated successfully, but these errors were encountered:
To convert your streaming responses into a format that AppGenerateService.generate() can process, you'll need to implement a conversion logic that transforms the streaming data into a generator of JSON strings. This involves creating a method that iterates over each piece of the streaming response, converting each part into the appropriate JSON format, and then yielding these JSON strings for further processing.
Here's a simplified example to guide you:
defstream_response_converter(streaming_response):
forresinstreaming_response:
# Assuming res is a dict representing each message or eventifres['event'] =='message':
yieldjson.dumps({
'event': 'message',
'message_id': res['message_id'],
'conversation_id': res['conversation_id'],
'answer': res['answer'],
'created_at': res['created_at']
})
elifres['event'] =='message_end':
yieldjson.dumps({
'event': 'message_end',
'id': res['id'],
'conversation_id': res['conversation_id'],
'metadata': res['metadata']
})
# Add more conditions as needed based on your streaming response structure
To use this converter with AppGenerateService.generate(), you would do something like this:
Replace your_streaming_data with the actual streaming data you're working with. This example assumes that your streaming data is structured in a way that the stream_response_converter function expects. If your data structure is different, you'll need to adjust the conversion logic accordingly.
This approach allows you to convert streaming responses into a generator of JSON strings, which can then be processed by AppGenerateService.generate() and ultimately compacted into a final response using helper.compact_generate_response(response).
About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
Self Checks
Dify version
latest
Cloud or Self Hosted
Self Hosted (Docker), Self Hosted (Source)
Steps to reproduce
I have Streaming responce now i want to convert into '
AppGenerateService.generate() --> response
' generator to that i can pass to return helper.compact_generate_response(response)Streaming Mode ( Basic Assistant )
How can i make generator for same like
✔️ Expected Behavior
No response
❌ Actual Behavior
No response
The text was updated successfully, but these errors were encountered: