service

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileInfo

type FileInfo struct {
	Name      string
	Size      int64
	Extension string
	MD5       string
	URL       string
}

FileInfo 文件信息

type LLMProvider

type LLMProvider interface {
	// ChatCompletion 普通对话
	ChatCompletion(ctx context.Context, messages []Message, config ModelConfig) (string, Usage, error)
	// StreamCompletion 流式对话
	StreamCompletion(ctx context.Context, messages []Message, config ModelConfig, callback func(chunk string, usage Usage, err error))
	// ValidateModel 验证模型配置
	ValidateModel(ctx context.Context, config ModelConfig) ([]ModelInfo, error)
}

LLMProvider LLM 提供商接口

type Message

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

Message LLM 聊天消息

type ModelConfig

type ModelConfig struct {
	BaseURL string `json:"base_url"`
	APIKey  string `json:"api_key"`
	Model   string `json:"model"`
}

ModelConfig LLM 模型配置

type ModelInfo

type ModelInfo struct {
	ID      string `json:"id"`
	OwnedBy string `json:"owned_by"`
}

ModelInfo 模型信息

type SMSProvider

type SMSProvider interface {
	// SendCode 发送验证码
	SendCode(ctx context.Context, phone string, code string) error
	// SendMessage 发送普通短信
	SendMessage(ctx context.Context, phone string, content string, templateCode string) error
}

SMSProvider 短信服务提供商接口. 远程调用应遵循 ctx 的超时/取消;实现方需在 ctx 结束时尽快返回.

type StorageProvider

type StorageProvider interface {
	// UploadFile 上传文件
	UploadFile(ctx context.Context, file []byte, filename string) (*FileInfo, error)
	// DeleteFile 删除文件
	DeleteFile(ctx context.Context, fileID string) error
	// GetFileURL 获取文件访问URL
	GetFileURL(ctx context.Context, fileID string) (string, error)
}

StorageProvider 文件存储提供商接口. 上传/下载/删除均可能访问远端存储,因此统一接收 ctx.

type Usage

type Usage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

Usage Token 使用情况

Jump to

Keyboard shortcuts

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