mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-03 19:41:31 +08:00
🎨 OpenAI API 接入增加环境变量 SIYUAN_OPENAI_API_BASE_URL
This commit is contained in:
parent
1c9e0356cc
commit
a8129de5f5
@ -27,26 +27,20 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func ChatGPT(msg string) (ret string) {
|
func ChatGPT(msg string) (ret string) {
|
||||||
cloud := IsSubscriber()
|
if !isOpenAIAPIEnabled() {
|
||||||
if !cloud && !isOpenAIAPIEnabled() {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cloud = false
|
return chatGPT(msg, false)
|
||||||
|
|
||||||
return chatGPT(msg, cloud)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ChatGPTWithAction(ids []string, action string) (ret string) {
|
func ChatGPTWithAction(ids []string, action string) (ret string) {
|
||||||
cloud := IsSubscriber()
|
if !isOpenAIAPIEnabled() {
|
||||||
if !cloud && !isOpenAIAPIEnabled() {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cloud = false
|
|
||||||
|
|
||||||
msg := getBlocksContent(ids)
|
msg := getBlocksContent(ids)
|
||||||
ret = chatGPTWithAction(msg, action, cloud)
|
ret = chatGPTWithAction(msg, action, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ var (
|
|||||||
OpenAIAPITimeout = 30 * time.Second
|
OpenAIAPITimeout = 30 * time.Second
|
||||||
OpenAIAPIProxy = ""
|
OpenAIAPIProxy = ""
|
||||||
OpenAIAPIMaxTokens = 0
|
OpenAIAPIMaxTokens = 0
|
||||||
|
OpenAIAPIBaseURL = "https://api.openai.com/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ChatGPT(msg string, contextMsgs []string, c *gogpt.Client) (ret string, stop bool) {
|
func ChatGPT(msg string, contextMsgs []string, c *gogpt.Client) (ret string, stop bool) {
|
||||||
@ -94,6 +95,8 @@ func NewOpenAIClient() *gogpt.Client {
|
|||||||
config.HTTPClient = &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxyUrl)}}
|
config.HTTPClient = &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxyUrl)}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config.BaseURL = OpenAIAPIBaseURL
|
||||||
return gogpt.NewClientWithConfig(config)
|
return gogpt.NewClientWithConfig(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,5 +127,15 @@ func initOpenAI() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logging.LogInfof("OpenAI API enabled [maxTokens=%d, timeout=%ds, proxy=%s]", OpenAIAPIMaxTokens, int(OpenAIAPITimeout.Seconds()), OpenAIAPIProxy)
|
baseURL := os.Getenv("SIYUAN_OPENAI_API_BASE_URL")
|
||||||
|
if "" != baseURL {
|
||||||
|
OpenAIAPIBaseURL = baseURL
|
||||||
|
}
|
||||||
|
|
||||||
|
logging.LogInfof("OpenAI API enabled\n"+
|
||||||
|
" baseURL=%s\n"+
|
||||||
|
" timeout=%ds\n"+
|
||||||
|
" proxy=%s\n"+
|
||||||
|
" maxTokens=%d",
|
||||||
|
OpenAIAPIBaseURL, int(OpenAIAPITimeout.Seconds()), OpenAIAPIProxy, OpenAIAPIMaxTokens)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user