Skip to content

Update generate_completion_from_local_llm return type #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions llm_aided_ocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ async def generate_completion_from_openai(prompt: str, max_tokens: int = 5000) -
logging.error(f"An error occurred while requesting from OpenAI API: {e}")
return None

async def generate_completion_from_local_llm(llm_model_name: str, input_prompt: str, number_of_tokens_to_generate: int = 100, temperature: float = 0.7, grammar_file_string: str = None):
async def generate_completion_from_local_llm(llm_model_name: str, input_prompt: str, number_of_tokens_to_generate: int = 100, temperature: float = 0.7, grammar_file_string: str = None) -> Optional[str]:
logging.info(f"Starting text completion using model: '{llm_model_name}' for input prompt: '{input_prompt}'")
llm = load_model(llm_model_name)
prompt_tokens = estimate_tokens(input_prompt, llm_model_name)
Expand Down Expand Up @@ -396,11 +396,7 @@ async def generate_completion_from_local_llm(llm_model_name: str, input_prompt:
finish_reason = str(output['choices'][0]['finish_reason'])
llm_model_usage_json = json.dumps(output['usage'])
logging.info(f"Completed text completion in {output['usage']['total_time']:.2f} seconds. Beginning of generated text: \n'{generated_text[:150]}'...")
return {
"generated_text": generated_text,
"finish_reason": finish_reason,
"llm_model_usage_json": llm_model_usage_json
}
return generated_text

# Image Processing Functions
def preprocess_image(image):
Expand Down