feat: 新增语音转文字(ASR)功能
- 后端:新增 /api/audio/transcribe 接口,调用 Ollama whisper 进行语音识别 - 前端:新增 AudioTranscribePage.vue 页面,支持 MP3/WAV/M4A/OGG/FLAC 等格式 - 注册路由、工具卡片、智能助手欢迎语更新 Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Config 全局配置,从环境变量读取(带默认值)。
|
||||
// system_config 表中的值在运行时覆盖对应字段(见 service)。
|
||||
type Config struct {
|
||||
Port string
|
||||
DBPath string // SQLite 文件路径
|
||||
JWTSecret string
|
||||
JWTExpireMin int
|
||||
|
||||
LLMBaseURL string
|
||||
LLMAPIKey string
|
||||
LLMModel string
|
||||
EmbedModel string
|
||||
|
||||
KnowledgeServiceURL string
|
||||
KnowledgeIndexDir string
|
||||
|
||||
KBDataDir string
|
||||
KnowledgeSourceDir string
|
||||
|
||||
FileMaxDoc int64
|
||||
FileMaxVideo int64
|
||||
ChunkThreshold int64
|
||||
|
||||
LibreOfficeBin string
|
||||
PdftotextBin string
|
||||
|
||||
KingdeeBaseURL string
|
||||
KingdeeAccountID string
|
||||
KingdeeUsername string
|
||||
KingdeePassword string
|
||||
KingdeeLCID int
|
||||
KingdeeTimeoutSec int
|
||||
}
|
||||
|
||||
// Load 读取环境变量构造配置。缺失的用默认值(部署时通过 .env / systemd 注入)。
|
||||
func Load() *Config {
|
||||
baseDir := backendBaseDir()
|
||||
|
||||
return &Config{
|
||||
Port: getenv("PORT", "8080"),
|
||||
DBPath: getenv("DB_PATH", filepath.Join(baseDir, "data", "eai_agentplatform.db")),
|
||||
JWTSecret: getenv("JWT_SECRET", "change-this-to-a-strong-secret-in-production"),
|
||||
JWTExpireMin: getenvInt("JWT_EXPIRE_MINUTES", 480),
|
||||
|
||||
LLMBaseURL: getenv("LLM_BASE_URL", "http://127.0.0.1:11434/v1"),
|
||||
LLMAPIKey: getenv("LLM_API_KEY", "ollama"),
|
||||
LLMModel: getenv("LLM_MODEL", "qwen2.5:7b"),
|
||||
EmbedModel: getenv("EMBED_MODEL", "bge-m3"),
|
||||
|
||||
KnowledgeServiceURL: getenv("KNOWLEDGE_SERVICE_URL", "http://127.0.0.1:10233"),
|
||||
KnowledgeIndexDir: getenv("KNOWLEDGE_INDEX_DIR", filepath.Join(baseDir, "data", "faiss")),
|
||||
|
||||
KBDataDir: getenv("KB_DATA_DIR", filepath.Join(baseDir, "data", "kb_data")),
|
||||
KnowledgeSourceDir: getenv("KNOWLEDGE_SOURCE_DIR", filepath.Join(baseDir, "knowledge_source")),
|
||||
|
||||
FileMaxDoc: getenvInt64("FILE_MAX_SIZE_DOC", 209715200),
|
||||
FileMaxVideo: getenvInt64("FILE_MAX_SIZE_VIDEO", 2147483648),
|
||||
ChunkThreshold: getenvInt64("CHUNK_THRESHOLD", 104857600),
|
||||
|
||||
LibreOfficeBin: getenv("LIBREOFFICE_BIN", "libreoffice"),
|
||||
PdftotextBin: getenv("PDFTOTEXT_BIN", "pdftotext"),
|
||||
|
||||
KingdeeBaseURL: getenv("KINGDEE_BASE_URL", ""),
|
||||
KingdeeAccountID: getenv("KINGDEE_ACCOUNT_ID", ""),
|
||||
KingdeeUsername: getenv("KINGDEE_USERNAME", ""),
|
||||
KingdeePassword: getenv("KINGDEE_PASSWORD", ""),
|
||||
KingdeeLCID: getenvInt("KINGDEE_LCID", 2052),
|
||||
KingdeeTimeoutSec: getenvInt("KINGDEE_TIMEOUT_SEC", 15),
|
||||
}
|
||||
}
|
||||
|
||||
func backendBaseDir() string {
|
||||
if exe, err := os.Executable(); err == nil && exe != "" {
|
||||
return filepath.Clean(filepath.Join(filepath.Dir(exe), ".."))
|
||||
}
|
||||
if wd, err := os.Getwd(); err == nil && wd != "" {
|
||||
return wd
|
||||
}
|
||||
return "."
|
||||
}
|
||||
|
||||
func getenv(key, def string) string {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
return v
|
||||
}
|
||||
return def
|
||||
}
|
||||
|
||||
func getenvInt(key string, def int) int {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
if n, err := strconv.Atoi(v); err == nil {
|
||||
return n
|
||||
}
|
||||
}
|
||||
return def
|
||||
}
|
||||
|
||||
func getenvInt64(key string, def int64) int64 {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
if n, err := strconv.ParseInt(v, 10, 64); err == nil {
|
||||
return n
|
||||
}
|
||||
}
|
||||
return def
|
||||
}
|
||||
Reference in New Issue
Block a user