POLRAMBORA commited on
Commit
6838891
·
verified ·
1 Parent(s): ed3124a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -25
app.py CHANGED
@@ -112,33 +112,21 @@ def respond(message, api_key, max_tokens, top_p, temperature):
112
 
113
  print(f"Received line: {line}")
114
 
115
- if line.startswith("data:"):
116
- line_content = line[5:].strip()
117
- if not line_content:
118
- continue
119
-
120
- try:
121
- chunk = json.loads(line_content)
122
- chunk_message = chunk.get("chunk", {}).get("content", "")
123
- assistant_reply += chunk_message
124
- yield assistant_reply
125
- except json.JSONDecodeError as e:
126
- print(f"Stream chunk error: {e} with line: {line_content}")
127
- yield f"Error in stream chunk: {e}" # Optionally notify the user
128
- continue
129
-
130
  line_content = line[5:].strip()
131
  if not line_content:
132
- continue
133
-
134
- try:
135
- chunk = json.loads(line_content)
136
- chunk_message = chunk.get("chunk", {}).get("content", "")
137
- assistant_reply += chunk_message
138
- yield assistant_reply
139
- except json.JSONDecodeError as e:
140
- print(f"Stream chunk error: {e} with line: {line_content}")
141
- continue
 
 
142
 
143
  history.append((message, assistant_reply, "You", "P-ALPLE", sessions[api_key]["avatar"], ASSISTANT_PIC_PATH))
144
  sessions[api_key]["history"] = history
 
112
 
113
  print(f"Received line: {line}")
114
 
115
+ if line.startswith("data:"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  line_content = line[5:].strip()
117
  if not line_content:
118
+ continue
119
+
120
+ try:
121
+ chunk = json.loads(line_content)
122
+ chunk_message = chunk.get("chunk", {}).get("content", "")
123
+ assistant_reply += chunk_message
124
+ yield assistant_reply
125
+ except json.JSONDecodeError as e:
126
+ print(f"Stream chunk error: {e} with line: {line_content}")
127
+ yield f"Error in stream chunk: {e}" # Optionally notify the user
128
+ continue
129
+
130
 
131
  history.append((message, assistant_reply, "You", "P-ALPLE", sessions[api_key]["avatar"], ASSISTANT_PIC_PATH))
132
  sessions[api_key]["history"] = history