Skip to content

Commit

Permalink
🐛 Bug: Fix the bug where there is no error handling for JSON parsing …
Browse files Browse the repository at this point in the history
…errors
  • Loading branch information
yym68686 committed Sep 28, 2024
1 parent d5fa861 commit c1e2f2d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name="modelmerge",
version="0.11.47",
version="0.11.48",
description="modelmerge is a multi-large language model API aggregator.",
long_description=Path.open(Path("README.md"), encoding="utf-8").read(),
long_description_content_type="text/markdown",
Expand Down
20 changes: 11 additions & 9 deletions src/ModelMerge/models/chatgpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,6 @@ def ask_stream(
full_response: str = ""
function_full_response: str = ""
function_call_name: str = ""
function_call_id: str = ""
need_function_call: bool = False
total_tokens = 0
for line in response.iter_lines():
Expand Down Expand Up @@ -623,7 +622,6 @@ async def ask_stream_async(
full_response: str = ""
function_full_response: str = ""
function_call_name: str = ""
function_call_id: str = ""
need_function_call: bool = False
total_tokens = 0

Expand Down Expand Up @@ -723,13 +721,17 @@ async def ask_stream_async(
if line == "[DONE]":
break
else:
line = json.loads(line)
full_response = safe_get(line, "choices", 0, "message", "content")
if full_response:
yield full_response
else:
yield line
break
try:
line = json.loads(line)
full_response = safe_get(line, "choices", 0, "message", "content")
if full_response:
yield full_response
else:
yield line
break
except:
print("json.loads error:", repr(line))
continue
resp: dict = json.loads(line)
if "error" in resp:
raise Exception(f"{resp}")
Expand Down

0 comments on commit c1e2f2d

Please sign in to comment.