MCPcopy Index your code
hub / github.com/VectifyAI/PageIndex / llm_completion

Function llm_completion

pageindex/utils.py:32–58  ·  view source on GitHub ↗
(model, prompt, chat_history=None, return_finish_reason=False)

Source from the content-addressed store, hash-verified

30
31
32def llm_completion(model, prompt, chat_history=None, return_finish_reason=False):
33 if model:
34 model = model.removeprefix("litellm/")
35 max_retries = 10
36 messages = list(chat_history) + [{"role": "user", "content": prompt}] if chat_history else [{"role": "user", "content": prompt}]
37 for i in range(max_retries):
38 try:
39 response = litellm.completion(
40 model=model,
41 messages=messages,
42 temperature=0,
43 )
44 content = response.choices[0].message.content
45 if return_finish_reason:
46 finish_reason = "max_output_reached" if response.choices[0].finish_reason == "length" else "finished"
47 return content, finish_reason
48 return content
49 except Exception as e:
50 print('************* Retrying *************')
51 logging.error(f"Error: {e}")
52 if i < max_retries - 1:
53 time.sleep(1)
54 else:
55 logging.error('Max retries reached for prompt: ' + prompt)
56 if return_finish_reason:
57 return "", "error"
58 return ""
59
60
61

Callers 11

toc_detector_single_pageFunction · 0.85
extract_toc_contentFunction · 0.85
detect_page_indexFunction · 0.85
toc_index_extractorFunction · 0.85
toc_transformerFunction · 0.85
add_page_number_to_tocFunction · 0.85
generate_toc_continueFunction · 0.85
generate_toc_initFunction · 0.85
generate_doc_descriptionFunction · 0.85

Calls 1

errorMethod · 0.80

Tested by

no test coverage detected