gemini

package
v0.0.0-...-21b4ffc Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: Unlicense Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApiBase         = "https://generativelanguage.googleapis.com"
	ApiPathGenerate = "/v1beta/models/gemini-2.5-flash:generateContent"
	ApiPathUpload   = "/upload/v1beta/files"
	RoleModel       = "model"
	RoleUser        = "user"
	MaxSourceLinks  = 10
)
View Source
const (
	MaxRetries               = 3
	Temperature              = 0.8
	TopK                     = 1
	TopP                     = 1
	MaxOutputTokens          = 900
	MaxInputCharacters       = 250000 // Should be roughly 1 mio tokens, max input tokens are 1048576
	TokensPerImage           = 258    // https://ai.google.dev/gemini-api/docs/tokens?lang=go#multimodal-tokens
	DefaultSystemInstruction = ""     /* 274-byte string literal not displayed */
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Content

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

func (*Content) Chars

func (c *Content) Chars() int

func (*Content) Text

func (c *Content) Text() string

type FileData

type FileData struct {
	MimeType string `json:"mimeType,omitempty"`
	FileUri  string `json:"fileUri,omitempty"`
}

type FileUploadResponse

type FileUploadResponse struct {
	File struct {
		MimeType string `json:"mimeType"`
		Uri      string `json:"uri"`
	} `json:"file"`
}

FileUploadResponse - https://ai.google.dev/api/files#response-body

type GenerateContentRequest

type GenerateContentRequest struct {
	Contents          []Content         `json:"contents"`
	SafetySettings    []SafetySetting   `json:"safetySettings"`
	GenerationConfig  GenerationConfig  `json:"generationConfig"`
	SystemInstruction SystemInstruction `json:"system_instruction"`
	Tools             []Tool            `json:"tools"`
}

GenerateContentRequest - https://ai.google.dev/api/generate-content#request-body

type GenerateContentResponse

type GenerateContentResponse struct {
	Candidates []struct {
		Content       Content `json:"content"`
		FinishReason  string  `json:"finishReason"`
		SafetyRatings []struct {
			Category    string `json:"category"`
			Probability string `json:"probability"`
		} `json:"safetyRatings"`
		GroundingMetadata GroundingMetadata `json:"groundingMetadata"`
	} `json:"candidates"`
}

GenerateContentResponse - https://ai.google.dev/api/generate-content#generatecontentresponse

type GenerationConfig

type GenerationConfig struct {
	Temperature     float64        `json:"temperature"`
	TopK            int            `json:"topK"`
	TopP            int            `json:"topP"`
	MaxOutputTokens int            `json:"maxOutputTokens"`
	ThinkingConfig  ThinkingConfig `json:"thinkingConfig"`
}

type GroundingMetadata

type GroundingMetadata struct {
	// https://ai.google.dev/api/generate-content#GroundingChunk
	GroundingChunks []struct {
		// https://ai.google.dev/api/generate-content#Web
		Web struct {
			Uri   string `json:"uri"`
			Title string `json:"title"`
		} `json:"web"`
	} `json:"groundingChunks"`
	WebSearchQueries []string `json:"webSearchQueries"`
}

GroundingMetadata - https://ai.google.dev/api/generate-content#GroundingMetadata

func (g *GroundingMetadata) Links() string

type Part

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

type Plugin

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

func New

func New(credentialService model.CredentialService, geminiService Service) *Plugin

func (*Plugin) Commands

func (p *Plugin) Commands() []gotgbot.BotCommand

func (*Plugin) Handlers

func (p *Plugin) Handlers(botInfo *gotgbot.User) []plugin.Handler

func (*Plugin) Name

func (p *Plugin) Name() string

type SafetySetting

type SafetySetting struct {
	Category  string `json:"category"`  // https://ai.google.dev/api/generate-content#v1beta.HarmCategory
	Threshold string `json:"threshold"` // https://ai.google.dev/api/generate-content#HarmBlockThreshold
}

type Service

type Service interface {
	GetHistory(chat *gotgbot.Chat) (model.GeminiData, error)
	ResetHistory(chat *gotgbot.Chat) error
	SetHistory(chat *gotgbot.Chat, history string) error
}

type SystemInstruction

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

type ThinkingConfig

type ThinkingConfig struct {
	IncludeThoughts bool `json:"includeThoughts"`
	ThinkingBudget  int  `json:"thinkingBudget"`
}

ThinkingConfig - https://ai.google.dev/api/generate-content#ThinkingConfig

type Tool

type Tool struct {
	// GoogleSearch - https://ai.google.dev/api/caching#GoogleSearch (has no fields)
	GoogleSearch struct {
	} `json:"google_search"`
}

Tool - https://ai.google.dev/api/caching#Tool

Jump to

Keyboard shortcuts

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