package ai import ( "apigo.cc/ai/ai/llm" _ "apigo.cc/ai/ai/llm/openai" _ "apigo.cc/ai/ai/llm/zhipu" "github.com/ssgo/config" "github.com/ssgo/u" "os" ) var confAes = u.NewAes([]byte("?GQ$0K0GgLdO=f+~L68PLm$uhKr4'=tV"), []byte("VFs7@sK61cj^f?HZ")) var keysIsSet = false var isInit = false func SetSSKey(key, iv []byte) { if !keysIsSet { confAes = u.NewAes(key, iv) keysIsSet = true } } func Init() { InitFrom("") } func InitFrom(filePath string) { if !isInit { isInit = true list := map[string]*struct { Endpoint string ApiKey string DefaultChatModelConfig llm.ChatConfig Llm string }{} savedPath := "" if filePath != "" { curPath, _ := os.Getwd() if curPath != filePath { savedPath = curPath _ = os.Chdir(filePath) config.ResetConfigEnv() } } _ = config.LoadConfig("llm", &list) if savedPath != "" { _ = os.Chdir(savedPath) } for name, llmConf := range list { if llmConf.Llm == "" { llmConf.Llm = name } llmConf.ApiKey = confAes.DecryptUrlBase64ToString(llmConf.ApiKey) llm.Create(name, llmConf.Llm, llm.Config{ Endpoint: llmConf.Endpoint, ApiKey: llmConf.ApiKey, ChatConfig: llmConf.DefaultChatModelConfig, }) } } }