Alikestocode commited on
Commit
597f1a9
·
1 Parent(s): de18e95

Fix: Move trim_at_stop_sequences function before it's used

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -201,6 +201,18 @@ def extract_json_from_text(text: str) -> str:
201
  raise ValueError("Router output JSON appears truncated.")
202
 
203
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  def is_function_call(text: str) -> bool:
205
  return bool(TOOL_PATTERN.match(text.strip()))
206
 
@@ -505,13 +517,4 @@ if __name__ == "__main__": # pragma: no cover
505
  server_port=int(os.environ.get("PORT", 7860)),
506
  show_api=True
507
  )
508
- def trim_at_stop_sequences(text: str) -> Tuple[str, bool]:
509
- earliest = None
510
- for stop in STOP_SEQUENCES:
511
- idx = text.find(stop)
512
- if idx != -1 and (earliest is None or idx < earliest):
513
- earliest = idx
514
- if earliest is not None:
515
- return text[:earliest], True
516
- return text, False
517
 
 
201
  raise ValueError("Router output JSON appears truncated.")
202
 
203
 
204
+ def trim_at_stop_sequences(text: str) -> Tuple[str, bool]:
205
+ """Trim text at stop sequences and return trimmed text and whether a stop was found."""
206
+ earliest = None
207
+ for stop in STOP_SEQUENCES:
208
+ idx = text.find(stop)
209
+ if idx != -1 and (earliest is None or idx < earliest):
210
+ earliest = idx
211
+ if earliest is not None:
212
+ return text[:earliest], True
213
+ return text, False
214
+
215
+
216
  def is_function_call(text: str) -> bool:
217
  return bool(TOOL_PATTERN.match(text.strip()))
218
 
 
517
  server_port=int(os.environ.get("PORT", 7860)),
518
  show_api=True
519
  )
 
 
 
 
 
 
 
 
 
520