forked from open-webui/open-webui
refac
This commit is contained in:
parent
47dc3b5fb2
commit
a37b9c126f
1 changed files with 4 additions and 6 deletions
|
@ -98,16 +98,17 @@ async def proxy(path: str, request: Request, user=Depends(get_current_user)):
|
||||||
print(data)
|
print(data)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|
||||||
async def gen():
|
async def generate():
|
||||||
async for line in response.content:
|
async for line in response.content:
|
||||||
yield line
|
yield line
|
||||||
await session.close()
|
await session.close()
|
||||||
|
|
||||||
return StreamingResponse(gen(), response.status)
|
return StreamingResponse(generate(), response.status)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
error_detail = "Ollama WebUI: Server Connection Error"
|
error_detail = "Ollama WebUI: Server Connection Error"
|
||||||
|
|
||||||
if response is not None:
|
if response is not None:
|
||||||
try:
|
try:
|
||||||
res = await response.json()
|
res = await response.json()
|
||||||
|
@ -117,11 +118,8 @@ async def proxy(path: str, request: Request, user=Depends(get_current_user)):
|
||||||
error_detail = f"Ollama: {e}"
|
error_detail = f"Ollama: {e}"
|
||||||
|
|
||||||
await session.close()
|
await session.close()
|
||||||
|
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=response.status if response else 500,
|
status_code=response.status if response else 500,
|
||||||
detail=error_detail,
|
detail=error_detail,
|
||||||
)
|
)
|
||||||
|
|
||||||
# print(e)
|
|
||||||
# error_detail = "Ollama WebUI: Server Connection Error"
|
|
||||||
# return {"error": error_detail, "message": str(e)}
|
|
||||||
|
|
Loading…
Reference in a new issue