mirror of
https://github.com/open-webui/open-webui
synced 2025-05-19 12:51:35 +00:00
enh: pipe handling
This commit is contained in:
parent
837944dcc5
commit
4c9fa6cf37
@ -233,6 +233,16 @@ async def generate_function_chat_completion(form_data, user):
|
|||||||
res = await pipe(**params)
|
res = await pipe(**params)
|
||||||
else:
|
else:
|
||||||
res = pipe(**params)
|
res = pipe(**params)
|
||||||
|
|
||||||
|
# Directly return if the response is a StreamingResponse
|
||||||
|
if isinstance(res, StreamingResponse):
|
||||||
|
async for data in res.body_iterator:
|
||||||
|
yield data
|
||||||
|
return
|
||||||
|
if isinstance(res, dict):
|
||||||
|
yield f"data: {json.dumps(res)}\n\n"
|
||||||
|
return
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error: {e}")
|
print(f"Error: {e}")
|
||||||
yield f"data: {json.dumps({'error': {'detail':str(e)}})}\n\n"
|
yield f"data: {json.dumps({'error': {'detail':str(e)}})}\n\n"
|
||||||
@ -285,15 +295,13 @@ async def generate_function_chat_completion(form_data, user):
|
|||||||
res = await pipe(**params)
|
res = await pipe(**params)
|
||||||
else:
|
else:
|
||||||
res = pipe(**params)
|
res = pipe(**params)
|
||||||
|
|
||||||
|
if isinstance(res, StreamingResponse):
|
||||||
|
return res
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error: {e}")
|
print(f"Error: {e}")
|
||||||
return {"error": {"detail": str(e)}}
|
return {"error": {"detail": str(e)}}
|
||||||
|
|
||||||
if inspect.iscoroutinefunction(pipe):
|
|
||||||
res = await pipe(**params)
|
|
||||||
else:
|
|
||||||
res = pipe(**params)
|
|
||||||
|
|
||||||
if isinstance(res, dict):
|
if isinstance(res, dict):
|
||||||
return res
|
return res
|
||||||
elif isinstance(res, BaseModel):
|
elif isinstance(res, BaseModel):
|
||||||
|
Loading…
Reference in New Issue
Block a user