utils

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigInstance = Config{}

Functions

func CloseGormDB

func CloseGormDB() error

func EnsureDir

func EnsureDir(path string) error

确保目录存在,如果不存在则创建

func FileExists

func FileExists(path string) bool

检查文件是否存在

func GetDefaultConfig

func GetDefaultConfig() *models.AppConfig

默认配置

func GetGormDB

func GetGormDB() (*gorm.DB, error)

func InitAppDirs

func InitAppDirs() error

初始化应用目录结构

func ValidateAIConfig

func ValidateAIConfig(config *models.AIConfig) error

ValidateAIConfig 验证AI配置是否完整

Types

type AIClient

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

AIClient AI客户端封装

func NewAIClient

func NewAIClient(config *models.AIConfig) (*AIClient, error)

NewAIClient 创建AI客户端

func (*AIClient) CallAI

func (c *AIClient) CallAI(ctx context.Context, reqConfig *AIRequestConfig) *AIResponse

CallAI 调用AI接口的统一入口

func (*AIClient) CallAIStream

func (c *AIClient) CallAIStream(ctx context.Context, systemPrompt, userPrompt string, enableStreaming bool) (string, error)

CallAIStream 简化的流式AI调用接口

func (*AIClient) CallAISync

func (c *AIClient) CallAISync(ctx context.Context, systemPrompt, userPrompt string) (string, error)

CallAISync 简化的同步AI调用接口

type AIRequestConfig

type AIRequestConfig struct {
	SystemPrompt string        // 系统提示词
	UserPrompt   string        // 用户输入内容
	Mode         AIRequestMode // 请求模式
	Streaming    bool          // 是否启用流式输出显示
}

AIRequestConfig AI请求配置

type AIRequestMode

type AIRequestMode int

AIRequestMode AI请求模式

const (
	// AIRequestModeSync 同步(非流式)请求
	AIRequestModeSync AIRequestMode = iota
	// AIRequestModeStream 流式请求
	AIRequestModeStream
)

type AIResponse

type AIResponse struct {
	Content  string        // AI返回的内容
	Duration time.Duration // 请求耗时
	Success  bool          // 是否成功
	Error    error         // 错误信息
}

AIResponse AI响应结果

type Config

type Config struct {
	HomeDir      string
	AppSeriesDir string
	AppDir       string
	ConfigDir    string
	ConfigPath   string
	DbDir        string
	DbPath       string
	LogDir       string
	LogPath      string
}

func (*Config) GetAppDir

func (c *Config) GetAppDir() string

func (*Config) GetAppSeriesDir

func (c *Config) GetAppSeriesDir() string

func (*Config) GetConfigDir

func (c *Config) GetConfigDir() string

func (*Config) GetConfigPath

func (c *Config) GetConfigPath() string

func (*Config) GetDbDir

func (c *Config) GetDbDir() string

func (*Config) GetDbPath

func (c *Config) GetDbPath() string

func (*Config) GetHomeDir

func (c *Config) GetHomeDir() string

func (*Config) GetLogDir

func (c *Config) GetLogDir() string

func (*Config) GetLogPath

func (c *Config) GetLogPath() string

func (*Config) LoadConfig

func (c *Config) LoadConfig() *models.AppConfig

func (*Config) SaveConfig

func (c *Config) SaveConfig(config *models.AppConfig)

Jump to

Keyboard shortcuts

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