Mendu9 commited on
Commit
e0184e0
·
1 Parent(s): 987424d

fix: json.loads SSE tokens in streamlit client — tokens were rendered as quoted strings

Browse files
Files changed (1) hide show
  1. app/streamlit_app.py +6 -1
app/streamlit_app.py CHANGED
@@ -125,7 +125,12 @@ def _stream_response(
125
  if token.startswith("__meta__:"):
126
  yield token # pass through raw for caller to handle
127
  continue
128
- yield token + " "
 
 
 
 
 
129
  except requests.exceptions.ConnectionError:
130
  yield (
131
  "\n\n_[Error: Cannot connect to backend. "
 
125
  if token.startswith("__meta__:"):
126
  yield token # pass through raw for caller to handle
127
  continue
128
+ try:
129
+ import json as _json
130
+ token = _json.loads(token)
131
+ except Exception:
132
+ pass # not JSON-encoded, use as-is
133
+ yield token
134
  except requests.exceptions.ConnectionError:
135
  yield (
136
  "\n\n_[Error: Cannot connect to backend. "