Julian Vanecek commited on
Commit
287e8c6
·
1 Parent(s): 86c379e

reverting frontend

Browse files
Files changed (1) hide show
  1. app.py +12 -11
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 response (Lambda returns complete response as plain text)
42
  full_response = ""
43
  for chunk in response.iter_content(chunk_size=1024, decode_unicode=True):
44
  if chunk:
45
- full_response += chunk
46
-
47
- # Simulate streaming by yielding progressively
48
- if full_response:
49
- words = full_response.split()
50
- current_text = ""
51
- for i, word in enumerate(words):
52
- current_text += word + " "
53
- if i % 2 == 0 or i == len(words) - 1: # Yield every 2 words or at the end
54
- yield current_text.strip()
 
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