Skip to content

Commit 334ee6d

Browse files
coggsflcoggsflod
andauthored
Update README.md with Azure OpenAI ChatGPT example (#239)
Co-authored-by: coggsflod <[email protected]>
1 parent 33ca1da commit 334ee6d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,43 @@ func main() {
381381
}
382382
```
383383
</details>
384+
385+
<details>
386+
<summary>Azure OpenAI ChatGPT</summary>
387+
388+
```go
389+
package main
390+
391+
import (
392+
"context"
393+
"fmt"
394+
395+
openai "github.com/sashabaranov/go-openai"
396+
)
397+
398+
func main() {
399+
400+
config := openai.DefaultAzureConfig("your Azure OpenAI Key", "https://your Azure OpenAI Endpoint ", "your Model deployment name")
401+
client := openai.NewClientWithConfig(config)
402+
resp, err := client.CreateChatCompletion(
403+
context.Background(),
404+
openai.ChatCompletionRequest{
405+
Model: openai.GPT3Dot5Turbo,
406+
Messages: []openai.ChatCompletionMessage{
407+
{
408+
Role: openai.ChatMessageRoleUser,
409+
Content: "Hello Azure OpenAI!",
410+
},
411+
},
412+
},
413+
)
414+
415+
if err != nil {
416+
fmt.Printf("ChatCompletion error: %v\n", err)
417+
return
418+
}
419+
420+
fmt.Println(resp.Choices[0].Message.Content)
421+
}
422+
```
423+
</details>

0 commit comments

Comments
 (0)