Skip to content

Commit

Permalink
🔍 Improve logging, remove sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
shroominic committed Nov 22, 2023
1 parent cad3b8b commit 6c18f6c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/funcchain/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,19 @@ def _remove_a_key(d: dict, remove_key: str) -> None:


def pydantic_to_functions(pydantic_object: Type[BaseModel]) -> dict[str, Any]:
from rich import print

schema = pydantic_object.schema()
docstring = parse(pydantic_object.__doc__ or "")
parameters = {k: v for k, v in schema.items() if k not in ("title", "description")}

for param in docstring.params:
if (name := param.arg_name) in parameters["properties"] and (
description := param.description
):
if "description" not in parameters["properties"][name]:
parameters["properties"][name]["description"] = description

parameters["required"] = sorted(
k for k, v in parameters["properties"].items() if "default" not in v
)
parameters["type"] = "object"

if "description" not in schema:
Expand All @@ -126,6 +126,15 @@ def pydantic_to_functions(pydantic_object: Type[BaseModel]) -> dict[str, Any]:
_remove_a_key(parameters, "title")
_remove_a_key(parameters, "additionalProperties")

print(
"pydantic_to_functions",
{
"name": pydantic_object.__name__.lower(),
"description": schema["description"],
"parameters": parameters,
},
)

return {
"function_call": {
"name": pydantic_object.__name__.lower(),
Expand Down

0 comments on commit 6c18f6c

Please sign in to comment.