Update app.py
Browse files
app.py
CHANGED
@@ -148,11 +148,6 @@ def messages():
|
|
148 |
chunk = text['chunks'][-1] if text['chunks'] else None
|
149 |
if chunk:
|
150 |
response_text.append(chunk)
|
151 |
-
return create_event("content_block_delta", {
|
152 |
-
"type": "content_block_delta",
|
153 |
-
"index": 0,
|
154 |
-
"delta": {"type": "text_delta", "text": chunk},
|
155 |
-
})
|
156 |
|
157 |
def on_query_complete(data):
|
158 |
response_event.set()
|
@@ -163,11 +158,8 @@ def messages():
|
|
163 |
|
164 |
def on_connect_error(data):
|
165 |
logging.error(f"Connection error: {data}")
|
166 |
-
|
167 |
-
|
168 |
-
"index": 0,
|
169 |
-
"delta": {"type": "text_delta", "text": f"Error connecting to Perplexity AI: {data}"},
|
170 |
-
})
|
171 |
|
172 |
sio.on('connect', on_connect)
|
173 |
sio.on('query_progress', on_query_progress)
|
@@ -177,12 +169,10 @@ def messages():
|
|
177 |
|
178 |
try:
|
179 |
sio.connect('wss://www.perplexity.ai/', **connect_opts, headers=sio_opts['extraHeaders'])
|
180 |
-
response_event.wait(timeout=30) # 等待响应,最多30秒
|
181 |
|
182 |
-
# 处理接收到的响应
|
183 |
while not response_event.is_set():
|
184 |
sio.sleep(0.1)
|
185 |
-
|
186 |
chunk = response_text.pop(0)
|
187 |
yield create_event("content_block_delta", {
|
188 |
"type": "content_block_delta",
|
|
|
148 |
chunk = text['chunks'][-1] if text['chunks'] else None
|
149 |
if chunk:
|
150 |
response_text.append(chunk)
|
|
|
|
|
|
|
|
|
|
|
151 |
|
152 |
def on_query_complete(data):
|
153 |
response_event.set()
|
|
|
158 |
|
159 |
def on_connect_error(data):
|
160 |
logging.error(f"Connection error: {data}")
|
161 |
+
response_text.append(f"Error connecting to Perplexity AI: {data}")
|
162 |
+
response_event.set()
|
|
|
|
|
|
|
163 |
|
164 |
sio.on('connect', on_connect)
|
165 |
sio.on('query_progress', on_query_progress)
|
|
|
169 |
|
170 |
try:
|
171 |
sio.connect('wss://www.perplexity.ai/', **connect_opts, headers=sio_opts['extraHeaders'])
|
|
|
172 |
|
|
|
173 |
while not response_event.is_set():
|
174 |
sio.sleep(0.1)
|
175 |
+
while response_text:
|
176 |
chunk = response_text.pop(0)
|
177 |
yield create_event("content_block_delta", {
|
178 |
"type": "content_block_delta",
|