Documentation
¶
Index ¶
- Variables
- type ModelGenerator
- func (g *ModelGenerator) Generate(ctx context.Context, ...) (*ai.ModelResponse, error)
- func (g *ModelGenerator) GetRequest() *openai.ChatCompletionNewParams
- func (g *ModelGenerator) WithConfig(config any) *ModelGenerator
- func (g *ModelGenerator) WithMessages(messages []*ai.Message) *ModelGenerator
- func (g *ModelGenerator) WithTools(tools []*ai.ToolDefinition, choice ai.ToolChoice) *ModelGenerator
- type OpenAICompatible
- func (o *OpenAICompatible) DefineEmbedder(g *genkit.Genkit, provider, name string) (ai.Embedder, error)
- func (o *OpenAICompatible) DefineModel(g *genkit.Genkit, provider, name string, info ai.ModelInfo) (ai.Model, error)
- func (o *OpenAICompatible) Embedder(g *genkit.Genkit, name string, provider string) ai.Embedder
- func (o *OpenAICompatible) Init(ctx context.Context, g *genkit.Genkit) error
- func (o *OpenAICompatible) IsDefinedEmbedder(g *genkit.Genkit, name string, provider string) bool
- func (o *OpenAICompatible) IsDefinedModel(g *genkit.Genkit, name string, provider string) bool
- func (o *OpenAICompatible) Model(g *genkit.Genkit, name string, provider string) ai.Model
- func (o *OpenAICompatible) Name() string
- type OpenAIConfig
Constants ¶
This section is empty.
Variables ¶
var ( // BasicText describes model capabilities for text-only GPT models. BasicText = ai.ModelInfo{ Supports: &ai.ModelSupports{ Multiturn: true, Tools: true, SystemRole: true, Media: false, }, } // Multimodal describes model capabilities for multimodal GPT models. Multimodal = ai.ModelInfo{ Supports: &ai.ModelSupports{ Multiturn: true, Tools: true, SystemRole: true, Media: true, ToolChoice: true, }, } )
Functions ¶
This section is empty.
Types ¶
type ModelGenerator ¶
type ModelGenerator struct {
// contains filtered or unexported fields
}
ModelGenerator handles OpenAI generation requests
func NewModelGenerator ¶
func NewModelGenerator(client *openai.Client, modelName string) *ModelGenerator
NewModelGenerator creates a new ModelGenerator instance
func (*ModelGenerator) Generate ¶
func (g *ModelGenerator) Generate(ctx context.Context, handleChunk func(context.Context, *ai.ModelResponseChunk) error) (*ai.ModelResponse, error)
Generate executes the generation request
func (*ModelGenerator) GetRequest ¶
func (g *ModelGenerator) GetRequest() *openai.ChatCompletionNewParams
func (*ModelGenerator) WithConfig ¶
func (g *ModelGenerator) WithConfig(config any) *ModelGenerator
WithConfig adds configuration parameters from the model request see https://platform.openai.com/docs/api-reference/responses/create for more details on openai's request fields
func (*ModelGenerator) WithMessages ¶
func (g *ModelGenerator) WithMessages(messages []*ai.Message) *ModelGenerator
WithMessages adds messages to the request
func (*ModelGenerator) WithTools ¶
func (g *ModelGenerator) WithTools(tools []*ai.ToolDefinition, choice ai.ToolChoice) *ModelGenerator
WithTools adds tools to the request
type OpenAICompatible ¶
type OpenAICompatible struct { // Opts contains request options for the OpenAI client. // Required: Must include at least WithAPIKey for authentication. // Optional: Can include other options like WithOrganization, WithBaseURL, etc. Opts []option.RequestOption // Provider is a unique identifier for the plugin. // This will be used as a prefix for model names (e.g., "myprovider/model-name"). // Should be lowercase and match the plugin's Name() method. Provider string // contains filtered or unexported fields }
OpenAICompatible is a plugin that provides compatibility with OpenAI's Compatible APIs. It allows defining models and embedders that can be used with Genkit.
func (*OpenAICompatible) DefineEmbedder ¶
func (o *OpenAICompatible) DefineEmbedder(g *genkit.Genkit, provider, name string) (ai.Embedder, error)
DefineEmbedder defines an embedder with a given name.
func (*OpenAICompatible) DefineModel ¶
func (o *OpenAICompatible) DefineModel(g *genkit.Genkit, provider, name string, info ai.ModelInfo) (ai.Model, error)
DefineModel defines a model in the registry
func (*OpenAICompatible) Embedder ¶
Embedder returns the ai.Embedder with the given name. It returns nil if the embedder was not defined.
func (*OpenAICompatible) IsDefinedEmbedder ¶
IsDefinedEmbedder reports whether the named [Embedder] is defined by this plugin.
func (*OpenAICompatible) IsDefinedModel ¶
IsDefinedModel reports whether the named [Model] is defined by this plugin.
func (*OpenAICompatible) Model ¶
Model returns the ai.Model with the given name. It returns nil if the model was not defined.
func (*OpenAICompatible) Name ¶
func (o *OpenAICompatible) Name() string
Name implements genkit.Plugin.
type OpenAIConfig ¶
type OpenAIConfig struct { // Maximum number of tokens to generate MaxOutputTokens int `json:"max_output_tokens,omitempty"` // Temperature for sampling Temperature float64 `json:"temperature,omitempty"` // Top-p value for nucleus sampling TopP float64 `json:"top_p,omitempty"` // List of sequences where the model will stop generating StopSequences []string `json:"stop_sequences,omitempty"` }
OpenaiConfig mirrors the OpenAI API configuration fields