Originally created by @RobinBially on GitHub (Jul 23, 2024).
Is your feature request related to a problem? Please describe.
Currently, a function blocks the event loop if it is called synchronously, but if we call it asynchronously, we need to return a starlette StreamingResponse, which complicates the code.
Describe the solution you'd like
Just add this code to apps/webui/main.py, line 400:
if isinstance(res, AsyncGenerator):
async for line in res:
if isinstance(line, BaseModel):
line = line.model_dump_json()
line = f"data: {line}"
if isinstance(line, dict):
line = f"data: {json.dumps(line)}"
try:
line = line.decode("utf-8")
except:
pass
if line.startswith("data:"):
yield f"{line}\n\n"
else:
line = stream_message_template(form_data["model"], line)
yield f"data: {json.dumps(line)}\n\n"
and
elif isinstance(res, AsyncGenerator):
async for line in res:
return line
in line 449 (non streaming case)
Additionally, we should be able to run a non-coroutine pipe function in a separate thread.
Originally created by @RobinBially on GitHub (Jul 23, 2024).
**Is your feature request related to a problem? Please describe.**
Currently, a function blocks the event loop if it is called synchronously, but if we call it asynchronously, we need to return a starlette StreamingResponse, which complicates the code.
**Describe the solution you'd like**
Just add this code to apps/webui/main.py, line 400:
```
if isinstance(res, AsyncGenerator):
async for line in res:
if isinstance(line, BaseModel):
line = line.model_dump_json()
line = f"data: {line}"
if isinstance(line, dict):
line = f"data: {json.dumps(line)}"
try:
line = line.decode("utf-8")
except:
pass
if line.startswith("data:"):
yield f"{line}\n\n"
else:
line = stream_message_template(form_data["model"], line)
yield f"data: {json.dumps(line)}\n\n"
```
and
```
elif isinstance(res, AsyncGenerator):
async for line in res:
return line
```
in line 449 (non streaming case)
Additionally, we should be able to run a non-coroutine pipe function in a separate thread.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @RobinBially on GitHub (Jul 23, 2024).
Is your feature request related to a problem? Please describe.
Currently, a function blocks the event loop if it is called synchronously, but if we call it asynchronously, we need to return a starlette StreamingResponse, which complicates the code.
Describe the solution you'd like
Just add this code to apps/webui/main.py, line 400:
and
in line 449 (non streaming case)
Additionally, we should be able to run a non-coroutine pipe function in a separate thread.
@justinh-rahb commented on GitHub (Jul 23, 2024):
PR welcomed 👍
@tjbck commented on GitHub (Jul 24, 2024):
Added to dev!