Skip to content

Commit

Permalink
Update schema formater
Browse files Browse the repository at this point in the history
  • Loading branch information
badgeir committed Nov 1, 2024
1 parent 97cc2a5 commit a73a40c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
9 changes: 7 additions & 2 deletions llmio/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ def function_definition(self) -> T.FunctionDefinition:
"""
Returns the tool schema that is sent to the OpenAI API.
"""
schema = self.params.schema()
schema = self.params.model_json_schema()

schema.pop("title", None)
for prop in schema.get("properties", {}).values():
prop.pop("title", None)

if self.strict:
schema["additionalProperties"] = False
return T.FunctionDefinition(
Expand Down Expand Up @@ -537,7 +542,7 @@ async def speak(

@property
def response_format(self) -> dict[str, Any]:
schema = self._response_format.schema()
schema = self._response_format.model_json_schema()
schema["additionalProperties"] = False
return {
"type": "json_schema",
Expand Down
10 changes: 2 additions & 8 deletions llmio/function_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,5 @@ def model_from_function(function: Callable) -> type[BaseModel]:
"Unable to parse function signature. Only named arguments supported."
)

class Config:
@staticmethod
def json_schema_extra(schema: Dict[str, Any]) -> None:
schema.pop("title", None)
for prop in schema.get("properties", {}).values():
prop.pop("title", None)

return create_model(to_camel(function.__name__), __config__=Config, **fields) # type: ignore
model = create_model(to_camel(function.__name__), **fields) # type: ignore
return model

0 comments on commit a73a40c

Please sign in to comment.