Spaces:
Build error
Build error
Julian Vanecek commited on
Commit ·
287e8c6
1
Parent(s): 86c379e
reverting frontend
Browse files
app.py
CHANGED
|
@@ -38,20 +38,21 @@ def process_faq(question, user_id="anonymous", model="claude-sonnet"):
|
|
| 38 |
if response.status_code != 200:
|
| 39 |
return f"Error: Lambda function returned status code {response.status_code}"
|
| 40 |
|
| 41 |
-
# Process the
|
| 42 |
full_response = ""
|
| 43 |
for chunk in response.iter_content(chunk_size=1024, decode_unicode=True):
|
| 44 |
if chunk:
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
| 55 |
|
| 56 |
return full_response
|
| 57 |
|
|
|
|
| 38 |
if response.status_code != 200:
|
| 39 |
return f"Error: Lambda function returned status code {response.status_code}"
|
| 40 |
|
| 41 |
+
# Process the streaming response
|
| 42 |
full_response = ""
|
| 43 |
for chunk in response.iter_content(chunk_size=1024, decode_unicode=True):
|
| 44 |
if chunk:
|
| 45 |
+
try:
|
| 46 |
+
# Try to parse the chunk as JSON
|
| 47 |
+
chunk_data = json.loads(chunk)
|
| 48 |
+
if "response" in chunk_data:
|
| 49 |
+
chunk_text = chunk_data["response"]
|
| 50 |
+
full_response += chunk_text
|
| 51 |
+
yield full_response
|
| 52 |
+
except json.JSONDecodeError:
|
| 53 |
+
# If not JSON, treat as plain text
|
| 54 |
+
full_response += chunk
|
| 55 |
+
yield full_response
|
| 56 |
|
| 57 |
return full_response
|
| 58 |
|