feat: 扩展配置结构,新增 Session/Heartbeat/Shutdown/STT Timeout/HTTP Client/TTS Output 配置项
This commit is contained in:
@@ -13,12 +13,19 @@ import (
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
App AppConfig `mapstructure:"app"`
|
App AppConfig `mapstructure:"app"`
|
||||||
Server ServerConfig `mapstructure:"server"`
|
Server ServerConfig `mapstructure:"server"`
|
||||||
|
Session SessionConfig `mapstructure:"session"`
|
||||||
Redis RedisConfig `mapstructure:"redis"`
|
Redis RedisConfig `mapstructure:"redis"`
|
||||||
AI AIConfig `mapstructure:"ai"`
|
AI AIConfig `mapstructure:"ai"`
|
||||||
Storage StorageConfig `mapstructure:"storage"`
|
Storage StorageConfig `mapstructure:"storage"`
|
||||||
Log LogConfig `mapstructure:"log"`
|
Log LogConfig `mapstructure:"log"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SessionConfig 会话管理配置。
|
||||||
|
type SessionConfig struct {
|
||||||
|
TTL int `mapstructure:"ttl"` // 会话过期时间(分钟)
|
||||||
|
MaxHistory int `mapstructure:"max_history"` // 对话历史上限(条)
|
||||||
|
}
|
||||||
|
|
||||||
type AppConfig struct {
|
type AppConfig struct {
|
||||||
Env string `mapstructure:"env"`
|
Env string `mapstructure:"env"`
|
||||||
Version string `mapstructure:"version"`
|
Version string `mapstructure:"version"`
|
||||||
@@ -29,6 +36,10 @@ type ServerConfig struct {
|
|||||||
Port int `mapstructure:"port"`
|
Port int `mapstructure:"port"`
|
||||||
ReadTimeout int `mapstructure:"read_timeout"`
|
ReadTimeout int `mapstructure:"read_timeout"`
|
||||||
WriteTimeout int `mapstructure:"write_timeout"`
|
WriteTimeout int `mapstructure:"write_timeout"`
|
||||||
|
HeartbeatInterval int `mapstructure:"heartbeat_interval"` // 心跳检查间隔(秒)
|
||||||
|
HeartbeatTimeout int `mapstructure:"heartbeat_timeout"` // 心跳超时(秒)
|
||||||
|
ShutdownTimeout int `mapstructure:"shutdown_timeout"` // 优雅关闭超时(秒)
|
||||||
|
AllowedOrigins []string `mapstructure:"allowed_origins"` // CORS 允许的来源,空表示允许所有
|
||||||
}
|
}
|
||||||
|
|
||||||
// Addr 返回 host:port 地址。
|
// Addr 返回 host:port 地址。
|
||||||
@@ -53,6 +64,8 @@ type STTConfig struct {
|
|||||||
APIKey string `mapstructure:"api_key"`
|
APIKey string `mapstructure:"api_key"`
|
||||||
Model string `mapstructure:"model"`
|
Model string `mapstructure:"model"`
|
||||||
Endpoint string `mapstructure:"endpoint"`
|
Endpoint string `mapstructure:"endpoint"`
|
||||||
|
Timeout int `mapstructure:"timeout"` // STT 超时(秒)
|
||||||
|
HTTPClientTimeout int `mapstructure:"http_client_timeout"` // HTTP 客户端超时(秒)
|
||||||
}
|
}
|
||||||
|
|
||||||
type LLMConfig struct {
|
type LLMConfig struct {
|
||||||
@@ -61,6 +74,7 @@ type LLMConfig struct {
|
|||||||
Model string `mapstructure:"model"`
|
Model string `mapstructure:"model"`
|
||||||
Endpoint string `mapstructure:"endpoint"`
|
Endpoint string `mapstructure:"endpoint"`
|
||||||
Timeout int `mapstructure:"timeout"`
|
Timeout int `mapstructure:"timeout"`
|
||||||
|
HTTPClientTimeout int `mapstructure:"http_client_timeout"` // HTTP 客户端超时(秒)
|
||||||
}
|
}
|
||||||
|
|
||||||
type TTSConfig struct {
|
type TTSConfig struct {
|
||||||
@@ -71,6 +85,9 @@ type TTSConfig struct {
|
|||||||
Speed float64 `mapstructure:"speed"`
|
Speed float64 `mapstructure:"speed"`
|
||||||
Endpoint string `mapstructure:"endpoint"`
|
Endpoint string `mapstructure:"endpoint"`
|
||||||
Timeout int `mapstructure:"timeout"`
|
Timeout int `mapstructure:"timeout"`
|
||||||
|
HTTPClientTimeout int `mapstructure:"http_client_timeout"` // HTTP 客户端超时(秒)
|
||||||
|
OutputFormat string `mapstructure:"output_format"` // 输出格式:mp3/wav
|
||||||
|
SampleRate int `mapstructure:"sample_rate"` // 输出采样率
|
||||||
}
|
}
|
||||||
|
|
||||||
type StorageConfig struct {
|
type StorageConfig struct {
|
||||||
@@ -94,25 +111,37 @@ func Load() (*Config, error) {
|
|||||||
|
|
||||||
// 默认值
|
// 默认值
|
||||||
v.SetDefault("app.env", "dev")
|
v.SetDefault("app.env", "dev")
|
||||||
|
v.SetDefault("app.version", "dev")
|
||||||
v.SetDefault("server.host", "0.0.0.0")
|
v.SetDefault("server.host", "0.0.0.0")
|
||||||
v.SetDefault("server.port", 8080)
|
v.SetDefault("server.port", 8080)
|
||||||
v.SetDefault("server.read_timeout", 30)
|
v.SetDefault("server.read_timeout", 30)
|
||||||
v.SetDefault("server.write_timeout", 30)
|
v.SetDefault("server.write_timeout", 30)
|
||||||
|
v.SetDefault("server.heartbeat_interval", 30)
|
||||||
|
v.SetDefault("server.heartbeat_timeout", 60)
|
||||||
|
v.SetDefault("server.shutdown_timeout", 10)
|
||||||
|
v.SetDefault("session.ttl", 30)
|
||||||
|
v.SetDefault("session.max_history", 20)
|
||||||
v.SetDefault("redis.addr", "localhost:6379")
|
v.SetDefault("redis.addr", "localhost:6379")
|
||||||
v.SetDefault("redis.db", 0)
|
v.SetDefault("redis.db", 0)
|
||||||
v.SetDefault("ai.stt.provider", "deepgram")
|
v.SetDefault("ai.stt.provider", "deepgram")
|
||||||
v.SetDefault("ai.stt.model", "nova-2")
|
v.SetDefault("ai.stt.model", "nova-2")
|
||||||
v.SetDefault("ai.stt.endpoint", "wss://api.deepgram.com/v1/listen")
|
v.SetDefault("ai.stt.endpoint", "wss://api.deepgram.com/v1/listen")
|
||||||
|
v.SetDefault("ai.stt.timeout", 5)
|
||||||
|
v.SetDefault("ai.stt.http_client_timeout", 30)
|
||||||
v.SetDefault("ai.llm.provider", "openai")
|
v.SetDefault("ai.llm.provider", "openai")
|
||||||
v.SetDefault("ai.llm.model", "gpt-4o")
|
v.SetDefault("ai.llm.model", "gpt-4o")
|
||||||
v.SetDefault("ai.llm.endpoint", "https://api.openai.com/v1")
|
v.SetDefault("ai.llm.endpoint", "https://api.openai.com/v1")
|
||||||
v.SetDefault("ai.llm.timeout", 10)
|
v.SetDefault("ai.llm.timeout", 10)
|
||||||
|
v.SetDefault("ai.llm.http_client_timeout", 60)
|
||||||
v.SetDefault("ai.tts.provider", "openai")
|
v.SetDefault("ai.tts.provider", "openai")
|
||||||
v.SetDefault("ai.tts.model", "tts-1")
|
v.SetDefault("ai.tts.model", "tts-1")
|
||||||
v.SetDefault("ai.tts.voice", "mimo_default")
|
v.SetDefault("ai.tts.voice", "mimo_default")
|
||||||
v.SetDefault("ai.tts.speed", 1.0)
|
v.SetDefault("ai.tts.speed", 1.0)
|
||||||
v.SetDefault("ai.tts.endpoint", "https://api.openai.com/v1")
|
v.SetDefault("ai.tts.endpoint", "https://api.openai.com/v1")
|
||||||
v.SetDefault("ai.tts.timeout", 5)
|
v.SetDefault("ai.tts.timeout", 5)
|
||||||
|
v.SetDefault("ai.tts.http_client_timeout", 30)
|
||||||
|
v.SetDefault("ai.tts.output_format", "mp3")
|
||||||
|
v.SetDefault("ai.tts.sample_rate", 24000)
|
||||||
v.SetDefault("storage.driver", "memory")
|
v.SetDefault("storage.driver", "memory")
|
||||||
v.SetDefault("log.level", "info")
|
v.SetDefault("log.level", "info")
|
||||||
v.SetDefault("log.format", "console")
|
v.SetDefault("log.format", "console")
|
||||||
|
|||||||
Reference in New Issue
Block a user