gemini

package
v1.15.1 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package gemini provides a client for the Google generative AI API.

Index

Constants

View Source
const (
	Model25Flash = "gemini-2.5-flash"
	Model25Pro   = "gemini-2.5-pro"

	DefaultModel = Model25Flash

	RoleUser  = "user"
	RoleModel = "model"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	ModelName string
	Cli       *genai.Client
	Model     *genai.GenerativeModel
	// contains filtered or unexported fields
}

Client is a Google generative AI client.

func NewClient

func NewClient(apiKey string, opts ...ClientOption) (*Client, error)

NewClient creates a new Google generative AI client.

func (*Client) Close

func (c *Client) Close() error

Close closes the client.

func (*Client) ListContextMessages

func (c *Client) ListContextMessages() []*ContextMessage

ListContextMessages list assistant context messages

func (*Client) ListModelNames

func (c *Client) ListModelNames(ctx context.Context) ([]string, error)

ListModelNames lists the available models.

func (*Client) RefreshContext

func (c *Client) RefreshContext()

RefreshContext refreshes assistant context

func (*Client) Send

func (c *Client) Send(ctx context.Context, prompt string, files ...string) (string, error)

Send sends a prompt to the gemini model and returns the response.

func (*Client) SendStream

func (c *Client) SendStream(ctx context.Context, prompt string, files ...string) *aicli.StreamReply

SendStream sends a prompt to the gemini model and returns a channel of responses.

type ClientOption

type ClientOption func(*Client)

ClientOption is a function that sets a Client option.

func WithEnableContext

func WithEnableContext() ClientOption

WithEnableContext enable assistant context

func WithInitialContextMessages

func WithInitialContextMessages(messages ...*ContextMessage) ClientOption

WithInitialContextMessages sets assistant initial context messages

func WithModel

func WithModel(name string) ClientOption

WithModel sets the model name

type ContextMessage

type ContextMessage struct {
	Role    string `json:"role"` // "user" or "model"
	Content string `json:"content"`
}

ContextMessage chat history message

Jump to

Keyboard shortcuts

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