mirror of
https://github.com/open-webui/open-webui
synced 2024-11-29 23:41:50 +00:00
feat: pipe async support
This commit is contained in:
parent
5621025c12
commit
4370f233a1
@ -843,7 +843,7 @@ async def generate_chat_completions(form_data: dict, user=Depends(get_verified_u
|
||||
"role": user.role,
|
||||
}
|
||||
|
||||
def job():
|
||||
async def job():
|
||||
pipe_id = form_data["model"]
|
||||
if "." in pipe_id:
|
||||
pipe_id, sub_pipe_id = pipe_id.split(".", 1)
|
||||
@ -852,7 +852,10 @@ async def generate_chat_completions(form_data: dict, user=Depends(get_verified_u
|
||||
pipe = webui_app.state.FUNCTIONS[pipe_id].pipe
|
||||
if form_data["stream"]:
|
||||
|
||||
def stream_content():
|
||||
async def stream_content():
|
||||
if inspect.iscoroutinefunction(pipe):
|
||||
res = await pipe(body=form_data)
|
||||
else:
|
||||
res = pipe(body=form_data)
|
||||
|
||||
if isinstance(res, str):
|
||||
@ -897,6 +900,9 @@ async def generate_chat_completions(form_data: dict, user=Depends(get_verified_u
|
||||
return StreamingResponse(
|
||||
stream_content(), media_type="text/event-stream"
|
||||
)
|
||||
else:
|
||||
if inspect.iscoroutinefunction(pipe):
|
||||
res = await pipe(body=form_data)
|
||||
else:
|
||||
res = pipe(body=form_data)
|
||||
|
||||
@ -930,7 +936,7 @@ async def generate_chat_completions(form_data: dict, user=Depends(get_verified_u
|
||||
],
|
||||
}
|
||||
|
||||
return await run_in_threadpool(job)
|
||||
return await job()
|
||||
if model["owned_by"] == "ollama":
|
||||
return await generate_ollama_chat_completion(form_data, user=user)
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user