Skip to content

Commit f834569

Browse files
committed
feat: raise error
1 parent f943cc5 commit f834569

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

apps/chat/serializers/chat.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,13 @@ def generate_prompt(self, instance: dict):
187187

188188
def process():
189189
model = get_model_instance_by_model_workspace_id(model_id=model_id, workspace_id=workspace_id,**application.model_params_setting)
190-
for r in model.stream([SystemMessage(content=system_content),
190+
try:
191+
for r in model.stream([SystemMessage(content=system_content),
191192
*[HumanMessage(content=m.get('content')) if m.get('role') == 'user' else AIMessage(
192193
content=m.get('content')) for m in messages]]):
193-
yield 'data: ' + json.dumps({'content': r.content}) + '\n\n'
194-
194+
yield 'data: ' + json.dumps({'content': r.content}) + '\n\n'
195+
except Exception as e:
196+
yield 'data: ' + json.dumps({'error': str(e)}) + '\n\n'
195197
return to_stream_response_simple(process())
196198

197199

0 commit comments

Comments
 (0)