From 2fa481cbcdfa9e8ded0b4b17291d4c4e9a8d2e23 Mon Sep 17 00:00:00 2001 From: jifei <1045195056@qq.com> Date: Fri, 27 Dec 2024 22:52:30 +0800 Subject: [PATCH] support steaming mode content start with data: --- api/core/model_runtime/model_providers/moonshot/llm/llm.py | 2 +- .../model_providers/openai_api_compatible/llm/llm.py | 2 +- api/core/model_runtime/model_providers/stepfun/llm/llm.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/core/model_runtime/model_providers/moonshot/llm/llm.py b/api/core/model_runtime/model_providers/moonshot/llm/llm.py index 90d015942ebb26..cfee0b91e7949c 100644 --- a/api/core/model_runtime/model_providers/moonshot/llm/llm.py +++ b/api/core/model_runtime/model_providers/moonshot/llm/llm.py @@ -252,7 +252,7 @@ def get_tool_call(tool_name: str): # ignore sse comments if chunk.startswith(":"): continue - decoded_chunk = chunk.strip().removeprefix("data: ") + decoded_chunk = chunk.strip().removeprefix("data:").lstrip() chunk_json = None try: chunk_json = json.loads(decoded_chunk) diff --git a/api/core/model_runtime/model_providers/openai_api_compatible/llm/llm.py b/api/core/model_runtime/model_providers/openai_api_compatible/llm/llm.py index 8e07d56f4592de..e375efd846513f 100644 --- a/api/core/model_runtime/model_providers/openai_api_compatible/llm/llm.py +++ b/api/core/model_runtime/model_providers/openai_api_compatible/llm/llm.py @@ -462,7 +462,7 @@ def get_tool_call(tool_call_id: str): # ignore sse comments if chunk.startswith(":"): continue - decoded_chunk = chunk.strip().removeprefix("data: ") + decoded_chunk = chunk.strip().removeprefix("data:").lstrip() if decoded_chunk == "[DONE]": # Some provider returns "data: [DONE]" continue diff --git a/api/core/model_runtime/model_providers/stepfun/llm/llm.py b/api/core/model_runtime/model_providers/stepfun/llm/llm.py index 686809ff2be64d..b14d5ec2ecdb4a 100644 --- a/api/core/model_runtime/model_providers/stepfun/llm/llm.py +++ b/api/core/model_runtime/model_providers/stepfun/llm/llm.py @@ -250,7 +250,7 @@ def get_tool_call(tool_name: str): # ignore sse comments if chunk.startswith(":"): continue - decoded_chunk = chunk.strip().removeprefix("data: ") + decoded_chunk = chunk.strip().removeprefix("data:").lstrip() chunk_json = None try: chunk_json = json.loads(decoded_chunk)