mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🎨 Support custom AI request User-Agent header https://github.com/siyuan-note/siyuan/issues/10351
This commit is contained in:
parent
3df54adcc5
commit
7e87c8c8ad
11 changed files with 59 additions and 8 deletions
|
|
@ -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}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue