Closed MrHuangjiacong closed 4 hours ago
just like this https://github.com/sashabaranov/go-openai
This third-party library can easily use Azure's OpenAI
package main import ( "context" "fmt" openai "github.com/sashabaranov/go-openai" ) func main() { config := openai.DefaultAzureConfig("your Azure OpenAI Key", "https://your Azure OpenAI Endpoint") // If you use a deployment name different from the model name, you can customize the AzureModelMapperFunc function config.AzureModelMapperFunc = func(model string) string { azureModelMapping := map[string]string{ "gpt-3.5-turbo": "your gpt-3.5-turbo deployment name", } return azureModelMapping[model] } client := openai.NewClientWithConfig(config) resp, err := client.CreateChatCompletion( context.Background(), openai.ChatCompletionRequest{ Model: openai.GPT3Dot5Turbo, Messages: []openai.ChatCompletionMessage{ { Role: openai.ChatMessageRoleUser, Content: "Hello Azure OpenAI!", }, }, }, ) if err != nil { fmt.Printf("ChatCompletion error: %v\n", err) return } fmt.Println(resp.Choices[0].Message.Content) }
We have builtin support for Azure, see this section of the README.
just like this https://github.com/sashabaranov/go-openai
This third-party library can easily use Azure's OpenAI