70 lines
2.8 KiB
Go
70 lines
2.8 KiB
Go
package service
|
|
|
|
import (
|
|
"ai-search/utils"
|
|
|
|
"github.com/ilyakaznacheev/cleanenv"
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
type AppSettings struct {
|
|
ListenAddr string `env:"LISTEN_ADDR" env-default:":8080"`
|
|
DBPath string `env:"DB_PATH" env-default:"/litefs/db"`
|
|
OpenAIEndpint string `env:"OPENAI_ENDPOINT" env-required:"true"`
|
|
OpenAIAPIKey string `env:"OPENAI_API_KEY" env-required:"true"`
|
|
OpenAIWriterPrompt string `env:"OPENAI_WRITER_PROMPT" env-default:"您是一名人工智能写作助手,可以根据先前文本的上下文继续现有文本。给予后面的字符比开始的字符更多的权重/优先级。而且绝对一定要尽量多使用中文!将您的回答限制在 200 个字符以内,但请确保构建完整的句子。"`
|
|
HttpProxy string `env:"HTTP_PROXY"`
|
|
IsDebug bool `env:"DEBUG" env-default:"false"`
|
|
ChatMaxTokens int `env:"CHAT_MAX_TOKENS" env-default:"400"`
|
|
OpenAIChatEndpoint string `env:"OPENAI_CHAT_ENDPOINT" env-required:"true"`
|
|
OpenAIChatAPIKey string `env:"OPENAI_CHAT_API_KEY" env-required:"true"`
|
|
OpenAIChatNetworkDelay int `env:"OPENAI_CHAT_NETWORK_DELAY" env-default:"5"`
|
|
OpenAIChatQueueLen int `env:"OPENAI_CHAT_QUEUE_LEN" env-default:"10"`
|
|
CacheSize int `env:"CACHE_SIZE" env-default:"100"` // in MB
|
|
RAGSearchCount int `env:"RAG_SEARCH_COUNT" env-default:"8"`
|
|
RAGSearchCacheTime int `env:"RAG_SEARCH_CACHE_TIME" env-default:"1200"` // sec
|
|
RPCEndpoints RPCEndpoints `env-prefix:"RPC_"`
|
|
Prompts Prompts `env-prefix:"PROMPT_"`
|
|
RAGParams RAGParams `env-prefix:"RAG_"`
|
|
}
|
|
|
|
type RPCEndpoints struct {
|
|
SearchURL string `env:"SEARCH_URL" env-required:"true"`
|
|
}
|
|
|
|
type Prompts struct {
|
|
RAGPath string `env:"RAG_PATH" env-default:""`
|
|
MoreQuestionsPath string `env:"MORE_QUESTIONS_PATH" env-default:""`
|
|
}
|
|
|
|
type RAGParams struct {
|
|
MaxTokens int `env:"MAX_TOKENS" env-default:"2048"`
|
|
MoreQuestionsMaxTokens int `env:"MORE_QUESTIONS_MAX_TOKENS" env-default:"1024"`
|
|
Temperature float32 `env:"TEMPERATURE" env-default:"0.9"`
|
|
MoreQuestionsTemperature float32 `env:"MORE_QUESTIONS_TEMPERATURE" env-default:"0.7"`
|
|
}
|
|
|
|
var (
|
|
appSetting *AppSettings
|
|
)
|
|
|
|
func init() {
|
|
godotenv.Load()
|
|
conf := &AppSettings{}
|
|
if err := cleanenv.ReadEnv(conf); err != nil {
|
|
panic(err)
|
|
}
|
|
appSetting = conf
|
|
InitCache()
|
|
if len(appSetting.Prompts.MoreQuestionsPath) >= 0 {
|
|
moreQuestionsPrompt = utils.GetFileContent(appSetting.Prompts.MoreQuestionsPath)
|
|
}
|
|
if len(appSetting.Prompts.RAGPath) >= 0 {
|
|
ragPrompt = utils.GetFileContent(appSetting.Prompts.RAGPath)
|
|
}
|
|
}
|
|
|
|
func GetSettings() *AppSettings {
|
|
return appSetting
|
|
}
|