Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

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 uv:

uv add gpt-pydantic-tools

Usage

  1. Define Pydantic Models: Create your Pydantic models as per your requirements.
  2. Convert to GPT Tool Schema: Use the ToolSchemaManager to convert your Pydantic models into GPT tool schemas.
  3. 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.

Metadata

Release files for gpt-pydantic-tools 0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gpt-pydantic-tools 0.3
File Size Uploaded
gpt_pydantic_tools-0.3.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gpt-pydantic-tools 0.3
File Interpreter ABI Platform
gpt_pydantic_tools-0.3-py3-none-any.whl Python 3 none any Details

Total release size: 9.2 kB

Release files / gpt_pydantic_tools-0.3.tar.gz

Download URL gpt_pydantic_tools-0.3.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a304a86d124c2c8993bf2c9b33e1dad1ff9a6e46f0e1ab3901b86d57fbb66dd2
BLAKE2b-256 checksum
How to use checksums
51b85733912569a83da62f1bf572efff015c8127c292fdad3288039cd8f958d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / gpt_pydantic_tools-0.3-py3-none-any.whl

Download URL gpt_pydantic_tools-0.3-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
96bf0982e0bc8271260c486ffe507bf1a10a35763f14075b3fc94e85cf24c283
BLAKE2b-256 checksum
How to use checksums
7a9c62bd0749a00c270a56827cf323c247091e35067e1c1f5dc50b621207fd8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

0.3 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page