Skip to main content

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gpt_pydantic_tools-0.3.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gpt_pydantic_tools-0.3-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file gpt_pydantic_tools-0.3.tar.gz.

File metadata

  • Download URL: gpt_pydantic_tools-0.3.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for gpt_pydantic_tools-0.3.tar.gz
Algorithm Hash digest
SHA256 a304a86d124c2c8993bf2c9b33e1dad1ff9a6e46f0e1ab3901b86d57fbb66dd2
MD5 a5bcd5a26991631b4afc5e4e673900d5
BLAKE2b-256 51b85733912569a83da62f1bf572efff015c8127c292fdad3288039cd8f958d7

See more details on using hashes here.

File details

Details for the file gpt_pydantic_tools-0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for gpt_pydantic_tools-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 96bf0982e0bc8271260c486ffe507bf1a10a35763f14075b3fc94e85cf24c283
MD5 b57e1f9a52d8e9e73f314a33630c1850
BLAKE2b-256 7a9c62bd0749a00c270a56827cf323c247091e35067e1c1f5dc50b621207fd8f

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.3 This release

2 files

0.2

2 files

0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page