Last active
December 26, 2024 19:08
-
-
Save intellectronica/9b190aca94bf4372c4b08e8b016922ec to your computer and use it in GitHub Desktop.
pydantic-ai-openai-strict.ipynb
Nice! You can probably simplify
_map_tool_definition
todef _map_tool_definition(f: ToolDefinition) -> ChatCompletionToolParam: tool_param = super()._map_tool_definition(f) tool_param['function']['strict'] = True return tool_param
@samuelcolvin Almost. super()
can't be used like this, but we can just call the method from the class explicitly. And we need to also set additionalProperties
.
This works:
@staticmethod
def _map_tool_definition(f: ToolDefinition) -> ChatCompletionToolParam:
tool_def = OpenAIModel._map_tool_definition(f)
tool_def['function']['strict'] = True
tool_def['function']['parameters']['additionalProperties'] = False
return tool_def
Gist updated. Thanks for the suggestion, this is more elegant and less duplicative.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! You can probably simplify
_map_tool_definition
to