Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azure support #261

Merged
merged 2 commits into from
Apr 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions api/chat_main_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,18 +364,23 @@ func (h *ChatHandler) chatStream(w http.ResponseWriter, chatSession sqlc_queries
}

baseUrl, err := getModelBaseUrl(chatModel.Url)

if err != nil {
RespondWithError(w, http.StatusInternalServerError, eris.Wrap(err, "get base url").Error(), err)
return "", "", true
}
log.Println(baseUrl)

token := os.Getenv(chatModel.ApiAuthKey)
config := openai.DefaultConfig(token)
config.BaseURL = baseUrl
// check if azure
var config openai.ClientConfig
if os.Getenv("AZURE_RESOURCE_NAME") != "" {
config = openai.DefaultAzureConfig(token, chatModel.Url, os.Getenv("AZURE_RESOURCE_NAME"))
} else {
config = openai.DefaultConfig(token)
config.BaseURL = baseUrl
// handler proxy
configOpenAIProxy(config)
}
client := openai.NewClientWithConfig(config)
// handler proxy
configOpenAIProxy(config)

openai_req := NewChatCompletionRequest(chatSession, chat_compeletion_messages)
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
Expand Down Expand Up @@ -472,12 +477,18 @@ func (h *ChatHandler) CompletionStream(w http.ResponseWriter, chatSession sqlc_q
}

token := os.Getenv(chatModel.ApiAuthKey)
config := openai.DefaultConfig(token)
config.BaseURL = baseUrl
client := openai.NewClientWithConfig(config)
// handler proxy
configOpenAIProxy(config)

var config openai.ClientConfig

if os.Getenv("AZURE_RESOURCE_NAME") != "" {
config = openai.DefaultAzureConfig(token, chatModel.Url, os.Getenv("AZURE_RESOURCE_NAME"))
} else {
config = openai.DefaultConfig(token)
config.BaseURL = baseUrl
// handler proxy
configOpenAIProxy(config)
}
client := openai.NewClientWithConfig(config)
// latest message contents
prompt := chat_compeletion_messages[len(chat_compeletion_messages)-1].Content
N := int(chatSession.N)
Expand Down