This commit is contained in:
Daniel 2024-02-28 23:36:10 +08:00
parent 9f69d7dc4a
commit 77885a8cc0
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
10 changed files with 35 additions and 3 deletions

View file

@ -37,6 +37,7 @@ type OpenAI struct {
APIBaseURL string `json:"apiBaseURL"`
APIUserAgent string `json:"apiUserAgent"`
APIProvider string `json:"apiProvider"` // OpenAI, Azure
APIVersion string `json:"apiVersion"` // Azure API version
}
func NewAI() *AI {

View file

@ -92,7 +92,7 @@ func chatGPTContinueWrite(msg string, contextMsgs []string, cloud bool) (ret str
if cloud {
gpt = &CloudGPT{}
} else {
gpt = &OpenAIGPT{c: util.NewOpenAIClient(Conf.AI.OpenAI.APIKey, Conf.AI.OpenAI.APIProxy, Conf.AI.OpenAI.APIBaseURL, Conf.AI.OpenAI.APIUserAgent)}
gpt = &OpenAIGPT{c: util.NewOpenAIClient(Conf.AI.OpenAI.APIKey, Conf.AI.OpenAI.APIProxy, Conf.AI.OpenAI.APIBaseURL, Conf.AI.OpenAI.APIUserAgent, Conf.AI.OpenAI.APIVersion, Conf.AI.OpenAI.APIProvider)}
}
buf := &bytes.Buffer{}

View file

@ -75,8 +75,13 @@ func ChatGPT(msg string, contextMsgs []string, c *openai.Client, model string, m
return
}
func NewOpenAIClient(apiKey, apiProxy, apiBaseURL, apiUserAgent string) *openai.Client {
func NewOpenAIClient(apiKey, apiProxy, apiBaseURL, apiUserAgent, apiVersion, apiProvider string) *openai.Client {
config := openai.DefaultConfig(apiKey)
if "Azure" == apiProvider {
config = openai.DefaultAzureConfig(apiKey, apiBaseURL)
config.APIVersion = apiVersion
}
transport := &http.Transport{}
if "" != apiProxy {
proxyUrl, err := url.Parse(apiProxy)