Update README.md with Azure OpenAI ChatGPT example (#239)

Co-authored-by: coggsflod <richard.coggins@officedepot.com>
This commit is contained in:
Rich Coggins
2023-04-08 14:42:55 -04:00
committed by GitHub
parent 33ca1dac95
commit 334ee6dbdd

View File

@@ -381,3 +381,43 @@ func main() {
}
```
</details>
<details>
<summary>Azure OpenAI ChatGPT</summary>
```go
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 ", "your Model deployment name")
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)
}
```
</details>