google

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

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 FileUploader

type FileUploader struct {
	// contains filtered or unexported fields
}

FileUploader is a utility for uploading files to Google Gemini File API.

func NewFileUploader

func NewFileUploader(ctx context.Context, apiKey string) (*FileUploader, error)

NewFileUploader creates a new FileUploader.

func (*FileUploader) Upload

func (u *FileUploader) Upload(ctx context.Context, path string) (*genai.File, func(), error)

Upload uploads a file to the Gemini File API and waits for it to become ACTIVE. It returns the uploaded file info, a cleanup function to delete the file, and any error.

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

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 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

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

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

func GetReasoningMetadata(providerOptions fantasy.ProviderOptions) *ReasoningMetadata

GetReasoningMetadata extracts reasoning metadata from provider options for google models.

func (ReasoningMetadata) MarshalJSON

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

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"`
	IncludeThoughts *bool  `json:"include_thoughts"`
}

ThinkingConfig represents thinking configuration 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