SDK for structured, typehinted GPT responses
Top 47.7% on sourcepulse
This library provides a Python wrapper for OpenAI's GPT models, enabling users to declaratively define expected output formats using Pydantic schemas. It simplifies structured data extraction from LLM responses, supporting various GPT features like Vision API and Function Calling, and includes built-in retry logic and JSON transformation for common API failures.
How It Works
The core mechanism involves defining Pydantic models that represent the desired output structure. The library then injects a JSON schema derived from these models into the prompt, instructing the GPT model to adhere to this format. It supports both single object and list responses, and can integrate with GPT's function calling capabilities by mapping Pydantic models to function signatures.
Quick Start & Requirements
pip install gpt-json
Highlighted Details
Maintenance & Community
Licensing & Compatibility
Limitations & Caveats
The library is specifically tailored for the GPT-X family of models and does not support Hugging Face models due to differences in output mechanisms like logit probabilities and fixed decoder templating. While it attempts to fix common JSON errors, GPT's output can still be unpredictable, and users may need to implement custom logic for edge cases.
1 year ago
1 day