Define GPT tool schemas using Pydantic.
Project description
GPT Pydantic Tools
The gpt_pydantic_tools
repository offers a Python module designed to integrate Pydantic models with GPT-style tool schemas. It facilitates the transformation of Pydantic models into a format that is suitable for use with GPT-4's tools functionality, ensuring structured data and tool interaction consistency.
Features
- Model Conversion: Convert Pydantic models into GPT-4 tool schemas.
- Flexible Tool Choice Handling: Provides several strategies for tool invocation such as auto, required, and none, based on the context or specific requirements.
Installation
Install directly using pip:
pip install gpt-pydantic-tools
Usage
- Define Pydantic Models: Create your Pydantic models as per your requirements.
- Convert to GPT Tool Schema: Use the
ToolSchemaManager
to convert your Pydantic models into GPT tool schemas. - Tool Choice Management: Utilize the
get_tool_choice_dict
to manage how tools are chosen for execution based on the defined strategies.
Example usage:
from pydantic import BaseModel
from gpt_pydantic_tools import ToolSchemaManager, get_tool_choice_dict, ToolChoiceEnum
class MyModel(BaseModel):
name: str
age: int
# Convert Pydantic model to GPT tool schema
schema_manager = ToolSchemaManager(pydantic_obj=MyModel)
tool_schema = schema_manager.tools_schema
# Determine tool invocation strategy
tool_choice = get_tool_choice_dict(ToolChoiceEnum.AUTO, schema_manager)
If you want to do the Pydantic Schema conversion yourself, and directly provide the JSON instead, you can do:
schema_manager = ToolSchemaManager(pydantic_obj_json_schema=my_model_json_schema)
Contributing
Contributions are welcome! Please feel free to submit pull requests, create issues, and suggest improvements to the repository.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file gpt_pydantic_tools-0.2.tar.gz
.
File metadata
- Download URL: gpt_pydantic_tools-0.2.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79a2258190c03c84624b494d21bab5ab66fdac7a86adb9cdbb66de22e4383918 |
|
MD5 | ae39800896abd8847ad9a1371627214b |
|
BLAKE2b-256 | 1eb1bc022cc16e6f3a3b46ae59d52ff996ea63e1527375755f94641a311633a2 |
File details
Details for the file gpt_pydantic_tools-0.2-py3-none-any.whl
.
File metadata
- Download URL: gpt_pydantic_tools-0.2-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24ca9549ee89c1694dc5526c2c7ae03cea82045b572606fee7452318b46b7ed8 |
|
MD5 | be9e6b59322c4692a3929d892f7a3a00 |
|
BLAKE2b-256 | 5a6283ecf6e158fe41bfcaf683a9de87a1654dc8ec8789578f4ed11f32296d1a |