Skip to content

Commit 022989c

Browse files
committed
v0.0.63
1 parent 7b15647 commit 022989c

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

agixtsdk/__init__.py

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,41 @@ def plan_task(
16751675
except Exception as e:
16761676
return self.handle_error(e)
16771677

1678+
def _generate_detailed_schema(self, model: Type[BaseModel], depth: int = 0) -> str:
1679+
"""
1680+
Recursively generates a detailed schema representation of a Pydantic model,
1681+
including nested models.
1682+
"""
1683+
fields = model.__annotations__
1684+
field_descriptions = []
1685+
indent = " " * depth
1686+
1687+
for field, field_type in fields.items():
1688+
description = f"{indent}{field}: "
1689+
1690+
if get_origin(field_type) == Union:
1691+
field_type = get_args(field_type)[0]
1692+
1693+
if isinstance(field_type, type) and issubclass(field_type, BaseModel):
1694+
description += f"Nested Model:\n{self._generate_detailed_schema(field_type, depth + 1)}"
1695+
elif get_origin(field_type) == List:
1696+
list_type = get_args(field_type)[0]
1697+
if isinstance(list_type, type) and issubclass(list_type, BaseModel):
1698+
description += f"List of Nested Model:\n{self._generate_detailed_schema(list_type, depth + 1)}"
1699+
else:
1700+
description += f"List[{list_type.__name__}]"
1701+
elif get_origin(field_type) == Dict:
1702+
key_type, value_type = get_args(field_type)
1703+
description += f"Dict[{key_type.__name__}, {value_type.__name__}]"
1704+
elif isinstance(field_type, type) and issubclass(field_type, Enum):
1705+
enum_values = ", ".join([f"{e.name} = {e.value}" for e in field_type])
1706+
description += f"{field_type.__name__} (Enum values: {enum_values})"
1707+
else:
1708+
description += f"{field_type.__name__}"
1709+
1710+
field_descriptions.append(description)
1711+
return "\n".join(field_descriptions)
1712+
16781713
def convert_to_model(
16791714
self,
16801715
input_string: str,
@@ -1688,7 +1723,6 @@ def convert_to_model(
16881723
Converts a string to a Pydantic model using an AGiXT agent.
16891724
16901725
Args:
1691-
16921726
input_string (str): The string to convert to a model.
16931727
model (Type[BaseModel]): The Pydantic model to convert the string to.
16941728
agent_name (str): The name of the AGiXT agent to use for the conversion.
@@ -1697,21 +1731,13 @@ def convert_to_model(
16971731
**kwargs: Additional arguments to pass to the AGiXT agent as prompt arguments.
16981732
"""
16991733
input_string = str(input_string)
1700-
fields = model.__annotations__
1701-
field_descriptions = []
1702-
for field, field_type in fields.items():
1703-
description = f"{field}: {field_type}"
1704-
if get_origin(field_type) == Union:
1705-
field_type = get_args(field_type)[0]
1706-
if isinstance(field_type, type) and issubclass(field_type, Enum):
1707-
enum_values = ", ".join([f"{e.name} = {e.value}" for e in field_type])
1708-
description += f" (Enum values: {enum_values})"
1709-
field_descriptions.append(description)
1710-
schema = "\n".join(field_descriptions)
1734+
schema = self._generate_detailed_schema(model)
1735+
17111736
if "user_input" in kwargs:
17121737
del kwargs["user_input"]
17131738
if "schema" in kwargs:
17141739
del kwargs["schema"]
1740+
17151741
response = self.prompt_agent(
17161742
agent_name=agent_name,
17171743
prompt_name="Convert to Model",
@@ -1721,10 +1747,12 @@ def convert_to_model(
17211747
**kwargs,
17221748
},
17231749
)
1750+
17241751
if "```json" in response:
17251752
response = response.split("```json")[1].split("```")[0].strip()
17261753
elif "```" in response:
17271754
response = response.split("```")[1].strip()
1755+
17281756
try:
17291757
response = json.loads(response)
17301758
if response_type == "json":

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup(
1010
name="agixtsdk",
11-
version="0.0.62",
11+
version="0.0.63",
1212
description="The AGiXT SDK for Python.",
1313
long_description=long_description,
1414
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)