Skip to content

Commit

Permalink
Add error message when cannot convert to pydantic
Browse files Browse the repository at this point in the history
  • Loading branch information
s-jse committed Aug 13, 2024
1 parent 7e17baf commit 8dc33c6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion chainlite/llm_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,14 @@ async def postprocess_generations(input_: AsyncIterator[str]) -> AsyncIterator[s

@chain
def string_to_pydantic_object(llm_output: str, pydantic_class: BaseModel):
return pydantic_class.model_validate(json.loads(llm_output))
try:
return pydantic_class.model_validate(json.loads(llm_output))
except Exception as e:
logger.exception(
f"Error decoding JSON: {e}. This might be resolved by increasing `max_tokens`"
)
logger.error(f"LLM output: {llm_output}")
return None


def is_list(obj):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="chainlite",
version="0.2.1",
version="0.2.2",
author="Sina Semnani",
author_email="[email protected]",
description="A Python package that uses LangChain and LiteLLM to call large language model APIs easily",
Expand Down

0 comments on commit 8dc33c6

Please sign in to comment.