msyql 容器化, aichatservice 容器化
This commit is contained in:
22
ai-chat-backend/docker.config.yaml
Normal file
22
ai-chat-backend/docker.config.yaml
Normal file
@@ -0,0 +1,22 @@
|
||||
http:
|
||||
ip: 0.0.0.0
|
||||
port: 7080
|
||||
frontend_path: "www"
|
||||
log:
|
||||
level: "info"
|
||||
logPath: "runtime/logs/app.log"
|
||||
chat:
|
||||
model: "kimi-k2.5"
|
||||
max_tokens: 4096
|
||||
temperature: 1
|
||||
top_p: 1
|
||||
presence_penalty: 0
|
||||
frequency_penalty: 0
|
||||
bot_desc: "你是一个AI助手,我需要你模拟一名资深的软件工程师来回答我的问题"
|
||||
min_response_tokens: 600
|
||||
context_ttl: 1800
|
||||
context_len: 4
|
||||
dependOn:
|
||||
ai-chat-service:
|
||||
address: "ai-chat-service:50055"
|
||||
accessToken: "me256487ang1chubdpdialoud22sev1ozhoguumyqca"
|
||||
@@ -1,13 +1,9 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"github.com/spf13/viper"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -45,7 +41,6 @@ type Config struct {
|
||||
var conf *Config
|
||||
|
||||
func InitConfig(filePath string, typ ...string) {
|
||||
loadProjectDotEnv(filePath)
|
||||
v := viper.New()
|
||||
v.SetConfigFile(filePath)
|
||||
if len(typ) > 0 {
|
||||
@@ -61,7 +56,6 @@ func InitConfig(filePath string, typ ...string) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
normalizeConfig(conf)
|
||||
overrideConfigFromEnv(conf)
|
||||
|
||||
}
|
||||
|
||||
@@ -98,88 +92,3 @@ func normalizeConfig(conf *Config) {
|
||||
conf.DependOn.AiChatService.Address = "localhost:50055"
|
||||
}
|
||||
}
|
||||
|
||||
func overrideConfigFromEnv(conf *Config) {
|
||||
overrideString(&conf.Http.IP, os.Getenv("SERVER_HOST"))
|
||||
overrideInt(&conf.Http.Port, os.Getenv("SERVER_PORT"))
|
||||
overrideString(&conf.BasicAuthUser, os.Getenv("BASIC_AUTH_USER"))
|
||||
overrideString(&conf.BasicAuthPassword, os.Getenv("BASIC_AUTH_PASSWORD"))
|
||||
overrideString(&conf.FrontendPath, os.Getenv("FRONTEND_PATH"))
|
||||
overrideString(&conf.Chat.Model, os.Getenv("OPENAI_MODEL"))
|
||||
overrideInt(&conf.Chat.MaxTokens, os.Getenv("OPENAI_MAX_TOKENS"))
|
||||
overrideScaledFloat32(&conf.Chat.Temperature, os.Getenv("OPENAI_TEMPERATURE"))
|
||||
overrideScaledFloat32(&conf.Chat.PresencePenalty, os.Getenv("OPENAI_PRESENCE_PENALTY"))
|
||||
overrideScaledFloat32(&conf.Chat.FrequencyPenalty, os.Getenv("OPENAI_FREQUENCY_PENALTY"))
|
||||
overrideInt(&conf.Chat.MinResponseTokens, os.Getenv("CHAT_MIN_RESPONSE_TOKENS"))
|
||||
overrideString(&conf.DependOn.AiChatService.Address, firstNonEmpty(
|
||||
os.Getenv("AI_CHAT_SERVICE_ADDRESS"),
|
||||
os.Getenv("AI_CHAT_SERVICE_ADDR"),
|
||||
))
|
||||
overrideString(&conf.DependOn.AiChatService.AccessToken, os.Getenv("AI_CHAT_SERVICE_ACCESS_TOKEN"))
|
||||
}
|
||||
|
||||
func loadProjectDotEnv(configFilePath string) {
|
||||
projectRoot := filepath.Dir(filepath.Dir(configFilePath))
|
||||
envPath := filepath.Join(projectRoot, ".env")
|
||||
file, err := os.Open(envPath)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
line := strings.TrimSpace(scanner.Text())
|
||||
if line == "" || strings.HasPrefix(line, "#") {
|
||||
continue
|
||||
}
|
||||
key, value, ok := strings.Cut(line, "=")
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
key = strings.TrimSpace(key)
|
||||
value = strings.TrimSpace(value)
|
||||
if key == "" {
|
||||
continue
|
||||
}
|
||||
if _, exists := os.LookupEnv(key); exists {
|
||||
continue
|
||||
}
|
||||
_ = os.Setenv(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
func firstNonEmpty(values ...string) string {
|
||||
for _, value := range values {
|
||||
if strings.TrimSpace(value) != "" {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func overrideString(target *string, value string) {
|
||||
if strings.TrimSpace(value) != "" {
|
||||
*target = strings.TrimSpace(value)
|
||||
}
|
||||
}
|
||||
|
||||
func overrideInt(target *int, value string) {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
return
|
||||
}
|
||||
if parsed, err := strconv.Atoi(value); err == nil {
|
||||
*target = parsed
|
||||
}
|
||||
}
|
||||
|
||||
func overrideScaledFloat32(target *float32, value string) {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
return
|
||||
}
|
||||
if parsed, err := strconv.ParseFloat(value, 32); err == nil {
|
||||
*target = float32(parsed / 100.0)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user