fraudTech commited on
Commit
85f703c
·
verified ·
1 Parent(s): f0b72ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -4
app.py CHANGED
@@ -95,7 +95,6 @@ def proxy_chat_stream():
95
  return Response("Invalid JSON", status=400)
96
 
97
  def generate():
98
- # Forward streaming request to backend
99
  with requests.post(
100
  f"{BACKEND_BASE}/chat/stream",
101
  json=payload,
@@ -104,13 +103,13 @@ def proxy_chat_stream():
104
  timeout=300,
105
  ) as r:
106
 
107
- # Backend error? Surface it.
108
  if r.status_code != 200:
 
109
  yield f"[Backend error {r.status_code}]"
110
  return
111
 
112
- # Yield chunks from backend to frontend
113
- for chunk in r.iter_lines():
114
  if chunk:
115
  yield chunk.decode("utf-8")
116
 
 
95
  return Response("Invalid JSON", status=400)
96
 
97
  def generate():
 
98
  with requests.post(
99
  f"{BACKEND_BASE}/chat/stream",
100
  json=payload,
 
103
  timeout=300,
104
  ) as r:
105
 
 
106
  if r.status_code != 200:
107
+ # Surface backend error as a single line
108
  yield f"[Backend error {r.status_code}]"
109
  return
110
 
111
+ # 🔥 IMPORTANT: use iter_content so we DON'T strip newlines
112
+ for chunk in r.iter_content(chunk_size=1024):
113
  if chunk:
114
  yield chunk.decode("utf-8")
115