service 修改 Redis 存储 KV
This commit is contained in:
@@ -28,14 +28,6 @@ type Config struct {
|
||||
FrequencyPenalty float32 `mapstructure:"frequency_penalty"`
|
||||
BotDesc string `mapstructure:"bot_desc"`
|
||||
MinResponseTokens int `mapstructure:"min_response_tokens"`
|
||||
ContextTTL int `mapstructure:"context_ttl"`
|
||||
ContextLen int `mapstructure:"context_len"`
|
||||
}
|
||||
Mysql struct {
|
||||
DSN string
|
||||
MaxLifeTime int
|
||||
MaxOpenConn int
|
||||
MaxIdleConn int
|
||||
}
|
||||
Redis struct {
|
||||
Host string
|
||||
@@ -55,28 +47,6 @@ type Config struct {
|
||||
Address string
|
||||
}
|
||||
}
|
||||
Vector struct {
|
||||
Provider string
|
||||
Threshold float32
|
||||
Tencent struct {
|
||||
Url string
|
||||
Username string
|
||||
Pwd string
|
||||
Database string
|
||||
Timeout int
|
||||
MaxIdleConnPerHost int
|
||||
ReadConsistency string
|
||||
IdleConnTimeout int
|
||||
}
|
||||
Pgvector struct {
|
||||
DSN string `mapstructure:"dsn"`
|
||||
Table string `mapstructure:"table"`
|
||||
Dimensions int `mapstructure:"dimensions"`
|
||||
MaxLifeTime int `mapstructure:"maxLifeTime"`
|
||||
MaxOpenConn int `mapstructure:"maxOpenConn"`
|
||||
MaxIdleConn int `mapstructure:"maxIdleConn"`
|
||||
}
|
||||
}
|
||||
Embedding struct {
|
||||
Provider string
|
||||
BaseUrl string `mapstructure:"base_url"`
|
||||
@@ -84,15 +54,11 @@ type Config struct {
|
||||
Model string `mapstructure:"model"`
|
||||
Timeout int
|
||||
}
|
||||
VectorDB struct {
|
||||
Url string
|
||||
Username string
|
||||
Pwd string
|
||||
Database string
|
||||
Timeout int
|
||||
MaxIdleConnPerHost int
|
||||
ReadConsistency string
|
||||
IdleConnTimeout int
|
||||
Faiss struct {
|
||||
BaseUrl string `mapstructure:"base_url"`
|
||||
SearchK int `mapstructure:"search_k"`
|
||||
SimilarityThreshold float32 `mapstructure:"similarity_threshold"`
|
||||
Timeout int
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,39 +89,6 @@ func GetConfig() *Config {
|
||||
}
|
||||
|
||||
func normalizeConfig(conf *Config) {
|
||||
if conf.Vector.Provider == "" {
|
||||
conf.Vector.Provider = "tencent"
|
||||
}
|
||||
if conf.Vector.Threshold == 0 {
|
||||
conf.Vector.Threshold = 0.99
|
||||
}
|
||||
|
||||
// Backfill the new vector.tencent block from the legacy vectorDB config.
|
||||
if conf.Vector.Tencent.Url == "" {
|
||||
conf.Vector.Tencent.Url = conf.VectorDB.Url
|
||||
}
|
||||
if conf.Vector.Tencent.Username == "" {
|
||||
conf.Vector.Tencent.Username = conf.VectorDB.Username
|
||||
}
|
||||
if conf.Vector.Tencent.Pwd == "" {
|
||||
conf.Vector.Tencent.Pwd = conf.VectorDB.Pwd
|
||||
}
|
||||
if conf.Vector.Tencent.Database == "" {
|
||||
conf.Vector.Tencent.Database = conf.VectorDB.Database
|
||||
}
|
||||
if conf.Vector.Tencent.Timeout == 0 {
|
||||
conf.Vector.Tencent.Timeout = conf.VectorDB.Timeout
|
||||
}
|
||||
if conf.Vector.Tencent.MaxIdleConnPerHost == 0 {
|
||||
conf.Vector.Tencent.MaxIdleConnPerHost = conf.VectorDB.MaxIdleConnPerHost
|
||||
}
|
||||
if conf.Vector.Tencent.ReadConsistency == "" {
|
||||
conf.Vector.Tencent.ReadConsistency = conf.VectorDB.ReadConsistency
|
||||
}
|
||||
if conf.Vector.Tencent.IdleConnTimeout == 0 {
|
||||
conf.Vector.Tencent.IdleConnTimeout = conf.VectorDB.IdleConnTimeout
|
||||
}
|
||||
|
||||
if conf.Embedding.Provider == "" {
|
||||
conf.Embedding.Provider = "openai-compatible"
|
||||
}
|
||||
@@ -168,6 +101,18 @@ func normalizeConfig(conf *Config) {
|
||||
if conf.Embedding.Timeout == 0 {
|
||||
conf.Embedding.Timeout = 10
|
||||
}
|
||||
if conf.Faiss.BaseUrl == "" {
|
||||
conf.Faiss.BaseUrl = "http://127.0.0.1:8451"
|
||||
}
|
||||
if conf.Faiss.SearchK == 0 {
|
||||
conf.Faiss.SearchK = 1
|
||||
}
|
||||
if conf.Faiss.SimilarityThreshold == 0 {
|
||||
conf.Faiss.SimilarityThreshold = 0.9
|
||||
}
|
||||
if conf.Faiss.Timeout == 0 {
|
||||
conf.Faiss.Timeout = 10
|
||||
}
|
||||
}
|
||||
|
||||
func applySecretEnvOverrides(conf *Config) {
|
||||
@@ -177,6 +122,9 @@ func applySecretEnvOverrides(conf *Config) {
|
||||
if v := os.Getenv("AI_CHAT_EMBEDDING_API_KEY"); v != "" {
|
||||
conf.Embedding.ApiKey = v
|
||||
}
|
||||
if v := os.Getenv("AI_CHAT_FAISS_BASE_URL"); v != "" {
|
||||
conf.Faiss.BaseUrl = v
|
||||
}
|
||||
if v := os.Getenv("REDIS_PASSWORD"); v != "" {
|
||||
conf.Redis.Pwd = v
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user