mirror of
https://github.com/open-webui/pipelines
synced 2025-05-12 16:40:45 +00:00
Refactor async pipe execution for improved readability
This commit is contained in:
parent
dcb74a7ba8
commit
8cc3d6d76c
4
main.py
4
main.py
@ -667,13 +667,13 @@ async def generate_openai_chat_completion(form_data: OpenAIChatCompletionForm):
|
|||||||
status_code=status.HTTP_404_NOT_FOUND,
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
detail=f"Pipeline {form_data.model} not found",
|
detail=f"Pipeline {form_data.model} not found",
|
||||||
)
|
)
|
||||||
|
|
||||||
async def execute_pipe(pipe, *args, **kwargs):
|
async def execute_pipe(pipe, *args, **kwargs):
|
||||||
if inspect.isasyncgenfunction(pipe):
|
if inspect.isasyncgenfunction(pipe):
|
||||||
async for res in pipe(*args, **kwargs):
|
async for res in pipe(*args, **kwargs):
|
||||||
yield res
|
yield res
|
||||||
elif inspect.iscoroutinefunction(pipe):
|
elif inspect.iscoroutinefunction(pipe):
|
||||||
ls = await pipe(*args, **kwargs)
|
for item in await pipe(*args, **kwargs):
|
||||||
for item in ls:
|
|
||||||
yield item
|
yield item
|
||||||
else:
|
else:
|
||||||
for item in await run_in_threadpool(pipe, *args, **kwargs):
|
for item in await run_in_threadpool(pipe, *args, **kwargs):
|
||||||
|
Loading…
Reference in New Issue
Block a user