Skip to content

Commit

Permalink
enhanged LLM response parsing for lists
Browse files Browse the repository at this point in the history
  • Loading branch information
emcf committed Sep 4, 2024
1 parent 55a224c commit 2e52ff2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def read_git_requirements(file):

setup(
name='thepipe_api',
version='1.2.3',
version='1.2.5',
author='Emmett McFarlane',
author_email='[email protected]',
description='AI-native extractor, powered by multimodal LLMs.',
Expand Down
4 changes: 4 additions & 0 deletions thepipe/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,15 @@ def extract_from_chunk(chunk: Chunk, chunk_index: int, schema: str, ai_model: st
if multiple_extractions:
if isinstance(llm_response_dict, dict) and "extraction" in llm_response_dict:
response_dict["extraction"] = llm_response_dict["extraction"]
elif isinstance(llm_response_dict, list):
response_dict["extraction"] = llm_response_dict
else:
response_dict["extraction"] = [llm_response_dict]
else:
if isinstance(llm_response_dict, dict):
response_dict.update(llm_response_dict)
elif isinstance(llm_response_dict, list):
response_dict["error"] = f"Expected a single JSON object but received a list: {llm_response_dict}"
else:
response_dict["error"] = f"Invalid JSON structure in LLM response: {llm_response_dict}"
else:
Expand Down

0 comments on commit 2e52ff2

Please sign in to comment.