gemini

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ask

func Ask(ctx context.Context, prompt string, opts ...Option) (string, error)

func GenerateSchema

func GenerateSchema(v any) (*genai.Schema, error)

Types

type Option

type Option func(*Options)

func WithAPIKey

func WithAPIKey(key string) Option

func WithBaseURL

func WithBaseURL(url string) Option

func WithClient added in v0.0.5

func WithClient(client *http.Client) Option

func WithMaxOutputTokens

func WithMaxOutputTokens(tokens int) Option

func WithModel

func WithModel(model string) Option

func WithResponseSchema

func WithResponseSchema(schema *genai.Schema) Option

func WithRetry added in v0.0.5

func WithRetry(max int) Option

func WithSystemPrompt

func WithSystemPrompt(prompt string) Option

func WithTemperature

func WithTemperature(temperature float32) Option

func WithTool

func WithTool(fn minds.Tool) Option

func WithToolRegistry

func WithToolRegistry(registry minds.ToolRegistry) Option

type Options

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

type Provider

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

func NewProvider

func NewProvider(ctx context.Context, opts ...Option) (*Provider, error)

NewProvider creates a new Gemini provider. If no model name is provided, the default model is used, currently "gemini-1.5-flash". The default model can be overridden by setting the GEMINI_DEFAULT_MODEL environment variable.

If no http.Client is provided, a default client is created with a retryable http client with a maximum of 10 retries provided by HashiCorp.

func (*Provider) Close

func (p *Provider) Close()

func (*Provider) CountTokens

func (p *Provider) CountTokens(text string) (int, error)

Implement the TokenCounter interface for the Gemini provider.

func (*Provider) GenerateContent

func (p *Provider) GenerateContent(ctx context.Context, req minds.Request) (minds.Response, error)

func (*Provider) HandleThread

func (p *Provider) HandleThread(tc minds.ThreadContext, next minds.ThreadHandler) (minds.ThreadContext, error)

HandleMessage implements the ThreadHandler interface for the Gemini provider.

func (*Provider) ModelName

func (p *Provider) ModelName() string

type Response

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

Response represents a unified response type that can handle both text responses and function calls from the Gemini API

func NewResponse

func NewResponse(resp *genai.GenerateContentResponse, calls []minds.ToolCall) (*Response, error)

NewResponse creates a new Response from a Gemini API response

func (*Response) Messages added in v0.0.4

func (r *Response) Messages() (minds.Messages, error)

func (*Response) Raw

Raw returns the underlying Gemini response

func (*Response) String

func (r *Response) String() string

String returns the text content if this is a text response. For function calls, it returns a formatted representation of the call.

func (*Response) ToolCalls

func (r *Response) ToolCalls() []minds.ToolCall

ToolCalls returns the function call details if this is a function call response. Returns nil and false if this isn't a function call.

Jump to

Keyboard shortcuts

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