Skip to content

Commit

Permalink
修复 Azure OpenAI 接口无法使用问题
Browse files Browse the repository at this point in the history
  • Loading branch information
mylxsw committed Oct 20, 2023
1 parent 9f35d19 commit baaf2a7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/ai/openai/openai_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestPromptFunctionRequest(t *testing.T) {

resp, err := client.CreateChatCompletion(context.TODO(), openailib.ChatCompletionRequest{
MaxTokens: 500,
Model: "gpt-3.5-turbo-0613",
Model: "gpt-3.5-turbo",
Messages: []openailib.ChatCompletionMessage{
{Role: "system", Content: prompt},
{Role: "user", Content: "奔跑的蜗牛"},
Expand Down
12 changes: 12 additions & 0 deletions internal/ai/openai/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ func createOpenAIClient(isAzure bool, apiVersion string, server, organization, k
openaiConf.APIType = openai.APITypeAzure
openaiConf.APIVersion = apiVersion
openaiConf.AzureModelMapperFunc = func(model string) string {
// TODO 应该使用配置文件配置,注意,这里返回的应该是 Azure 部署名称
switch model {
case "gpt-3.5-turbo", "gpt-3.5-turbo-0613":
return "gpt35-turbo"
case "gpt-3.5-turbo-16k", "gpt-3.5-turbo-16k-0613":
return "gpt35-turbo-16k"
case "gpt-4", "gpt-4-0613":
return "gpt4"
case "gpt-4-32k", "gpt-4-32k-0613":
return "gpt4-32k"
}

return regexp.MustCompile(`[.:]`).ReplaceAllString(model, "")
}
}
Expand Down

0 comments on commit baaf2a7

Please sign in to comment.