Skip to content

Commit

Permalink
Merge pull request #47 from weavel-ai/46-fix-should-check-if-response…
Browse files Browse the repository at this point in the history
…_format-is-a-subclass-of-basemodel-not-instance

[bug fix] Change isinstance to issubclass for response_format check
  • Loading branch information
aschung01 authored Oct 9, 2024
2 parents 9d9c2ec + 073a505 commit 6f14966
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 6f14966

Please sign in to comment.