Pavithiran commited on
Commit
e586e56
·
verified ·
1 Parent(s): a6c7b8e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -38,9 +38,16 @@ def respond(
38
  ):
39
  token = message.choices[0].delta.content
40
 
 
 
 
 
 
 
 
41
  response += token
42
  yield response
43
- except json.JSONDecodeError as e:
44
  yield f"Error: {e}"
45
 
46
  """
 
38
  ):
39
  token = message.choices[0].delta.content
40
 
41
+ # Check if the token is a valid JSON string
42
+ try:
43
+ json.loads(token)
44
+ except json.JSONDecodeError:
45
+ yield f"Error: Invalid JSON response - {token}"
46
+ break
47
+
48
  response += token
49
  yield response
50
+ except Exception as e:
51
  yield f"Error: {e}"
52
 
53
  """