Browse Source

fix: use `removeprefix()` instead of `lstrip()` to remove the `data:` prefix (#11272)

Signed-off-by: -LAN- <laipz8200@outlook.com>
tags/0.13.0
-LAN- 11 months ago
parent
commit
643a90c48d
No account linked to committer's email address

+ 1
- 1
api/core/model_runtime/model_providers/moonshot/llm/llm.py View File

@@ -252,7 +252,7 @@ class MoonshotLargeLanguageModel(OAIAPICompatLargeLanguageModel):
# ignore sse comments
if chunk.startswith(":"):
continue
decoded_chunk = chunk.strip().lstrip("data: ").lstrip()
decoded_chunk = chunk.strip().removeprefix("data: ")
chunk_json = None
try:
chunk_json = json.loads(decoded_chunk)

+ 1
- 1
api/core/model_runtime/model_providers/openai_api_compatible/llm/llm.py View File

@@ -462,7 +462,7 @@ class OAIAPICompatLargeLanguageModel(_CommonOaiApiCompat, LargeLanguageModel):
# ignore sse comments
if chunk.startswith(":"):
continue
decoded_chunk = chunk.strip().lstrip("data: ").lstrip()
decoded_chunk = chunk.strip().removeprefix("data: ")
if decoded_chunk == "[DONE]": # Some provider returns "data: [DONE]"
continue


+ 1
- 1
api/core/model_runtime/model_providers/stepfun/llm/llm.py View File

@@ -250,7 +250,7 @@ class StepfunLargeLanguageModel(OAIAPICompatLargeLanguageModel):
# ignore sse comments
if chunk.startswith(":"):
continue
decoded_chunk = chunk.strip().lstrip("data: ").lstrip()
decoded_chunk = chunk.strip().removeprefix("data: ")
chunk_json = None
try:
chunk_json = json.loads(decoded_chunk)

Loading…
Cancel
Save