genai

package
v0.0.0-...-c987250 Latest Latest
Warning

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

Go to latest
Published: May 21, 2025 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GenerateStats

type GenerateStats struct {
	DoneReason         string
	TotalDuration      time.Duration
	LoadDuration       time.Duration
	PromptTokens       int64
	PromptEvalDuration time.Duration
	TokenCount         int64
	EvalDuration       time.Duration
}

type GenerativeAI

type GenerativeAI interface {
	Chat(messages []Message) (string, GenerateStats, error)
	Complete(prompt string) (string, GenerateStats, error)
}

func New

func New(p Provider, config ProviderConfig) (GenerativeAI, error)

type Message

type Message struct {
	Role    string
	Content string
}

type Mode

type Mode int
const (
	ModeChat Mode = iota
	ModeCompletion
)

func ParseMode

func ParseMode(s string) (Mode, error)

func (Mode) String

func (m Mode) String() string

type Ollama

type Ollama struct {
	Client  *api.Client
	Model   string
	Options map[string]any
}

func (*Ollama) Chat

func (o *Ollama) Chat(messages []Message) (string, GenerateStats, error)

Chat generates a response from Ollama using a conversation history.

func (*Ollama) Complete

func (o *Ollama) Complete(prompt string) (string, GenerateStats, error)

type OllamaConfig

type OllamaConfig struct {
	BaseURL string
	Model   string
	Options map[string]any
}

func (*OllamaConfig) Validate

func (c *OllamaConfig) Validate() error

type OpenAI

type OpenAI struct {
	Client           *openai.Client
	Model            string
	FrequencyPenalty float64
	MaxTokens        int64
	PresencePenalty  float64
	ReasoningEffort  string
	Stop             string
	Temperature      float64
	TopP             float64
}

func (*OpenAI) Chat

func (o *OpenAI) Chat(messages []Message) (string, GenerateStats, error)

Chat generates a response from Ollama using a conversation history.

func (*OpenAI) Complete

func (o *OpenAI) Complete(prompt string) (string, GenerateStats, error)

type OpenAIConfig

type OpenAIConfig struct {
	BaseURL          string
	APIKey           string
	Model            string
	FrequencyPenalty float64
	MaxTokens        int64
	PresencePenalty  float64
	ReasoningEffort  string
	Stop             string
	Temperature      float64
	TopP             float64
}

func (*OpenAIConfig) Validate

func (c *OpenAIConfig) Validate() error

type Provider

type Provider int
const (
	ProviderOllama Provider = iota
	ProviderOpenAI
)

func ParseProvider

func ParseProvider(s string) (Provider, error)

func (Provider) String

func (p Provider) String() string

type ProviderConfig

type ProviderConfig interface {
	Validate() error
}

type ProviderFactory

type ProviderFactory func(ProviderConfig) (GenerativeAI, error)

Jump to

Keyboard shortcuts

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