mirror of
https://github.com/open-webui/open-webui
synced 2025-05-18 04:15:07 +00:00
enh: add content-type: application/x-ndjson to ollama /api/chat
This commit is contained in:
parent
062649e483
commit
689b05a73d
@ -148,7 +148,9 @@ async def cleanup_response(
|
|||||||
await session.close()
|
await session.close()
|
||||||
|
|
||||||
|
|
||||||
async def post_streaming_url(url: str, payload: Union[str, bytes], stream: bool = True):
|
async def post_streaming_url(
|
||||||
|
url: str, payload: Union[str, bytes], stream: bool = True, content_type=None
|
||||||
|
):
|
||||||
r = None
|
r = None
|
||||||
try:
|
try:
|
||||||
session = aiohttp.ClientSession(
|
session = aiohttp.ClientSession(
|
||||||
@ -162,10 +164,13 @@ async def post_streaming_url(url: str, payload: Union[str, bytes], stream: bool
|
|||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
|
|
||||||
if stream:
|
if stream:
|
||||||
|
headers = dict(r.headers)
|
||||||
|
if content_type:
|
||||||
|
headers["Content-Type"] = content_type
|
||||||
return StreamingResponse(
|
return StreamingResponse(
|
||||||
r.content,
|
r.content,
|
||||||
status_code=r.status,
|
status_code=r.status,
|
||||||
headers=dict(r.headers),
|
headers=headers,
|
||||||
background=BackgroundTask(
|
background=BackgroundTask(
|
||||||
cleanup_response, response=r, session=session
|
cleanup_response, response=r, session=session
|
||||||
),
|
),
|
||||||
@ -769,7 +774,9 @@ async def generate_chat_completion(
|
|||||||
log.info(f"url: {url}")
|
log.info(f"url: {url}")
|
||||||
log.debug(payload)
|
log.debug(payload)
|
||||||
|
|
||||||
return await post_streaming_url(f"{url}/api/chat", json.dumps(payload))
|
return await post_streaming_url(
|
||||||
|
f"{url}/api/chat", json.dumps(payload), content_type="application/x-ndjson"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# TODO: we should update this part once Ollama supports other types
|
# TODO: we should update this part once Ollama supports other types
|
||||||
|
Loading…
Reference in New Issue
Block a user