"backend/apps/vscode:/vscode.git/clone" did not exist on "7c9fb9199ebe254b147f25cbc55693875fbda88d"
Commit cf6447eb authored by Timothy J. Baek's avatar Timothy J. Baek
Browse files

feat: function exception handler

parent 9205b90a
......@@ -913,10 +913,15 @@ async def generate_chat_completions(form_data: dict, user=Depends(get_verified_u
if form_data["stream"]:
async def stream_content():
try:
if inspect.iscoroutinefunction(pipe):
res = await pipe(**param)
else:
res = pipe(**param)
except Exception as e:
print(f"Error: {e}")
yield f"data: {json.dumps({'error': {'detail':str(e)}})}\n\n"
return
if isinstance(res, str):
message = stream_message_template(form_data["model"], res)
......@@ -961,6 +966,16 @@ async def generate_chat_completions(form_data: dict, user=Depends(get_verified_u
stream_content(), media_type="text/event-stream"
)
else:
try:
if inspect.iscoroutinefunction(pipe):
res = await pipe(**param)
else:
res = pipe(**param)
except Exception as e:
print(f"Error: {e}")
return {"error": {"detail":str(e)}}
if inspect.iscoroutinefunction(pipe):
res = await pipe(**param)
else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment