mirror of
https://github.com/warmbly/warmbly.git
synced 2026-08-19 00:01:14 +00:00
27 lines
500 B
Go
27 lines
500 B
Go
package generation
|
|
|
|
import (
|
|
"github.com/invopop/jsonschema"
|
|
"github.com/openai/openai-go/v2"
|
|
"github.com/openai/openai-go/v2/option"
|
|
)
|
|
|
|
func GenerateSchema[T any]() *jsonschema.Schema {
|
|
reflector := jsonschema.Reflector{
|
|
AllowAdditionalProperties: false,
|
|
}
|
|
var v T
|
|
return reflector.Reflect(v)
|
|
}
|
|
|
|
type GenerationClient struct {
|
|
client openai.Client
|
|
}
|
|
|
|
func NewClient(apiKey string) *GenerationClient {
|
|
return &GenerationClient{
|
|
client: openai.NewClient(option.WithAPIKey(apiKey)),
|
|
}
|
|
|
|
}
|