genkit icon indicating copy to clipboard operation
genkit copied to clipboard

feat(go/genkit): add DefineSchema and Dotprompt reference support

Open ihan211 opened this issue 8 months ago • 1 comments

This PR adds a schema definition system to genkit with Dotprompt reference support.

Key Components

  • Schema registration with Dotprompt framework
  • DefineSchema API 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)

ihan211 avatar Apr 16 '25 01:04 ihan211

Tests are not passing, can you resolve that first?

apascal07 avatar Apr 17 '25 21:04 apascal07