mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
feat(openai): support azure api type #475
This commit is contained in:
parent
835349c33f
commit
ad97f973ab
23 changed files with 4726 additions and 3837 deletions
33
internal/chatbot/client.go
Normal file
33
internal/chatbot/client.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package chatbot
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/internal/transport"
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"github.com/sashabaranov/go-openai"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetClient() (*openai.Client, error) {
|
||||
var config openai.ClientConfig
|
||||
if openai.APIType(settings.OpenAISettings.APIType) == openai.APITypeAzure {
|
||||
config = openai.DefaultAzureConfig(settings.OpenAISettings.Token, settings.OpenAISettings.BaseUrl)
|
||||
} else {
|
||||
config = openai.DefaultConfig(settings.OpenAISettings.Token)
|
||||
}
|
||||
|
||||
if settings.OpenAISettings.Proxy != "" {
|
||||
t, err := transport.NewTransport(transport.WithProxy(settings.OpenAISettings.Proxy))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.HTTPClient = &http.Client{
|
||||
Transport: t,
|
||||
}
|
||||
}
|
||||
|
||||
if settings.OpenAISettings.BaseUrl != "" {
|
||||
config.BaseURL = settings.OpenAISettings.BaseUrl
|
||||
}
|
||||
|
||||
return openai.NewClientWithConfig(config), nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue