🎨 Support custom AI request User-Agent header https://github.com/siyuan-note/siyuan/issues/10351

This commit is contained in:
Daniel 2024-02-15 10:59:37 +08:00
parent 3df54adcc5
commit 7e87c8c8ad
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
11 changed files with 59 additions and 8 deletions

View file

@ -17,6 +17,7 @@
package conf
import (
"github.com/siyuan-note/siyuan/kernel/util"
"os"
"strconv"
@ -34,13 +35,15 @@ type OpenAI struct {
APIModel string `json:"apiModel"`
APIMaxTokens int `json:"apiMaxTokens"`
APIBaseURL string `json:"apiBaseURL"`
APIUserAgent string `json:"apiUserAgent"`
}
func NewAI() *AI {
openAI := &OpenAI{
APITimeout: 30,
APIModel: openai.GPT3Dot5Turbo,
APIBaseURL: "https://api.openai.com/v1",
APITimeout: 30,
APIModel: openai.GPT3Dot5Turbo,
APIBaseURL: "https://api.openai.com/v1",
APIUserAgent: util.UserAgent,
}
openAI.APIKey = os.Getenv("SIYUAN_OPENAI_API_KEY")
@ -67,5 +70,8 @@ func NewAI() *AI {
openAI.APIBaseURL = baseURL
}
if userAgent := os.Getenv("SIYUAN_OPENAI_API_USER_AGENT"); "" != userAgent {
openAI.APIUserAgent = userAgent
}
return &AI{OpenAI: openAI}
}