google

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Endpoint is the Google Generative AI API endpoint
	Endpoint = "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent"

	// FilesEndpoint is the Google Files API endpoint for uploads
	FilesEndpoint = "https://generativelanguage.googleapis.com/upload/v1beta/files"

	// Model is the default Gemini model to use
	Model = "gemini-2.5-flash"
)

API Configuration Constants

Variables

This section is empty.

Functions

func Prompt

func Prompt(systemPrompt, userPrompt, jsonSchema, apiKey string, files ...File) (string, error)

Prompt sends a prompt request to Google's Generative AI API

Types

type Candidate

type Candidate struct {
	Content struct {
		Parts []Part `json:"parts"`
		Role  string `json:"role"`
	} `json:"content"`
	FinishReason  string         `json:"finishReason"`
	Index         int            `json:"index"`
	SafetyRatings []SafetyRating `json:"safetyRatings"`
}

Candidate represents a response candidate

type Content

type Content struct {
	Parts []Part `json:"parts"`
}

Content represents a content part in the request

type File added in v0.2.2

type File struct {
	URI         string `json:"uri"`
	Name        string `json:"name"`
	DisplayName string `json:"display_name"`
	MimeType    string `json:"mime_type"`
	SizeBytes   int64  `json:"size_bytes"`
	State       string `json:"state"`
}

File represents an uploaded file

func UploadFile added in v0.2.2

func UploadFile(filePath, apiKey string) (*File, error)

UploadFile uploads a file to Google and returns file metadata

type FileData added in v0.2.2

type FileData struct {
	MimeType string `json:"mime_type"`
	FileURI  string `json:"file_uri"`
}

FileData represents a file reference in content

type FileUploadInfo added in v0.2.2

type FileUploadInfo struct {
	DisplayName string `json:"display_name"`
}

FileUploadInfo represents file metadata for upload

type FileUploadRequest added in v0.2.2

type FileUploadRequest struct {
	File FileUploadInfo `json:"file"`
}

FileUploadRequest represents the initial upload request

type FileUploadResponse added in v0.2.2

type FileUploadResponse struct {
	File File `json:"file"`
}

FileUploadResponse wraps the uploaded file

type GenerationConfig

type GenerationConfig struct {
	ResponseMimeType string      `json:"responseMimeType,omitempty"`
	ResponseSchema   interface{} `json:"responseSchema,omitempty"`
}

GenerationConfig configures the generation parameters

type GoogleRequest

type GoogleRequest struct {
	Contents         []Content         `json:"contents"`
	GenerationConfig *GenerationConfig `json:"generationConfig,omitempty"`
}

GoogleRequest represents the request body for Google's API

type GoogleResponse

type GoogleResponse struct {
	Candidates    []Candidate   `json:"candidates"`
	UsageMetadata UsageMetadata `json:"usageMetadata"`
}

GoogleResponse represents the API response structure

type JsonSchema

type JsonSchema struct {
	Type        string                 `json:"type"`
	Properties  map[string]interface{} `json:"properties,omitempty"`
	Items       interface{}            `json:"items,omitempty"`
	Required    []string               `json:"required,omitempty"`
	Description string                 `json:"description,omitempty"`
}

JsonSchema represents Google's JSON schema structure for structured output

type Part

type Part struct {
	Text     string    `json:"text,omitempty"`
	FileData *FileData `json:"file_data,omitempty"`
}

Part represents a text or file part of the content

type Provider added in v0.2.5

type Provider struct{}

Provider implements the internal.Provider interface for Google

func NewProvider added in v0.2.5

func NewProvider() *Provider

NewProvider creates a new Google provider

func (*Provider) Agent added in v0.2.5

func (p *Provider) Agent(apiKey string) (interface{}, error)

Agent implements the internal.Provider interface

func (*Provider) Prompt added in v0.2.5

func (p *Provider) Prompt(ctx context.Context, systemPrompt, userPrompt, jsonSchema, apiKey string, files ...internal.File) (string, error)

Prompt implements the internal.Provider interface

type SafetyRating

type SafetyRating struct {
	Category    string `json:"category"`
	Probability string `json:"probability"`
}

SafetyRating represents safety assessment

type UsageMetadata

type UsageMetadata struct {
	PromptTokenCount     int `json:"promptTokenCount"`
	CandidatesTokenCount int `json:"candidatesTokenCount"`
	TotalTokenCount      int `json:"totalTokenCount"`
}

UsageMetadata represents token usage information

Jump to

Keyboard shortcuts

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