google

package
v0.48.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 20 Imported by: 14

README

Google Provider

This document describes how to get an API keys for Google Gemini and Vertex.

Gemini

Simply navigate to this page in the Google AI Studio and create a new API key.

Vertex

Install gcloud

Install the gcloud command line tool. Install via Homebrew, Nix, or download it from here.

# Homebrew
brew install --cask google-cloud-sdk

# Nix
nix-env -iA nixpkgs.google-cloud-sdk
Authenticate

Then authenticate with your Google account:

gcloud auth login
Create And Setup Project

Navigate here to create a new project if you haven't already: https://console.cloud.google.com/projectcreate

Alternatively, you can create a new project via the command line:

gcloud projects create {YOUR_PROJECT_ID} --name="{YOUR_PROJECT_NAME}"

Set the project on your machine:

gcloud config set project {YOUR_PROJECT_ID}

Enable the Vertex AI API:

gcloud services enable aiplatform.googleapis.com
Setup Env

Finally, you need to run this command to ensure that libraries will be able to find your credentials.

gcloud auth application-default login

Documentation

Overview

Package google provides an implementation of the fantasy AI SDK for Google's language models.

Package google provides an implementation of the fantasy AI SDK for Google's language models.

Index

Constants

View Source
const (
	TypeProviderOptions   = Name + ".options"
	TypeReasoningMetadata = Name + ".reasoning_metadata"
)

Global type identifiers for Google-specific provider data.

View Source
const Name = "google"

Name is the name of the Google provider.

Variables

This section is empty.

Functions

func New

func New(opts ...Option) (fantasy.Provider, error)

New creates a new Google provider with the given options.

Types

type Option

type Option = func(*options)

Option defines a function that configures Google provider options.

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL sets the base URL for the Google provider.

func WithGeminiAPIKey

func WithGeminiAPIKey(apiKey string) Option

WithGeminiAPIKey sets the Gemini API key for the Google provider.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient sets the HTTP client for the Google provider.

func WithHeaders

func WithHeaders(headers map[string]string) Option

WithHeaders sets the headers for the Google provider.

func WithName

func WithName(name string) Option

WithName sets the name for the Google provider.

func WithObjectMode added in v0.3.0

func WithObjectMode(om fantasy.ObjectMode) Option

WithObjectMode sets the object generation mode for the Google provider.

func WithSkipAuth

func WithSkipAuth(skipAuth bool) Option

WithSkipAuth configures whether to skip authentication for the Google provider.

func WithToolCallIDFunc

func WithToolCallIDFunc(f ToolCallIDFunc) Option

WithToolCallIDFunc sets the function that generates a tool call ID.

func WithUserAgent added in v0.12.0

func WithUserAgent(ua string) Option

WithUserAgent sets an explicit User-Agent header, overriding the default and any value set via WithHeaders.

func WithVertex

func WithVertex(project, location string) Option

WithVertex configures the Google provider to use Vertex AI.

type ProviderOptions

type ProviderOptions struct {
	ThinkingConfig *ThinkingConfig `json:"thinking_config"`

	// Optional.
	// The name of the cached content used as context to serve the prediction.
	// Format: cachedContents/{cachedContent}
	CachedContent string `json:"cached_content"`

	// Optional. A list of unique safety settings for blocking unsafe content.
	SafetySettings []SafetySetting `json:"safety_settings"`
	// 'HARM_BLOCK_THRESHOLD_UNSPECIFIED',
	// 'BLOCK_LOW_AND_ABOVE',
	// 'BLOCK_MEDIUM_AND_ABOVE',
	// 'BLOCK_ONLY_HIGH',
	// 'BLOCK_NONE',
	// 'OFF',
	Threshold string `json:"threshold"`
}

ProviderOptions represents additional options for the Google provider.

func ParseOptions

func ParseOptions(data map[string]any) (*ProviderOptions, error)

ParseOptions parses provider options from a map for the Google provider.

func (ProviderOptions) MarshalJSON added in v0.3.0

func (o ProviderOptions) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling with type info for ProviderOptions.

func (*ProviderOptions) Options

func (o *ProviderOptions) Options()

Options implements the ProviderOptionsData interface for ProviderOptions.

func (*ProviderOptions) UnmarshalJSON added in v0.3.0

func (o *ProviderOptions) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling with type info for ProviderOptions.

type ReasoningMetadata

type ReasoningMetadata struct {
	Signature string `json:"signature"`
	ToolID    string `json:"tool_id"`
}

ReasoningMetadata represents reasoning metadata for the Google provider.

func GetReasoningMetadata added in v0.3.2

func GetReasoningMetadata(providerOptions fantasy.ProviderOptions) *ReasoningMetadata

GetReasoningMetadata extracts reasoning metadata from provider options for google models.

func (ReasoningMetadata) MarshalJSON added in v0.3.0

func (m ReasoningMetadata) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling with type info for ReasoningMetadata.

func (*ReasoningMetadata) Options

func (m *ReasoningMetadata) Options()

Options implements the ProviderOptionsData interface for ReasoningMetadata.

func (*ReasoningMetadata) UnmarshalJSON added in v0.3.0

func (m *ReasoningMetadata) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling with type info for ReasoningMetadata.

type SafetySetting

type SafetySetting struct {
	// 'HARM_CATEGORY_UNSPECIFIED',
	// 'HARM_CATEGORY_HATE_SPEECH',
	// 'HARM_CATEGORY_DANGEROUS_CONTENT',
	// 'HARM_CATEGORY_HARASSMENT',
	// 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
	// 'HARM_CATEGORY_CIVIC_INTEGRITY',
	Category string `json:"category"`

	// 'HARM_BLOCK_THRESHOLD_UNSPECIFIED',
	// 'BLOCK_LOW_AND_ABOVE',
	// 'BLOCK_MEDIUM_AND_ABOVE',
	// 'BLOCK_ONLY_HIGH',
	// 'BLOCK_NONE',
	// 'OFF',
	Threshold string `json:"threshold"`
}

SafetySetting represents safety settings for the Google provider.

type ThinkingConfig

type ThinkingConfig struct {
	ThinkingBudget  *int64  `json:"thinking_budget,omitempty"`
	IncludeThoughts *bool   `json:"include_thoughts,omitempty"`
	ThinkingLevel   *string `json:"thinking_level,omitempty"`
}

ThinkingConfig represents thinking configuration for the Google provider.

type ThinkingLevel added in v0.10.0

type ThinkingLevel = string

ThinkingLevel controls the amount of thinking a model does. Use this for Gemini 3+ models instead of ThinkingBudget. Mutually exclusive with ThinkingBudget.

const (
	ThinkingLevelLow     ThinkingLevel = "LOW"
	ThinkingLevelMedium  ThinkingLevel = "MEDIUM"
	ThinkingLevelHigh    ThinkingLevel = "HIGH"
	ThinkingLevelMinimal ThinkingLevel = "MINIMAL"
)

Predefined thinking levels for the Google provider.

type ToolCallIDFunc

type ToolCallIDFunc = func() string

ToolCallIDFunc defines a function that generates a tool call ID.

Jump to

Keyboard shortcuts

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