llm

package
v0.0.0-...-4d8ee2f Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnexpectedResponse = errors.New("llm: unexpected API response")
)

Functions

func Completion

func Completion(prompt string) (string, error)

Completion generates text from a text prompt.

func CompletionByParams

func CompletionByParams(args ...AllowedParam) (openai.ChatCompletionMessage, error)

func CompletionBySystem

func CompletionBySystem(prompt string) (string, error)

Completion generates text from a text prompt.

func Embedding

func Embedding(text string) ([]float32, error)

Embedding returns a vector representation of the input text.

func EmbeddingWithDim

func EmbeddingWithDim(text string, dimensions int) ([]float32, error)

EmbeddingWithDim returns embedding vector with specified dimension.

func Vision

func Vision(img image.Image) (string, error)

Vision analyzes an image and returns a textual description. Note: This function's implementation might require updates based on how openai-go handles images.

func VisionWithPrompt

func VisionWithPrompt(img image.Image, prompt string) (string, error)

VisionWithPrompt analyzes an image with a custom instruction.

Types

type AllowedParam

type AllowedParam interface {
	Allowed()
}

type Config

type Config struct {
	APIKey      string
	BaseURL     string // 支持兼容 API(如 Ollama)
	Model       string // 默认文本模型
	VisionModel string // 默认视觉模型
	EmbedModel  string // 默认 embedding 模型
	EmbedDim    int
	Temperature float64
	TopP        float64
}

func LoadConfig

func LoadConfig() (*Config, error)

type LLMClient

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

type MessageFunc

type MessageFunc func() openai.ChatCompletionMessageParamUnion

func SystemMessage

func SystemMessage(prompt string) MessageFunc

func ToolMessage

func ToolMessage(prompt string, toolCallID string) MessageFunc

func UserMessage

func UserMessage(prompt string) MessageFunc

func (MessageFunc) Allowed

func (MessageFunc) Allowed()

type ToolFunc

type ToolFunc func() []openai.ChatCompletionToolParam

func ToolsByJson

func ToolsByJson(jstr string) ToolFunc

func (ToolFunc) Allowed

func (ToolFunc) Allowed()

Directories

Path Synopsis
mcp

Jump to

Keyboard shortcuts

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