googlegenai

package
v0.5.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.ConstrainedSupportNoTools,
	}
)

Functions

func GoogleAIEmbedder

func GoogleAIEmbedder(g *genkit.Genkit, name string) ai.Embedder

GoogleAIEmbedder returns the ai.Embedder with the given name. It returns nil if the embedder was not defined.

func GoogleAIModel

func GoogleAIModel(g *genkit.Genkit, name string) ai.Model

GoogleAIModel returns the ai.Model with the given name. It returns nil if the model was not defined.

func GoogleAIModelRef added in v0.5.0

func GoogleAIModelRef(name string, config *GeminiConfig) ai.ModelRef

GoogleAIModelRef creates a new ModelRef for a Google AI model with the given name and configuration.

func HasCodeExecution added in v0.5.1

func HasCodeExecution(msg *ai.Message) bool

HasCodeExecution checks if a message contains code execution results or executable code.

func NewCodeExecutionResultPart added in v0.5.1

func NewCodeExecutionResultPart(outcome string, output string) *ai.Part

NewCodeExecutionResultPart returns a Part containing the result of code execution.

func NewExecutableCodePart added in v0.5.1

func NewExecutableCodePart(language string, code string) *ai.Part

NewExecutableCodePart returns a Part containing executable code.

func VertexAIEmbedder

func VertexAIEmbedder(g *genkit.Genkit, name string) ai.Embedder

VertexAIEmbedder returns the ai.Embedder with the given name. It returns nil if the embedder was not defined.

func VertexAIModel

func VertexAIModel(g *genkit.Genkit, name string) ai.Model

VertexAIModel returns the ai.Model with the given name. It returns nil if the model was not defined.

func VertexAIModelRef added in v0.5.0

func VertexAIModelRef(name string, config *GeminiConfig) ai.ModelRef

VertexAIModelRef creates a new ModelRef for a Vertex AI model with the given name and configuration.

Types

type CodeExecutionResult added in v0.5.1

type CodeExecutionResult struct {
	Outcome string `json:"outcome"`
	Output  string `json:"output"`
}

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 EmbedOptions added in v0.5.0

type EmbedOptions struct {
	// Document title.
	Title string `json:"title,omitempty"`
	// Task type: RETRIEVAL_QUERY, RETRIEVAL_DOCUMENT, and so forth.
	// See the Vertex AI text embedding docs.
	TaskType string `json:"task_type,omitempty"`
}

EmbedOptions are options for the Vertex AI embedder. Set ai.EmbedRequest.Options to a value of type *EmbedOptions.

type ExecutableCode added in v0.5.1

type ExecutableCode struct {
	Language string `json:"language"`
	Code     string `json:"code"`
}

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 GeminiConfig added in v0.5.0

type GeminiConfig struct {
	// MaxOutputTokens is the maximum number of tokens to generate.
	MaxOutputTokens int `json:"maxOutputTokens,omitempty"`
	// StopSequences is the list of sequences where the model will stop generating further tokens.
	StopSequences []string `json:"stopSequences,omitempty"`
	// Temperature is the temperature to use for the model.
	Temperature float64 `json:"temperature,omitempty"`
	// TopK is the number of top tokens to consider for the model.
	TopK int `json:"topK,omitempty"`
	// TopP is the top-p value to use for the model.
	TopP float64 `json:"topP,omitempty"`
	// Version is the version of the model to use.
	Version string `json:"version,omitempty"`
	// SafetySettings is the list of safety settings to use for the model.
	SafetySettings []*SafetySetting `json:"safetySettings,omitempty"`
	// CodeExecution is whether to allow executing of code generated by the model.
	CodeExecution bool `json:"codeExecution,omitempty"`
	// Response modalities for returned model messages
	ResponseModalities []Modality `json:"responseModalities,omitempty"`
	// Thinking configuration controls the model's internal reasoning process
	ThinkingConfig *ThinkingConfig `json:"thinkingConfig,omitempty"`
}

GeminiConfig mirrors GenerateContentConfig without direct genai dependency

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.
	// contains filtered or unexported fields
}

GoogleAI is a Genkit plugin for interacting with the Google AI service.

func (*GoogleAI) DefineEmbedder

func (ga *GoogleAI) DefineEmbedder(g *genkit.Genkit, name string) (ai.Embedder, error)

DefineEmbedder defines an embedder with a given name.

func (*GoogleAI) DefineModel

func (ga *GoogleAI) DefineModel(g *genkit.Genkit, name string, info *ai.ModelInfo) (ai.Model, error)

DefineModel defines an unknown model with the given name. The second argument describes the capability of the model. Use [IsDefinedModel] to determine if a model is already defined. After [Init] is called, only the known models are defined.

func (*GoogleAI) Init

func (ga *GoogleAI) Init(ctx context.Context, g *genkit.Genkit) (err error)

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

func (ga *GoogleAI) IsDefinedEmbedder(g *genkit.Genkit, name string) bool

IsDefinedEmbedder reports whether the named [Embedder] is defined by this plugin.

func (*GoogleAI) Name

func (ga *GoogleAI) Name() string

Name returns the name of the plugin.

type HarmBlockMethod added in v0.5.0

type HarmBlockMethod string

Specify if the threshold is used for probability or severity score. If not specified, the threshold is used for probability score.

const (
	// The harm block method is unspecified.
	HarmBlockMethodUnspecified HarmBlockMethod = "HARM_BLOCK_METHOD_UNSPECIFIED"
	// The harm block method uses both probability and severity scores.
	HarmBlockMethodSeverity HarmBlockMethod = "SEVERITY"
	// The harm block method uses the probability score.
	HarmBlockMethodProbability HarmBlockMethod = "PROBABILITY"
)

type HarmBlockThreshold added in v0.5.0

type HarmBlockThreshold string

The harm block threshold.

const (
	// Unspecified harm block threshold.
	HarmBlockThresholdUnspecified HarmBlockThreshold = "HARM_BLOCK_THRESHOLD_UNSPECIFIED"
	// Block low threshold and above (i.e. block more).
	HarmBlockThresholdBlockLowAndAbove HarmBlockThreshold = "BLOCK_LOW_AND_ABOVE"
	// Block medium threshold and above.
	HarmBlockThresholdBlockMediumAndAbove HarmBlockThreshold = "BLOCK_MEDIUM_AND_ABOVE"
	// Block only high threshold (i.e. block less).
	HarmBlockThresholdBlockOnlyHigh HarmBlockThreshold = "BLOCK_ONLY_HIGH"
	// Block none.
	HarmBlockThresholdBlockNone HarmBlockThreshold = "BLOCK_NONE"
	// Turn off the safety filter.
	HarmBlockThresholdOff HarmBlockThreshold = "OFF"
)

type HarmCategory added in v0.5.0

type HarmCategory string
const (
	// The harm category is unspecified.
	HarmCategoryUnspecified HarmCategory = "HARM_CATEGORY_UNSPECIFIED"
	// The harm category is hate speech.
	HarmCategoryHateSpeech HarmCategory = "HARM_CATEGORY_HATE_SPEECH"
	// The harm category is dangerous content.
	HarmCategoryDangerousContent HarmCategory = "HARM_CATEGORY_DANGEROUS_CONTENT"
	// The harm category is harassment.
	HarmCategoryHarassment HarmCategory = "HARM_CATEGORY_HARASSMENT"
	// The harm category is sexually explicit content.
	HarmCategorySexuallyExplicit HarmCategory = "HARM_CATEGORY_SEXUALLY_EXPLICIT"
	// The harm category is civic integrity.
	HarmCategoryCivicIntegrity HarmCategory = "HARM_CATEGORY_CIVIC_INTEGRITY"
)

type Modality added in v0.5.2

type Modality string
const (
	// Indicates the model should return images
	ImageMode Modality = "IMAGE"
	// Indicates the model should return text
	TextMode Modality = "TEXT"
)

type SafetySetting added in v0.5.0

type SafetySetting struct {
	// Determines if the harm block method uses probability or probability
	// and severity scores.
	Method HarmBlockMethod `json:"method,omitempty"`
	// Required. Harm category.
	Category HarmCategory `json:"category,omitempty"`
	// Required. The harm block threshold.
	Threshold HarmBlockThreshold `json:"threshold,omitempty"`
}

Safety settings.

type ThinkingConfig added in v0.5.4

type ThinkingConfig struct {
	// Indicates whether the response should include thoughts (if available and supported)
	IncludeThoughts bool `json:"includeThoughts,omitempty"`
	// Thinking budget in tokens. If set to zero, thinking gets disabled
	ThinkingBudget int32 `json:"thinkingBudget,omitempty"`
}

Thinking configuration to control reasoning

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.
	// contains filtered or unexported fields
}

VertexAI is a Genkit plugin for interacting with the Google Vertex AI service.

func (*VertexAI) DefineEmbedder

func (v *VertexAI) DefineEmbedder(g *genkit.Genkit, name string) (ai.Embedder, error)

DefineEmbedder defines an embedder with a given name.

func (*VertexAI) DefineModel

func (v *VertexAI) DefineModel(g *genkit.Genkit, name string, info *ai.ModelInfo) (ai.Model, error)

DefineModel defines an unknown model with the given name. The second argument describes the capability of the model. Use [IsDefinedModel] to determine if a model is already defined. After [Init] is called, only the known models are defined.

func (*VertexAI) Init

func (v *VertexAI) Init(ctx context.Context, g *genkit.Genkit) (err error)

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

func (v *VertexAI) IsDefinedEmbedder(g *genkit.Genkit, name string) bool

IsDefinedEmbedder reports whether the named [Embedder] is defined by this plugin.

func (*VertexAI) Name

func (v *VertexAI) Name() string

Name returns the name of the plugin.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL