-
Notifications
You must be signed in to change notification settings - Fork 271
Add JSON Schema Definition for gen_ai.tool.definitions #2793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"$defs": { | ||
"ToolDefinition": { | ||
"additionalProperties": true, | ||
"properties": { | ||
"type": { | ||
"anyOf": [ | ||
{ | ||
"$ref": "#/$defs/ToolType" | ||
}, | ||
{ | ||
"type": "string" | ||
} | ||
], | ||
"description": "Type of the tool.", | ||
"title": "ToolType" | ||
}, | ||
"name": { | ||
"description": "Name of the tool.", | ||
"title": "Name", | ||
"type": "string" | ||
}, | ||
"description": { | ||
"description": "Description of the tool.", | ||
"title": "Description", | ||
"type": "string" | ||
}, | ||
"parameters": { | ||
"description": "Format of the tool parameters. Maybe it is a JSON schema.", | ||
"title": "Parameters" | ||
}, | ||
"response": { | ||
"description": "Format of the tool response. Maybe it is a JSON schema.", | ||
"title": "Response" | ||
} | ||
}, | ||
"required": [ | ||
"type", | ||
"name" | ||
], | ||
"title": "ToolDefinition", | ||
"type": "object" | ||
}, | ||
"ToolType": { | ||
"enum": [ | ||
"function", | ||
"custom" | ||
], | ||
"title": "ToolType", | ||
"type": "string" | ||
} | ||
}, | ||
"description": "Represents the list of tool definitions sent to the model.", | ||
"items": { | ||
"$ref": "#/$defs/ToolDefinition" | ||
}, | ||
"title": "ToolDefinitions", | ||
"type": "array" | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -41,7 +41,7 @@ | |||||
}, | ||||||
{ | ||||||
"cell_type": "code", | ||||||
"execution_count": 1, | ||||||
"execution_count": null, | ||||||
"id": "5124fe15", | ||||||
"metadata": {}, | ||||||
"outputs": [], | ||||||
|
@@ -117,7 +117,24 @@ | |||||
" description=\"List of message parts that make up the message content.\")\n", | ||||||
"\n", | ||||||
" class Config:\n", | ||||||
" extra = \"allow\"" | ||||||
" extra = \"allow\"\n", | ||||||
"\n", | ||||||
"class ToolType(str, Enum):\n", | ||||||
" FUNCTION = \"function\"\n", | ||||||
" CUSTOM = \"custom\"\n", | ||||||
"\n", | ||||||
"class ToolDefinition(BaseModel):\n", | ||||||
" \"\"\"\n", | ||||||
" Represents a tool definition.\n", | ||||||
" \"\"\"\n", | ||||||
" type: Union[ToolType, str] = Field(description=\"Type of the tool.\")\n", | ||||||
" name: str = Field(description=\"Name of the tool.\")\n", | ||||||
" description: str = Field(description=\"Description of the tool.\")\n", | ||||||
" parameters: Any = Field(description=\"Format of the tool parameters. Maybe it is a JSON schema.\")\n", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
"Maybe it is a JSON schema" does not seem to be definitive enough. |
||||||
" response: Any = Field(description=\"Format of the tool response. Maybe it is a JSON schema.\")\n", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me add more example soon. |
||||||
"\n", | ||||||
" class Config:\n", | ||||||
" extra = \"allow\"\n" | ||||||
] | ||||||
}, | ||||||
{ | ||||||
|
@@ -222,6 +239,34 @@ | |||||
"# Print the JSON schema for the SystemInstructions model\n", | ||||||
"print(json.dumps(SystemInstructions.model_json_schema(), indent=4))" | ||||||
] | ||||||
}, | ||||||
{ | ||||||
"cell_type": "markdown", | ||||||
"id": "f019c33a", | ||||||
"metadata": {}, | ||||||
"source": [ | ||||||
"## `gen_ai.tool.definitions` model\n", | ||||||
"\n", | ||||||
"Corresponding attribute: [`gen_ai.tool.definitions`](/docs/registry/attributes/gen-ai.md#gen-ai-tool-definitions).\n", | ||||||
"JSON schema: [`gen_ai-tool-definitions.json`](../gen-ai-tool-definitions.json)" | ||||||
] | ||||||
}, | ||||||
{ | ||||||
"cell_type": "code", | ||||||
"execution_count": null, | ||||||
"id": "a9e84726", | ||||||
"metadata": {}, | ||||||
"outputs": [], | ||||||
"source": [ | ||||||
"class ToolDefinitions(RootModel[List[ToolDefinition]]):\n", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think ToolDefinition should be defined in this cell since it's not used elsewhere |
||||||
" \"\"\"\n", | ||||||
" Represents the list of tool definitions available to the GenAI agent or model.\n", | ||||||
" \"\"\"\n", | ||||||
" pass\n", | ||||||
"\n", | ||||||
"# Print the JSON schema for the ToolDefinitions model\n", | ||||||
"print(json.dumps(ToolDefinitions.model_json_schema(), indent=4))" | ||||||
] | ||||||
} | ||||||
], | ||||||
"metadata": { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does these mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://platform.openai.com/docs/api-reference/chat/get. OpenAI provide a 'custom' type for those tools who are not a function in a general sence - they usually have more customized input formats.