-
Notifications
You must be signed in to change notification settings - Fork 119
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
Add MetaData LLM call #20
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,7 @@ async def clear_ocr_cache(): | |
class OllamaGenerateRequest(BaseModel): | ||
model: str | ||
prompt: str | ||
generate_tags_summary: bool = False | ||
|
||
class OllamaPullRequest(BaseModel): | ||
model: str | ||
|
@@ -116,3 +117,25 @@ async def generate_llama(request: OllamaGenerateRequest): | |
|
||
generated_text = response.get("response", "") | ||
return {"generated_text": generated_text} | ||
|
||
@app.post("/llm_tags_summary") | ||
async def generate_tags_summary(request: OllamaGenerateRequest): | ||
""" | ||
Endpoint to generate tags and summary using Llama 3.1 model (and other models) via the Ollama API. | ||
""" | ||
print(request) | ||
if not request.prompt: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metadata request is different than the main request with prompt. Should be executed after the main LLM call on top of its results It should use metadata prompt defined in env variable for configuration purposes Then it should always return JSON object - I proposed its structure in the other comment |
||
raise HTTPException(status_code=400, detail="No prompt provided") | ||
|
||
try: | ||
response = ollama.generate(request.model, request.prompt) | ||
except ollama.ResponseError as e: | ||
print('Error:', e.error) | ||
if e.status_code == 404: | ||
print("Error: ", e.error) | ||
ollama.pull(request.model) | ||
|
||
raise HTTPException(status_code=500, detail="Failed to generate tags and summary with Ollama API") | ||
|
||
generated_text = response.get("response", "") | ||
return {"generated_text": generated_text} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,27 @@ def ocr_task(self, pdf_bytes, strategy_name, pdf_hash, ocr_cache, prompt, model) | |
num_chunk += 1 | ||
extracted_text += chunk['response'] | ||
|
||
self.update_state(state='DONE', meta={'progress': 100 , 'status': 'Processing done!', 'start_time': start_time, 'elapsed_time': time.time() - start_time}) # Example progress update | ||
# Optional call to generate tags and summary | ||
if prompt and model: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add an option |
||
tags_summary = generate_tags_summary(prompt, model) | ||
extracted_text += "\n\nTags and Summary:\n" + tags_summary | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When generate_metadata option defined it should be not returned within the general output but stored in the different json filename according to #10, used for file name strategies and stored within other field in the celerey result We probably need an additional endpoint to get just the metadata stored for specific celery task |
||
|
||
self.update_state(state='DONE', meta={'progress': 100 , 'status': 'Processing done!', 'start_time': start_time, 'elapsed_time': time.time() - start_time}) # Example progress update | ||
|
||
return extracted_text | ||
|
||
def generate_tags_summary(prompt, model): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please rename it to |
||
""" | ||
Function to generate tags and summary using the LLM. | ||
""" | ||
try: | ||
response = ollama.generate(model, prompt) | ||
except ollama.ResponseError as e: | ||
print('Error:', e.error) | ||
if e.status_code == 404: | ||
print("Error: ", e.error) | ||
ollama.pull(model) | ||
raise Exception("Failed to generate tags and summary with Ollama API") | ||
|
||
generated_text = response.get("response", "") | ||
return generated_text |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please name it
llm_metadata
and use this name instead oftags_summary