mirror of
https://github.com/VectifyAI/PageIndex.git
synced 2026-04-24 23:56:21 +02:00
Merge pull request #65 from luojiyin1987/fix/extract-toc-infinite-loop
fix: prevent infinite loop in extract_toc_content
This commit is contained in:
commit
599d2ce497
1 changed files with 9 additions and 6 deletions
|
|
@ -180,7 +180,14 @@ def extract_toc_content(content, model=None):
|
|||
response = response + new_response
|
||||
if_complete = check_if_toc_transformation_is_complete(content, response, model)
|
||||
|
||||
attempt = 0
|
||||
max_attempts = 5
|
||||
|
||||
while not (if_complete == "yes" and finish_reason == "finished"):
|
||||
attempt += 1
|
||||
if attempt > max_attempts:
|
||||
raise Exception('Failed to complete table of contents after maximum retries')
|
||||
|
||||
chat_history = [
|
||||
{"role": "user", "content": prompt},
|
||||
{"role": "assistant", "content": response},
|
||||
|
|
@ -190,10 +197,6 @@ def extract_toc_content(content, model=None):
|
|||
response = response + new_response
|
||||
if_complete = check_if_toc_transformation_is_complete(content, response, model)
|
||||
|
||||
# Optional: Add a maximum retry limit to prevent infinite loops
|
||||
if len(chat_history) > 5: # Arbitrary limit of 10 attempts
|
||||
raise Exception('Failed to complete table of contents after maximum retries')
|
||||
|
||||
return response
|
||||
|
||||
def detect_page_index(toc_content, model=None):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue