ai

package module
v1.0.21 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAIClosed = errors.New("AI client is nil or already closed")

Functions

func ApplyModelConfig added in v1.0.6

func ApplyModelConfig(ai AI, cfg ModelConfig)

func NewLimiter

func NewLimiter(rpm int64) *rate.Limiter

Types

type AI

type AI interface {
	LLMs() LLMs
	Model(context.Context) (string, error)

	Limiter

	SetModel(string)
	Model

	Chatbot
	ChatSession() ChatSession

	Close() error
}

type Blob added in v1.0.21

type Blob struct {
	MIMEType string
	Data     []byte
}

type ChatResponse

type ChatResponse interface {
	Raw() any
	Results() []string
	FunctionCalls() []FunctionCall
	TokenCount() TokenCount
}

type ChatSession added in v1.0.2

type ChatSession interface {
	Chatbot
	History() []Content
}

type ChatStream

type ChatStream interface {
	Next() (ChatResponse, error)
	Close() error
}

type Chatbot

type Chatbot interface {
	Chat(context.Context, ...Part) (ChatResponse, error)
	ChatStream(context.Context, ...Part) (ChatStream, error)
}

type ClientConfig added in v1.0.6

type ClientConfig struct {
	LLMs LLMs

	APIKey   string
	Endpoint string
	Proxy    string

	Limit *int64

	Model       string
	ModelConfig ModelConfig
}

type ClientOption added in v1.0.6

type ClientOption interface {
	Apply(*ClientConfig)
}

func WithAPIKey added in v1.0.6

func WithAPIKey(apiKey string) ClientOption

func WithEndpoint added in v1.0.6

func WithEndpoint(endpoint string) ClientOption

func WithLimit added in v1.0.6

func WithLimit(rpm int64) ClientOption

func WithModel added in v1.0.7

func WithModel(model string) ClientOption

func WithModelConfig added in v1.0.6

func WithModelConfig(config ModelConfig) ClientOption

func WithProxy added in v1.0.6

func WithProxy(proxy string) ClientOption

type Content added in v1.0.18

type Content struct {
	Parts []Part
	Role  string
}

type Function added in v1.0.19

type Function struct {
	Name        string
	Description string
	Parameters  Schema
}

type FunctionCall added in v1.0.19

type FunctionCall struct {
	ID        string
	Name      string
	Arguments string
}

type FunctionCallingMode added in v1.0.19

type FunctionCallingMode int
const (
	FunctionCallingAuto FunctionCallingMode = iota + 1
	FunctionCallingAny
	FunctionCallingNone
)

func (*FunctionCallingMode) UnmarshalText added in v1.0.19

func (m *FunctionCallingMode) UnmarshalText(text []byte) error

type FunctionResponse added in v1.0.19

type FunctionResponse struct {
	ID       string
	Response string
}

type Image added in v1.0.18

type Image string

func ImageData added in v1.0.18

func ImageData(mime string, data []byte) Image

func (Image) Data added in v1.0.18

func (img Image) Data() (mime string, data []byte)

func (Image) MIMEType added in v1.0.18

func (img Image) MIMEType() string

type JSONSchema added in v1.0.21

type JSONSchema struct {
	Name        string
	Description string
	Schema      Schema
}

type LLMs added in v1.0.6

type LLMs string
const (
	ChatGPT   LLMs = "ChatGPT"
	Gemini    LLMs = "Gemini"
	Anthropic LLMs = "Anthropic"
)

func (LLMs) MarshalText added in v1.0.6

func (m LLMs) MarshalText() ([]byte, error)

func (*LLMs) UnmarshalText added in v1.0.6

func (m *LLMs) UnmarshalText(text []byte) error

type Limiter

type Limiter interface {
	SetLimit(rpm int64)
	Limit() (rpm int64)
}

type Model

type Model interface {
	SetFunctionCall([]Function, FunctionCallingMode)
	SetCount(x int64)
	SetMaxTokens(x int64)
	SetTemperature(x float64)
	SetTopP(x float64)
	SetJSONResponse(set bool, schema *JSONSchema)
}

type ModelConfig added in v1.0.6

type ModelConfig struct {
	Count        *int64
	MaxTokens    *int64
	Temperature  *float64
	TopP         *float64
	JSONResponse *bool
	JSONSchema   *JSONSchema
	Tools        []Function
	ToolConfig   FunctionCallingMode
}

type Part added in v1.0.18

type Part interface {
	// contains filtered or unexported methods
}

type Schema added in v1.0.19

type Schema struct {
	Type       string         `json:"type"`
	Properties map[string]any `json:"properties"`
	Enum       []string       `json:"enum,omitempty"`
	Items      *Schema        `json:"items,omitempty"`
	Required   []string       `json:"required,omitempty"`
}

type Text added in v1.0.18

type Text string

type TokenCount added in v1.0.13

type TokenCount struct {
	Prompt int64
	Result int64
	Total  int64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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