🎨 AI supports configuration randomness and context number https://github.com/siyuan-note/siyuan/issues/10660

This commit is contained in:
Daniel 2024-03-20 10:54:22 +08:00
parent 97e3ff656d
commit a7e1e3abac
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
12 changed files with 66 additions and 16 deletions

View file

@ -29,15 +29,16 @@ type AI struct {
}
type OpenAI struct {
APIKey string `json:"apiKey"`
APITimeout int `json:"apiTimeout"`
APIProxy string `json:"apiProxy"`
APIModel string `json:"apiModel"`
APIMaxTokens int `json:"apiMaxTokens"`
APIBaseURL string `json:"apiBaseURL"`
APIUserAgent string `json:"apiUserAgent"`
APIProvider string `json:"apiProvider"` // OpenAI, Azure
APIVersion string `json:"apiVersion"` // Azure API version
APIKey string `json:"apiKey"`
APITimeout int `json:"apiTimeout"`
APIProxy string `json:"apiProxy"`
APIModel string `json:"apiModel"`
APIMaxTokens int `json:"apiMaxTokens"`
APITemperature float64 `json:"apiTemperature"`
APIBaseURL string `json:"apiBaseURL"`
APIUserAgent string `json:"apiUserAgent"`
APIProvider string `json:"apiProvider"` // OpenAI, Azure
APIVersion string `json:"apiVersion"` // Azure API version
}
func NewAI() *AI {
@ -69,6 +70,13 @@ func NewAI() *AI {
}
}
if temperature := os.Getenv("SIYUAN_OPENAI_API_TEMPERATURE"); "" != temperature {
temperatureFloat, err := strconv.ParseFloat(temperature, 64)
if nil == err {
openAI.APITemperature = temperatureFloat
}
}
if baseURL := os.Getenv("SIYUAN_OPENAI_API_BASE_URL"); "" != baseURL {
openAI.APIBaseURL = baseURL
}