Commit
·
a48985f
1
Parent(s):
f89bf86
Handle invalid JSON in call_api function
Browse files
app.py
CHANGED
@@ -58,7 +58,11 @@ def call_api(history, max_tokens, temperature, top_p, system_message="", seed=42
|
|
58 |
if line:
|
59 |
decoded_line = line.decode("utf-8").strip()
|
60 |
if decoded_line.startswith("data:"):
|
61 |
-
|
|
|
|
|
|
|
|
|
62 |
if "choices" in json_data and len(json_data["choices"]) > 0:
|
63 |
deltas = json_data["choices"][0].get("delta", {})
|
64 |
if "content" in deltas:
|
|
|
58 |
if line:
|
59 |
decoded_line = line.decode("utf-8").strip()
|
60 |
if decoded_line.startswith("data:"):
|
61 |
+
try:
|
62 |
+
json_data = json.loads(decoded_line[5:])
|
63 |
+
except json.JSONDecodeError:
|
64 |
+
print(f"Invalid JSON: {decoded_line[5:]}")
|
65 |
+
json_data = {}
|
66 |
if "choices" in json_data and len(json_data["choices"]) > 0:
|
67 |
deltas = json_data["choices"][0].get("delta", {})
|
68 |
if "content" in deltas:
|