Documentation
¶
Index ¶
- Variables
- func EmbedderRef(name string, config *genai.EmbedContentConfig) ai.EmbedderRef
- func GetEmbedderOptions(name, provider string) ai.EmbedderOptions
- func GetModelOptions(name, provider string) ai.ModelOptions
- func GoogleAIEmbedder(g *genkit.Genkit, id string) ai.Embedderdeprecated
- func GoogleAIModel(g *genkit.Genkit, id string) ai.Modeldeprecated
- func GoogleAIModelRef(id string, config *genai.GenerateContentConfig) ai.ModelRefdeprecated
- func HasCodeExecution(msg *ai.Message) bool
- func ImageModelRef(name string, config *genai.GenerateImagesConfig) ai.ModelRef
- func ModelRef(name string, config *genai.GenerateContentConfig) ai.ModelRef
- func RetryDelay(err error) (time.Duration, bool)
- func VertexAIEmbedder(g *genkit.Genkit, id string) ai.Embedderdeprecated
- func VertexAIModel(g *genkit.Genkit, id string) ai.Modeldeprecated
- func VertexAIModelRef(id string, config *genai.GenerateContentConfig) ai.ModelRefdeprecated
- func VideoModelRef(name string, config *genai.GenerateVideosConfig) ai.ModelRef
- type CodeExecutionResult
- type ExecutableCode
- type GoogleAI
- func (ga *GoogleAI) Client() (*genai.Client, error)
- func (ga *GoogleAI) DefineEmbedder(g *genkit.Genkit, id string, embedOpts *ai.EmbedderOptions) (ai.Embedder, error)deprecated
- func (ga *GoogleAI) DefineModel(g *genkit.Genkit, id string, opts *ai.ModelOptions) (ai.Model, error)deprecated
- func (ga *GoogleAI) Init(ctx context.Context) []api.Action
- func (ga *GoogleAI) IsDefinedEmbedder(g *genkit.Genkit, id string) booldeprecated
- func (ga *GoogleAI) ListActions(ctx context.Context) []api.ActionDesc
- func (ga *GoogleAI) Name() string
- func (ga *GoogleAI) ResolveAction(atype api.ActionType, id string) api.Action
- type ModelType
- type VertexAI
- func (v *VertexAI) Client() (*genai.Client, error)
- func (v *VertexAI) DefineEmbedder(g *genkit.Genkit, id string, embedOpts *ai.EmbedderOptions) (ai.Embedder, error)deprecated
- func (v *VertexAI) DefineModel(g *genkit.Genkit, id string, opts *ai.ModelOptions) (ai.Model, error)deprecated
- func (v *VertexAI) Init(ctx context.Context) []api.Action
- func (v *VertexAI) IsDefinedEmbedder(g *genkit.Genkit, id string) booldeprecated
- func (v *VertexAI) ListActions(ctx context.Context) []api.ActionDesc
- func (v *VertexAI) Name() string
- func (v *VertexAI) ResolveAction(atype api.ActionType, id string) api.Action
Constants ¶
This section is empty.
Variables ¶
var ( // BasicText describes model capabilities for text-only Gemini models. BasicText = ai.ModelSupports{ Multiturn: true, Tools: true, ToolChoice: true, SystemRole: true, Media: false, } // Multimodal describes model capabilities for multimodal Gemini models. Multimodal = ai.ModelSupports{ Multiturn: true, Tools: true, ToolChoice: true, SystemRole: true, Media: true, Constrained: ai.ConstrainedSupportAll, } // Media describes model capabilities for image generation models (Imagen). Media = ai.ModelSupports{ Multiturn: false, Tools: false, SystemRole: false, Media: true, Output: []string{"media"}, } // VeoSupports describes model capabilities for video generation models (Veo). VeoSupports = ai.ModelSupports{ Media: true, Multiturn: false, Tools: false, SystemRole: false, Output: []string{"media"}, LongRunning: true, } // TTSSupports describes model capabilities for text-to-speech models // (gemini-*-tts). They emit audio and, unlike conversational Gemini models, // do not support tools, multi-turn history, or system roles. Output is // "media" to match the convention used by the other media producers // (Imagen, Veo) rather than a TTS-only token. TTSSupports = ai.ModelSupports{ Multiturn: false, Media: false, Tools: false, ToolChoice: false, SystemRole: false, Output: []string{"media"}, } )
Model capability definitions - these describe what different model types support.
Functions ¶
func EmbedderRef ¶ added in v1.5.0
func EmbedderRef(name string, config *genai.EmbedContentConfig) ai.EmbedderRef
EmbedderRef creates an EmbedderRef for an embedding model. The name should include provider prefix (e.g., "googleai/text-embedding-004").
func GetEmbedderOptions ¶ added in v1.5.0
func GetEmbedderOptions(name, provider string) ai.EmbedderOptions
GetEmbedderOptions returns EmbedderOptions for an embedder name with provider-prefixed label.
func GetModelOptions ¶ added in v1.5.0
func GetModelOptions(name, provider string) ai.ModelOptions
GetModelOptions returns ModelOptions for a model name with provider-prefixed label. The returned options share the package's schema maps and supports structs; they are read-only and must not be mutated.
func GoogleAIEmbedder
deprecated
func GoogleAIModelRef
deprecated
added in
v0.5.0
func GoogleAIModelRef(id string, config *genai.GenerateContentConfig) ai.ModelRef
GoogleAIModelRef creates a ModelRef for a Google AI Gemini model.
Deprecated: Use ModelRef with full name instead.
func HasCodeExecution ¶ added in v0.5.1
HasCodeExecution checks if a message contains code execution results or executable code.
func ImageModelRef ¶ added in v1.5.0
func ImageModelRef(name string, config *genai.GenerateImagesConfig) ai.ModelRef
ImageModelRef creates a ModelRef for an image generation model. The name should include provider prefix (e.g., "googleai/imagen-4.0-generate-001").
func ModelRef ¶ added in v1.3.0
func ModelRef(name string, config *genai.GenerateContentConfig) ai.ModelRef
ModelRef creates a ModelRef for a Gemini model. The name should include provider prefix (e.g., "googleai/gemini-flash-latest").
func RetryDelay ¶ added in v1.12.0
RetryDelay reports the delay the service asked the caller to wait before retrying, taken from the google.rpc.RetryInfo detail that Gemini and Vertex AI attach to RESOURCE_EXHAUSTED (429) errors. It reads errors returned by this plugin's actions, including wrapped ones. The second result is false when err carries no retry information.
func VertexAIEmbedder
deprecated
func VertexAIModelRef
deprecated
added in
v0.5.0
func VertexAIModelRef(id string, config *genai.GenerateContentConfig) ai.ModelRef
VertexAIModelRef creates a ModelRef for a Vertex AI Gemini model.
Deprecated: Use ModelRef with full name instead.
func VideoModelRef ¶ added in v1.5.0
func VideoModelRef(name string, config *genai.GenerateVideosConfig) ai.ModelRef
VideoModelRef creates a ModelRef for a video generation model. The name should include provider prefix (e.g., "googleai/veo-3.1-generate-preview").
Types ¶
type CodeExecutionResult ¶ added in v0.5.1
CodeExecutionResult represents the result of a code execution.
func GetCodeExecutionResult ¶ added in v0.5.1
func GetCodeExecutionResult(msg *ai.Message) *CodeExecutionResult
GetCodeExecutionResult returns the first code execution result from a message. Returns nil if the message doesn't contain a code execution result.
func ToCodeExecutionResult ¶ added in v0.5.1
func ToCodeExecutionResult(part *ai.Part) *CodeExecutionResult
ToCodeExecutionResult tries to convert an ai.Part to a CodeExecutionResult. Returns nil if the part doesn't contain code execution results.
type ExecutableCode ¶ added in v0.5.1
ExecutableCode represents executable code.
func GetExecutableCode ¶ added in v0.5.1
func GetExecutableCode(msg *ai.Message) *ExecutableCode
GetExecutableCode returns the first executable code from a message. Returns nil if the message doesn't contain executable code.
func ToExecutableCode ¶ added in v0.5.1
func ToExecutableCode(part *ai.Part) *ExecutableCode
ToExecutableCode tries to convert an ai.Part to an ExecutableCode. Returns nil if the part doesn't contain executable code.
type GoogleAI ¶
type GoogleAI struct {
APIKey string // API key to access the service. If empty, the values of the environment variables GEMINI_API_KEY or GOOGLE_API_KEY will be consulted, in that order.
APIVersion string // API version to use ("v1", "v1beta", or "v1alpha"). If empty, the genai SDK default (v1beta) is used. Can be overridden per-request via config.HTTPOptions.APIVersion.
// BaseURL overrides the default API endpoint
// (https://generativelanguage.googleapis.com), e.g. to point at a proxy
// or an API gateway. Optional.
BaseURL string
// Headers are additional HTTP headers to send with every request. They
// are merged over the plugin's default headers, so a header set here wins
// on collision. Optional.
Headers http.Header
// HTTPClient is the HTTP client used for API requests. When set, it is
// used verbatim: the plugin does not install its default OpenTelemetry
// instrumented transport, so wrap your own transport with otelhttp if you
// want tracing. Optional.
HTTPClient *http.Client
// Models overrides what the plugin knows about a model, keyed by model ID.
// Every model the backend serves already works without an entry here:
// known IDs carry curated capabilities and the rest take the defaults for
// their kind. Supply an entry only to correct or extend what the plugin
// resolves, most often to describe a model released after this version of
// the plugin.
//
// &googlegenai.GoogleAI{Models: map[string]ai.ModelOptions{
// "gemini-flash-latest": {Supports: &ai.ModelSupports{Tools: true, Multiturn: true}},
// }}
//
// Fields left at their zero value keep what the plugin resolves, so an
// entry can pin one capability without restating the label or the config
// schema. Gemini, Imagen and Veo IDs are all keyed the same way, and
// entries apply to the actions [GoogleAI.ListActions] advertises as well
// as the ones [GoogleAI.ResolveAction] builds to serve a request.
Models map[string]ai.ModelOptions
// Embedders overrides what the plugin knows about an embedder, keyed by
// embedder ID. It works exactly as Models does.
Embedders map[string]ai.EmbedderOptions
// contains filtered or unexported fields
}
GoogleAI is a Genkit plugin for interacting with the Google AI service.
func (*GoogleAI) Client ¶ added in v1.12.0
Client returns the underlying Google GenAI SDK client used by the plugin. It gives access to service features that Genkit does not wrap, such as the Files, Caches, Batches, and Tunings APIs. It returns an error if the plugin has not been initialized.
func (*GoogleAI) DefineEmbedder
deprecated
func (ga *GoogleAI) DefineEmbedder(g *genkit.Genkit, id string, embedOpts *ai.EmbedderOptions) (ai.Embedder, error)
DefineEmbedder defines an embedder with a given ID.
Deprecated: describe the embedder through GoogleAI.Embedders instead. Like GoogleAI.DefineModel, this method builds the embedder and ignores g, so embedding by that name serves the request with the capabilities the plugin resolves rather than the ones passed here.
func (*GoogleAI) DefineModel
deprecated
func (ga *GoogleAI) DefineModel(g *genkit.Genkit, id string, opts *ai.ModelOptions) (ai.Model, error)
DefineModel defines an unknown model with the given ID. The second argument describes the capability of the model.
Deprecated: describe the model through GoogleAI.Models instead. This method builds the model and ignores g, so the result carries only the model's name: generation resolves a model from that name and serves the request with the capabilities the plugin resolves, not the ones passed here. An entry in Models reaches both paths.
func (*GoogleAI) Init ¶
Init initializes the Google AI plugin and all known models and embedders. After calling Init, you may call [DefineModel] and [DefineEmbedder] to create and register any additional generative models and embedders
func (*GoogleAI) IsDefinedEmbedder
deprecated
IsDefinedEmbedder reports whether the [Embedder] is defined by this plugin.
Deprecated: this existed to guard a registration call that could panic on a duplicate. Capabilities now come from GoogleAI.Embedders, which nothing has to register and which no ordering can defeat, leaving this a question about registry state that applications do not need to ask.
func (*GoogleAI) ListActions ¶ added in v0.6.0
func (ga *GoogleAI) ListActions(ctx context.Context) []api.ActionDesc
ListActions lists all the actions supported by the Google AI plugin.
func (*GoogleAI) ResolveAction ¶ added in v0.6.0
ResolveAction resolves an action with the given ID.
type ModelType ¶ added in v1.5.0
type ModelType int
ModelType categorizes models by their generation modality.
func ClassifyModel ¶ added in v1.5.0
ClassifyModel determines the model type from its name. This is the single source of truth for model type classification.
func (ModelType) ActionType ¶ added in v1.5.0
func (mt ModelType) ActionType() api.ActionType
ActionType returns the appropriate API action type for this model type.
func (ModelType) DefaultConfig ¶ added in v1.5.0
DefaultConfig returns the default config struct for this model type.
func (ModelType) DefaultSupports ¶ added in v1.5.0
func (mt ModelType) DefaultSupports() *ai.ModelSupports
DefaultSupports returns the default ModelSupports for this model type.
type VertexAI ¶
type VertexAI struct {
ProjectID string // Google Cloud project to use for Vertex AI. If empty, the value of the environment variable GOOGLE_CLOUD_PROJECT will be consulted.
Location string // Location of the Vertex AI service. If empty, GOOGLE_CLOUD_LOCATION and GOOGLE_CLOUD_REGION environment variables will be consulted, in that order. Accepts a regional location (e.g. "us-central1"), a multi-region location ("us" or "eu"), or "global".
APIVersion string // API version to use ("v1" or "v1beta1"). If empty, the genai SDK default (v1beta1) is used. Can be overridden per-request via config.HTTPOptions.APIVersion.
// APIKey enables Vertex AI Express Mode: API key authentication with no
// Google Cloud project, location, or Application Default Credentials
// involved. See
// https://cloud.google.com/vertex-ai/generative-ai/docs/start/express-mode/overview.
// Mutually exclusive with ProjectID, Location, and Credentials. Optional.
APIKey string
// Credentials overrides the Google Cloud credentials used to authenticate.
// If nil, Application Default Credentials are detected. Mutually exclusive
// with APIKey and HTTPClient. Optional.
Credentials *auth.Credentials
// BaseURL overrides the default location-derived API endpoint, e.g. to
// point at a proxy or an API gateway. Optional.
BaseURL string
// Headers are additional HTTP headers to send with every request. They
// are merged over the plugin's default headers, so a header set here wins
// on collision. Optional.
Headers http.Header
// HTTPClient is the HTTP client used for API requests. When set, it is
// used verbatim and must handle authentication itself (unless APIKey is
// set, which rides on a request header): the plugin does not install its
// default credential-carrying, OpenTelemetry instrumented transport.
// Optional.
HTTPClient *http.Client
// Models overrides what the plugin knows about a model, keyed by model ID;
// see [GoogleAI.Models]. Tuned Gemini endpoints are keyed in either the
// short form `endpoints/ID` or the full resource path
// `projects/PROJECT/locations/LOCATION/endpoints/ID`, whichever form the
// request names them by.
Models map[string]ai.ModelOptions
// Embedders overrides what the plugin knows about an embedder, keyed by
// embedder ID; see [GoogleAI.Embedders].
Embedders map[string]ai.EmbedderOptions
// contains filtered or unexported fields
}
VertexAI is a Genkit plugin for interacting with the Google Vertex AI service.
func (*VertexAI) Client ¶ added in v1.12.0
Client returns the underlying Google GenAI SDK client used by the plugin; see GoogleAI.Client.
func (*VertexAI) DefineEmbedder
deprecated
func (v *VertexAI) DefineEmbedder(g *genkit.Genkit, id string, embedOpts *ai.EmbedderOptions) (ai.Embedder, error)
DefineEmbedder defines an embedder with a given ID.
Deprecated: describe the embedder through VertexAI.Embedders instead; see GoogleAI.DefineEmbedder.
func (*VertexAI) DefineModel
deprecated
func (v *VertexAI) DefineModel(g *genkit.Genkit, id string, opts *ai.ModelOptions) (ai.Model, error)
DefineModel defines an unknown model with the given ID. The second argument describes the capability of the model.
Tuned Gemini endpoints are accepted in either the short form `endpoints/ID` or the full resource path `projects/PROJECT/locations/LOCATION/endpoints/ID`, and take the default Gemini capability set when opts is nil.
Deprecated: describe the model through VertexAI.Models instead; see GoogleAI.DefineModel for why the result of this method is not what serves the request.
func (*VertexAI) Init ¶
Init initializes the VertexAI plugin and all known models and embedders. After calling Init, you may call [DefineModel] and [DefineEmbedder] to create and register any additional generative models and embedders
func (*VertexAI) IsDefinedEmbedder
deprecated
IsDefinedEmbedder reports whether the [Embedder] is defined by this plugin.
Deprecated: see GoogleAI.IsDefinedEmbedder; capabilities now come from VertexAI.Embedders.
func (*VertexAI) ListActions ¶ added in v0.6.0
func (v *VertexAI) ListActions(ctx context.Context) []api.ActionDesc
ListActions lists all the actions supported by the Vertex AI plugin.
func (*VertexAI) ResolveAction ¶ added in v0.6.0
ResolveAction resolves an action with the given ID.