abanm commited on
Commit
f3ac531
·
verified ·
1 Parent(s): cceef00

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -125,10 +125,11 @@ if prompt := st.chat_input():
125
  )
126
  response.raise_for_status()
127
 
128
- # Read and yield the response incrementally
129
- for chunk in response.iter_content(chunk_size=256):
130
- if chunk:
131
- yield chunk.decode("utf-8")
 
132
  except requests.exceptions.Timeout:
133
  yield "The request timed out. Please try again later."
134
  except requests.exceptions.RequestException as e:
@@ -147,4 +148,3 @@ if prompt := st.chat_input():
147
 
148
  # Auto-save the updated chat history
149
  save_chat_history(st.session_state["session_name"], st.session_state["messages"])
150
-
 
125
  )
126
  response.raise_for_status()
127
 
128
+ # Process and yield only the response field
129
+ for line in response.iter_lines():
130
+ if line:
131
+ data = json.loads(line.decode("utf-8"))
132
+ yield data.get("response", "")
133
  except requests.exceptions.Timeout:
134
  yield "The request timed out. Please try again later."
135
  except requests.exceptions.RequestException as e:
 
148
 
149
  # Auto-save the updated chat history
150
  save_chat_history(st.session_state["session_name"], st.session_state["messages"])