genkit
genkit copied to clipboard
feat(go/genkit): add DefineSchema and Dotprompt reference support
This PR adds a schema definition system to genkit with Dotprompt reference support.
Key Components
- Schema registration with Dotprompt framework
DefineSchemaAPI for defining prompt data structures- Enhanced initialization process for schema registration
- Schema resolution within templates
Example Usage
// Define a product schema
type ProductSchema struct {
Name string `json:"name"`
Description string `json:"description"`
Price float64 `json:"price"`
Category string `json:"category"`
InStock bool `json:"inStock"`
}
// Register the schema with genkit
genkit.DefineSchema("ProductSchema", ProductSchema{})
// Reference the schema in a Dotprompt template
// promptContent example:
// ---
// input:
// schema:
// theme: string
// output:
// schema: ProductSchema
// ---
// Generate a product that fits the {{theme}} theme.
// Make sure to provide a detailed description and appropriate pricing.
The implementation enables:
* Automatic schema registration during Genkit initialization
* Structured output parsing from model responses to Go structs
* Schema reference resolution within Dotprompt templates
* JSON Schema support for standardized type definitions
Testing
Unit tests in schema_test.go
Working example in samples directory
Checklist (if applicable):
- [X] PR title is following https://www.conventionalcommits.org/en/v1.0.0/
- [X] Tested (manually, unit tested, etc.)
- [ ] Docs updated (updated docs or a docs bug required)
Tests are not passing, can you resolve that first?