(content, model=None)
| 158 | return json_content['completed'] |
| 159 | |
| 160 | def extract_toc_content(content, model=None): |
| 161 | prompt = f""" |
| 162 | Your job is to extract the full table of contents from the given text, replace ... with : |
| 163 | |
| 164 | Given text: {content} |
| 165 | |
| 166 | Directly return the full table of contents content. Do not output anything else.""" |
| 167 | |
| 168 | response, finish_reason = llm_completion(model=model, prompt=prompt, return_finish_reason=True) |
| 169 | |
| 170 | if_complete = check_if_toc_transformation_is_complete(content, response, model) |
| 171 | if if_complete == "yes" and finish_reason == "finished": |
| 172 | return response |
| 173 | |
| 174 | chat_history = [ |
| 175 | {"role": "user", "content": prompt}, |
| 176 | {"role": "assistant", "content": response}, |
| 177 | ] |
| 178 | prompt = f"""please continue the generation of table of contents , directly output the remaining part of the structure""" |
| 179 | new_response, finish_reason = llm_completion(model=model, prompt=prompt, chat_history=chat_history, return_finish_reason=True) |
| 180 | response = response + new_response |
| 181 | if_complete = check_if_toc_transformation_is_complete(content, response, model) |
| 182 | |
| 183 | attempt = 0 |
| 184 | max_attempts = 5 |
| 185 | |
| 186 | while not (if_complete == "yes" and finish_reason == "finished"): |
| 187 | attempt += 1 |
| 188 | if attempt > max_attempts: |
| 189 | raise Exception('Failed to complete table of contents after maximum retries') |
| 190 | |
| 191 | chat_history = [ |
| 192 | {"role": "user", "content": prompt}, |
| 193 | {"role": "assistant", "content": response}, |
| 194 | ] |
| 195 | prompt = f"""please continue the generation of table of contents , directly output the remaining part of the structure""" |
| 196 | new_response, finish_reason = llm_completion(model=model, prompt=prompt, chat_history=chat_history, return_finish_reason=True) |
| 197 | response = response + new_response |
| 198 | if_complete = check_if_toc_transformation_is_complete(content, response, model) |
| 199 | |
| 200 | return response |
| 201 | |
| 202 | def detect_page_index(toc_content, model=None): |
| 203 | print('start detect_page_index') |
nothing calls this directly
no test coverage detected