51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package tools
|
|
|
|
import (
|
|
"go-bot/config"
|
|
"log"
|
|
)
|
|
|
|
func GetOAIConfig() (string, string, string, string, int64) {
|
|
cfg := config.GetConfig()
|
|
// config.PrintConfig(cfg, "")
|
|
var OPENAI_API_KEY, OPENAI_BaseURL, MODEL, PROMPT string
|
|
var context int64
|
|
openai_cfg := cfg["OPENAI"].(map[string]interface{})
|
|
if openai_cfg["OPENAI_API_KEY"] != nil {
|
|
OPENAI_API_KEY = openai_cfg["OPENAI_API_KEY"].(string)
|
|
} else {
|
|
log.Println("OPENAI_API_KEY 未配置")
|
|
}
|
|
|
|
if openai_cfg["OPENAI_BaseURL"] != nil {
|
|
OPENAI_BaseURL = openai_cfg["OPENAI_BaseURL"].(string)
|
|
} else {
|
|
log.Println("OPENAI_BaseURL 未配置,使用openai默认配置")
|
|
OPENAI_BaseURL = "https://api.openai.com/v1"
|
|
}
|
|
|
|
if openai_cfg["MODEL"] != nil {
|
|
MODEL = openai_cfg["MODEL"].(string)
|
|
} else {
|
|
log.Println("模型 未配置,使用默认 gpt-4o 模型")
|
|
MODEL = "gpt-4o"
|
|
}
|
|
if openai_cfg["PROMPT"] != nil {
|
|
PROMPT = openai_cfg["PROMPT"].(string)
|
|
} else {
|
|
log.Println("PROMPT 未配置,使用默认 PROMPT")
|
|
PROMPT = ""
|
|
}
|
|
if openai_cfg["Context"] != nil {
|
|
// var err error
|
|
context = openai_cfg["Context"].(int64)
|
|
// if err != nil {
|
|
// log.Println("Context 解析错误,使用默认 Context")
|
|
// context = 5
|
|
// }
|
|
} else {
|
|
log.Println("Context 未配置,使用默认 Context")
|
|
context = 5
|
|
}
|
|
return OPENAI_API_KEY, OPENAI_BaseURL, MODEL, PROMPT, int64(context)
|
|
}
|