utils

package
v0.0.6 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigInstance = Config{}

Functions

func BackupFile

func BackupFile(filePath string) (string, error)

BackupFile 备份文件到本地backup目录 filePath: 要备份的文件路径 返回:备份文件路径和错误信息

func CallAIStream

func CallAIStream(ctx context.Context, config *models.AppConfig, systemPrompt, userPrompt string, enableStreaming bool) (string, error)

CallAIStream 简化的流式AI调用接口

func CallAISync

func CallAISync(ctx context.Context, config *models.AppConfig, systemPrompt, userPrompt string) (string, error)

CallAISync 简化的同步AI调用接口

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.AppConfig) error

ValidateAIConfig 验证AI配置是否完整

func WriteFileAtomically

func WriteFileAtomically(filePath string, data []byte) error

WriteFileAtomically 原子写入文件(先写临时文件再 rename)

Types

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响应结果

func CallAI

func CallAI(ctx context.Context, config *models.AppConfig, reqConfig *AIRequestConfig) *AIResponse

CallAI 调用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) error

Jump to

Keyboard shortcuts

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