Skip to content

Commit

Permalink
[bug fix] Change isinstance to issubclass for response_format check
Browse files Browse the repository at this point in the history
Update the condition in Prompt class to use issubclass instead of isinstance
when checking self.response_format against BaseModel. This allows for proper
handling of subclasses of BaseModel.

- Modified condition in two locations within prompt_base.py
- Updated version number in pyproject.toml from 0.2.0 to 0.2.1

Notes: The user clarified that self.response_format can be a subclass of
BaseModel, not just an instance. This change ensures that the code correctly
identifies and processes response formats that inherit from BaseModel.
  • Loading branch information
aschung01 committed Oct 8, 2024
1 parent 9d9c2ec commit 073a505
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions libs/ape-common/ape/common/prompt/prompt_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ async def __call__(
if self.response_format["type"] == "text":
return res_text
parsed_outputs: Dict[str, Any]
if isinstance(self.response_format, BaseModel):
if isinstance(self.response_format, type) and issubclass(
self.response_format, BaseModel
):
parsed_outputs = json.loads(res_text)
parsed_outputs = self.response_format.model_validate(parsed_outputs)
else:
Expand Down Expand Up @@ -285,7 +287,7 @@ def dump(self) -> str:
"""

response_format_cache = None
if isinstance(self.response_format, BaseModel):
if isinstance(self.response_format, type) and issubclass(self.response_format, BaseModel):
response_format_cache = self.response_format
self.response_format = type_to_response_format_param(self.response_format)

Expand Down
2 changes: 1 addition & 1 deletion libs/ape-common/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "ape-common"
version = "0.2.0"
version = "0.2.1"
description = "Common utilities for Ape: your AI prompt engineer"
readme = "README.md"
requires-python = ">=3.10"
Expand Down

0 comments on commit 073a505

Please sign in to comment.