suzmen commited on
Commit
43e0402
·
verified ·
1 Parent(s): 64cfada

Upload 64 files

Browse files
Files changed (1) hide show
  1. app/services/browser.py +11 -1
app/services/browser.py CHANGED
@@ -180,17 +180,27 @@ class BrowserEngine(threading.Thread):
180
  # Poll until the response stabilises
181
  last_text = ""
182
  unchanged_count = 0
 
 
183
  while unchanged_count < 4:
 
 
 
 
 
184
  elements = await page.query_selector_all(
185
  '[data-message-author-role="assistant"]'
186
  )
187
  if elements:
188
  current_text = await elements[-1].inner_text()
189
- if current_text == last_text and current_text.strip():
190
  unchanged_count += 1
191
  else:
 
 
192
  last_text = current_text
193
  unchanged_count = 0
 
194
  await asyncio.sleep(0.5)
195
 
196
  print(f"[PhantomAPI] ✨ Response complete ({len(last_text)} chars).")
 
180
  # Poll until the response stabilises
181
  last_text = ""
182
  unchanged_count = 0
183
+ start_polling = asyncio.get_event_loop().time()
184
+
185
  while unchanged_count < 4:
186
+ # Safety break: 90 seconds max for polling
187
+ if asyncio.get_event_loop().time() - start_polling > 90:
188
+ print("[PhantomAPI] ⚠️ Polling timeout reached (90s). Returning current text.")
189
+ break
190
+
191
  elements = await page.query_selector_all(
192
  '[data-message-author-role="assistant"]'
193
  )
194
  if elements:
195
  current_text = await elements[-1].inner_text()
196
+ if current_text == last_text:
197
  unchanged_count += 1
198
  else:
199
+ if len(current_text) > len(last_text):
200
+ print(f"[PhantomAPI] ⏳ Generating... ({len(current_text)} chars)")
201
  last_text = current_text
202
  unchanged_count = 0
203
+
204
  await asyncio.sleep(0.5)
205
 
206
  print(f"[PhantomAPI] ✨ Response complete ({len(last_text)} chars).")