Skip to content

Commit

Permalink
feat: improve exception feedback for extraction (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
lsorber authored Aug 17, 2024
1 parent fa2bad8 commit 7135e98
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/raglite/_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ class MyNameResponse(BaseModel):
)
try:
instance = return_type.model_validate_json(response["choices"][0]["message"]["content"]) # type: ignore[arg-type,index]
except (KeyError, ValueError, ValidationError):
except (KeyError, ValueError, ValidationError) as e:
# Malformed response, not a JSON string, or not a valid instance of the return type.
last_exception = e
continue
else:
break
else:
error_message = f"Failed to extract {return_type} from input {user_prompt}."
raise ValueError(error_message)
raise ValueError(error_message) from last_exception
return instance

0 comments on commit 7135e98

Please sign in to comment.