artificialguybr commited on
Commit
a48985f
·
1 Parent(s): f89bf86

Handle invalid JSON in call_api function

Browse files
Files changed (1) hide show
  1. app.py +5 -1
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
- json_data = json.loads(decoded_line[5:])
 
 
 
 
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: