Download the PHP package opctim/chatgpt-schema-generator without Composer
On this page you can find all versions of the php package opctim/chatgpt-schema-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download opctim/chatgpt-schema-generator
More information about opctim/chatgpt-schema-generator
Files in opctim/chatgpt-schema-generator
Package chatgpt-schema-generator
Short Description This bundle creates a JSON schema from your classes or DTOs to be used with the ChatGPT API so that you get back what you expect.
License MIT
Informations about the package chatgpt-schema-generator
OpenAI ChatGPT JSON Schema Generator
Easily generate JSON Schemas for OpenAI ChatGPT prompts using your PHP DTOs!
This package allows you to dynamically create JSON Schemas based on your DTO (Data Transfer Object) classes. These schemas can be passed to OpenAI’s ChatGPT API to ensure consistent, structured, and strongly-typed JSON responses. Ideal for developers who want precise control over ChatGPT outputs in their applications.
Key Features
- Seamless Schema Generation: Automatically generate JSON Schemas from your PHP DTO classes.
- Enum Support: Define strict enums in your DTO, and ChatGPT will adhere to your choices.
- Integration Ready: Easily pass the generated schemas to OpenAI APIs for structured responses.
- Serialization Support: Deserialize the JSON response back into your DTO with ease.
- Clean and Reusable Code: Write less boilerplate and focus on building smarter applications.
Requirements
- PHP >= 8.3
Installation
Usage
Excluding Properties & Classes
You can either replace properties:
Or the whole class:
Union Types
Union types will be returned as oneOf in the JSON schema.
If your class has a property that looks like this:
The result will be:
Schema output example
Result
Tests
Tests are located inside the tests/
folder and can be run with vendor/bin/phpunit
:
All versions of chatgpt-schema-generator with dependencies
phpdocumentor/reflection-docblock Version ^5.6
symfony/property-info Version >=5.4
symfony/serializer Version >=5.4