Skip to content

Commit ab7f6f4

Browse files
[azopenai] Updating to use openai-go/v3. (#25567)
Not too many breaking changes from the Stainless/openai-go side: mostly things just shuffled around a bit with function types, and specifying tools. Part of the work for #25558
1 parent dd4ab94 commit ab7f6f4

33 files changed

+317
-208
lines changed

sdk/ai/azopenai/CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
# Release History
22

3-
## 1.0.0-beta.1 (TBD)
3+
## 0.9.0 (TBD)
4+
5+
### Features Added
6+
7+
- Updating to /v3 of the OpenAI SDK (github.com/openai/openai-go/v3).
48

59
### Other Changes
10+
611
- Added examples demonstrating support for Managed Identity
7-
- Added examples demonstrating support for deepseek-r1 reasoning.
12+
- Added examples demonstrating support for deepseek-r1 reasoning.
813

914
## 0.8.0 (2025-06-03)
1015

sdk/ai/azopenai/MIGRATION.md

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Migration Guide from Azure OpenAI SDK v0.7.x to v0.8.0+
22

33
## Table of Contents
4+
45
- [Overview](#overview)
56
- [Summary of Major Changes](#summary-of-major-changes)
67
- [Key Changes](#key-changes)
@@ -20,13 +21,13 @@ The `azopenai.Client` provided by this package has been retired in favor of the
2021
2122
## Summary of Major Changes
2223

23-
| Area | v0.7.x Approach | v0.8.0+ Approach (Recommended) |
24-
|---------------------|--------------------------------|----------------------------------------|
25-
| Client | `azopenai.Client` | `openai.Client` |
26-
| Assistants | `azopenaiassistants` | **No longer available** |
27-
| Azure Extensions | Built-in | Use `azopenai` as a companion |
28-
| API Structure | Flat methods | Subclients per service category |
29-
| Authentication | Azure-specific | Use `azure.With...` options |
24+
| Area | v0.7.x Approach | v0.8.0+ Approach (Recommended) |
25+
| ---------------- | -------------------- | ------------------------------- |
26+
| Client | `azopenai.Client` | `openai.Client` |
27+
| Assistants | `azopenaiassistants` | **No longer available** |
28+
| Azure Extensions | Built-in | Use `azopenai` as a companion |
29+
| API Structure | Flat methods | Subclients per service category |
30+
| Authentication | Azure-specific | Use `azure.With...` options |
3031

3132
> [!IMPORTANT]
3233
> The Assistants API is no longer available in the `openai-go` package. If you require Assistants functionality, please refer to the [OpenAI API documentation](https://platform.openai.com/docs/api-reference/assistants) for alternative approaches or use the HTTP API directly.
@@ -39,31 +40,32 @@ Your projects must now include the official OpenAI Go client:
3940

4041
```go
4142
import (
42-
"github.com/openai/openai-go"
43+
"github.com/openai/openai-go/v3"
4344
)
4445
```
4546

4647
If you need Azure-specific extensions (for instance, Azure OpenAI On Your Data or content filtering), also include the `azopenai` package:
4748

4849
```go
4950
import (
50-
"github.com/openai/openai-go"
51+
"github.com/openai/openai-go/v3"
5152
"github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai"
5253
)
5354
```
5455

55-
> [!NOTE]
56-
> **Azure extensions** refer to features unique to the Azure OpenAI Service (e.g., Azure OpenAI On Your Data, or content filtering). Authentication for Azure resources is available in the `openai-go` package, and does not require this package.
56+
> [!NOTE] > **Azure extensions** refer to features unique to the Azure OpenAI Service (e.g., Azure OpenAI On Your Data, or content filtering). Authentication for Azure resources is available in the `openai-go` package, and does not require this package.
5757
5858
## Authentication and Client Creation
5959

6060
Instead of using the Azure OpenAI client directly for all operations, you'll now:
61+
6162
- Create an OpenAI client configured for the Azure OpenAI Service.
6263
- Use the Azure OpenAI companion library for Azure-specific extensions.
6364

6465
### Azure OpenAI with API Key
6566

6667
**Before:**
68+
6769
```go
6870
endpoint := os.Getenv("AZURE_OPENAI_ENDPOINT")
6971
key := os.Getenv("AZURE_OPENAI_API_KEY")
@@ -74,6 +76,7 @@ if err != nil {
7476
```
7577

7678
**After:**
79+
7780
```go
7881
endpoint := os.Getenv("AZURE_OPENAI_ENDPOINT")
7982
// Information on Azure OpenAI API versions can be found here: https://aka.ms/oai/docs/api-lifecycle
@@ -89,6 +92,7 @@ client := openai.NewClient(
8992
### Azure OpenAI with Token Credentials
9093

9194
**Before:**
95+
9296
```go
9397
endpoint := os.Getenv("AZURE_OPENAI_ENDPOINT")
9498

@@ -103,6 +107,7 @@ if err != nil {
103107
```
104108

105109
**After:**
110+
106111
```go
107112
endpoint := os.Getenv("AZURE_OPENAI_ENDPOINT")
108113
// Information on Azure OpenAI API versions can be found here: https://aka.ms/oai/docs/api-lifecycle
@@ -121,6 +126,7 @@ client := openai.NewClient(
121126
### OpenAI v1 (not using Azure OpenAI Service)
122127

123128
**Before:**
129+
124130
```go
125131
key := os.Getenv("OPENAI_API_KEY")
126132

@@ -131,6 +137,7 @@ if err != nil {
131137
```
132138

133139
**After:**
140+
134141
```go
135142
key := os.Getenv("OPENAI_API_KEY")
136143
client := openai.NewClient(
@@ -142,26 +149,25 @@ client := openai.NewClient(
142149

143150
The official OpenAI Go client organizes operations into subclients for each service category, rather than providing all operations on a single client.
144151

145-
| Service | Description |
146-
|-----------------------|-------------|
147-
| `client.Completions` | [Completions API](https://platform.openai.com/docs/api-reference/completions) |
148-
| `client.Chat` | [Chat Completions API](https://platform.openai.com/docs/api-reference/chat) |
149-
| `client.Embeddings` | [Embeddings API](https://platform.openai.com/docs/api-reference/embeddings) |
150-
| `client.Files` | [Files API](https://platform.openai.com/docs/api-reference/files) |
151-
| `client.Images` | [Images API](https://platform.openai.com/docs/api-reference/images) |
152-
| `client.Audio` | [Audio API](https://platform.openai.com/docs/api-reference/audio) |
153-
| `client.Moderations` | [Moderations API](https://platform.openai.com/docs/api-reference/moderations) |
154-
| `client.Models` | [Models API](https://platform.openai.com/docs/api-reference/models) |
155-
| `client.FineTuning` | [Fine-tuning API](https://platform.openai.com/docs/api-reference/fine-tuning) |
152+
| Service | Description |
153+
| --------------------- | --------------------------------------------------------------------------------- |
154+
| `client.Completions` | [Completions API](https://platform.openai.com/docs/api-reference/completions) |
155+
| `client.Chat` | [Chat Completions API](https://platform.openai.com/docs/api-reference/chat) |
156+
| `client.Embeddings` | [Embeddings API](https://platform.openai.com/docs/api-reference/embeddings) |
157+
| `client.Files` | [Files API](https://platform.openai.com/docs/api-reference/files) |
158+
| `client.Images` | [Images API](https://platform.openai.com/docs/api-reference/images) |
159+
| `client.Audio` | [Audio API](https://platform.openai.com/docs/api-reference/audio) |
160+
| `client.Moderations` | [Moderations API](https://platform.openai.com/docs/api-reference/moderations) |
161+
| `client.Models` | [Models API](https://platform.openai.com/docs/api-reference/models) |
162+
| `client.FineTuning` | [Fine-tuning API](https://platform.openai.com/docs/api-reference/fine-tuning) |
156163
| `client.VectorStores` | [Vector Stores API](https://platform.openai.com/docs/api-reference/vector-stores) |
157-
| `client.Batches` | [Batch API](https://platform.openai.com/docs/api-reference/batch) |
158-
| `client.Uploads` | [Uploads API](https://platform.openai.com/docs/api-reference/uploads) |
159-
| `client.Responses` | [Responses API](https://platform.openai.com/docs/api-reference/responses) |
164+
| `client.Batches` | [Batch API](https://platform.openai.com/docs/api-reference/batch) |
165+
| `client.Uploads` | [Uploads API](https://platform.openai.com/docs/api-reference/uploads) |
166+
| `client.Responses` | [Responses API](https://platform.openai.com/docs/api-reference/responses) |
160167

161168
Refer to the [official OpenAI Go client documentation](https://github.com/openai/openai-go) for details.
162169

163-
> [!NOTE]
164-
> **Assistants API:** As of v1.0.0, the Assistants API is not supported in the `openai-go` package. There is currently no official Go SDK support for Assistants. You may need to use direct HTTP requests for this functionality.
170+
> [!NOTE] > **Assistants API:** As of v1.0.0, the Assistants API is not supported in the `openai-go` package. There is currently no official Go SDK support for Assistants. You may need to use direct HTTP requests for this functionality.
165171
166172
For Azure-specific extensions, see the reference documentation and examples in this companion library.
167173

@@ -170,6 +176,7 @@ For Azure-specific extensions, see the reference documentation and examples in t
170176
### Chat Completions
171177

172178
**Before:**
179+
173180
```go
174181
resp, err := client.GetChatCompletions(context.TODO(), azopenai.ChatCompletionsOptions{
175182
// DeploymentName: "gpt-4o", // This only applies for the OpenAI service.
@@ -189,6 +196,7 @@ for _, choice := range resp.Choices {
189196
```
190197

191198
**After:**
199+
192200
```go
193201
deployment := os.Getenv("AZURE_OPENAI_DEPLOYMENT_NAME")
194202
resp, err := client.Chat.Completions.New(context.TODO(), openai.ChatCompletionNewParams{
@@ -218,6 +226,7 @@ for _, choice := range resp.Choices {
218226
#### Streaming Chat Completions
219227

220228
**Before:**
229+
221230
```go
222231
resp, err := client.GetChatCompletionsStream(context.TODO(), azopenai.ChatCompletionsStreamOptions{
223232
// DeploymentName: "gpt-4o", // This only applies for the OpenAI service.
@@ -251,6 +260,7 @@ for {
251260
```
252261

253262
**After:**
263+
254264
```go
255265
deployment := os.Getenv("AZURE_OPENAI_DEPLOYMENT_NAME")
256266
stream := client.Chat.Completions.NewStreaming(context.TODO(), openai.ChatCompletionNewParams{
@@ -280,6 +290,7 @@ for stream.Next() {
280290
### Chat Completions (On Your Data)
281291

282292
**Before:**
293+
283294
```go
284295
resp, err := client.GetChatCompletions(context.TODO(), azopenai.ChatCompletionsOptions{
285296
Messages: []azopenai.ChatRequestMessageClassification{
@@ -314,6 +325,7 @@ for _, choice := range resp.Choices {
314325
```
315326

316327
**After:**
328+
317329
```go
318330
// Create Azure Search data source configuration
319331
azureSearchDataSource := &azopenai.AzureSearchChatExtensionConfiguration{
@@ -360,6 +372,7 @@ for _, choice := range resp.Choices {
360372
### Embeddings
361373

362374
**Before:**
375+
363376
```go
364377
resp, err := client.GetEmbeddings(context.TODO(), azopenai.EmbeddingsOptions{
365378
// DeploymentName: to.Ptr("text-embedding-3-large"), // This only applies for the OpenAI service.
@@ -375,6 +388,7 @@ for _, embedding := range resp.Data {
375388
```
376389

377390
**After:**
391+
378392
```go
379393
resp, err := client.Embeddings.New(context.TODO(), openai.EmbeddingNewParams{
380394
Model: openai.EmbeddingModel("my-deployment"), // Azure deployment name here
@@ -397,6 +411,7 @@ for _, embedding := range resp.Data {
397411
### Legacy Completions
398412

399413
**Before:**
414+
400415
```go
401416
resp, err := client.GetCompletions(context.TODO(), azopenai.CompletionsOptions{
402417
Prompt: []string{"What is Azure OpenAI, in 20 words or less"},
@@ -416,6 +431,7 @@ for _, choice := range resp.Choices {
416431
```
417432

418433
**After:**
434+
419435
```go
420436
resp, err := client.Completions.New(context.TODO(), openai.CompletionNewParams{
421437
Model: openai.CompletionNewParamsModel(model), // Azure deployment name here
@@ -440,6 +456,7 @@ for _, choice := range resp.Choices {
440456
#### Transcription
441457

442458
**Before:**
459+
443460
```go
444461
mp3Bytes, err := os.ReadFile("audio.mp3")
445462
if err != nil {
@@ -462,6 +479,7 @@ if err != nil {
462479
```
463480

464481
**After:**
482+
465483
```go
466484
audio_file, err := os.Open("audio.mp3")
467485
if err != nil {
@@ -484,6 +502,7 @@ if err != nil {
484502
#### Text to speech
485503

486504
**Before:**
505+
487506
```go
488507
audioResp, err := client.GenerateSpeechFromText(context.Background(), azopenai.SpeechGenerationOptions{
489508
Input: to.Ptr("i am a computer"),
@@ -508,6 +527,7 @@ if err != nil {
508527
```
509528

510529
**After:**
530+
511531
```go
512532
audioResp, err := client.Audio.Speech.New(context.Background(), openai.AudioSpeechNewParams{
513533
Model: openai.SpeechModel(model),
@@ -535,6 +555,7 @@ if err != nil {
535555
#### Translation
536556

537557
**Before:**
558+
538559
```go
539560
resp, err := client.GetAudioTranslation(context.TODO(), azopenai.AudioTranslationOptions{
540561
File: mp3Bytes,
@@ -550,6 +571,7 @@ if err != nil {
550571
```
551572

552573
**After:**
574+
553575
```go
554576
resp, err := client.Audio.Translations.New(context.TODO(), openai.AudioTranslationNewParams{
555577
Model: openai.AudioModel(model),
@@ -567,6 +589,7 @@ if err != nil {
567589
### Image
568590

569591
**Before:**
592+
570593
```go
571594
resp, err := client.GetImageGenerations(context.TODO(), azopenai.ImageGenerationOptions{
572595
Prompt: to.Ptr("a cat"),
@@ -602,6 +625,7 @@ for _, generatedImage := range resp.Data {
602625
```
603626

604627
**After:**
628+
605629
```go
606630
resp, err := client.Images.Generate(context.TODO(), openai.ImageGenerateParams{
607631
Prompt: "a cat",
@@ -640,6 +664,7 @@ for _, generatedImage := range resp.Data {
640664
### Vision
641665

642666
**Before:**
667+
643668
```go
644669
imageURL := "https://www.bing.com/th?id=OHR.BradgateFallow_EN-US3932725763_1920x1080.jpg"
645670

@@ -679,6 +704,7 @@ for _, choice := range resp.Choices {
679704
```
680705

681706
**After:**
707+
682708
```go
683709
imageURL := "https://www.bing.com/th?id=OHR.BradgateFallow_EN-US3932725763_1920x1080.jpg"
684710

sdk/ai/azopenai/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Azure OpenAI extensions module for Go
22

3-
This module provides models and convenience functions to make it simpler to use Azure OpenAI features, such as [Azure OpenAI On Your Data][openai_on_your_data], with the OpenAI Go client (https://pkg.go.dev/github.com/openai/openai-go).
3+
This module provides models and convenience functions to make it simpler to use Azure OpenAI features, such as [Azure OpenAI On Your Data][openai_on_your_data], with the OpenAI Go client (https://pkg.go.dev/github.com/openai/openai-go/v3).
44

55
[Source code][repo] | [Package (pkg.go.dev)][pkggodev] | [REST API documentation][openai_rest_docs] | [Product documentation][openai_docs]
66

77
## Getting started
88

99
### Prerequisites
1010

11-
* Go, version 1.23 or higher - [Install Go](https://go.dev/doc/install)
12-
* [Azure subscription][azure_sub]
13-
* [Azure OpenAI access][azure_openai_access]
11+
- Go, version 1.23 or higher - [Install Go](https://go.dev/doc/install)
12+
- [Azure subscription][azure_sub]
13+
- [Azure OpenAI access][azure_openai_access]
1414

1515
### Install the packages
1616

@@ -31,7 +31,7 @@ See [Key concepts][openai_key_concepts] in the product documentation for more de
3131

3232
# Examples
3333

34-
Examples for scenarios specific to Azure can be found on [pkg.go.dev](https://aka.ms/azsdk/go/azopenaiextensions/pkg#pkg-examples) or in the example*_test.go files in our GitHub repo for [azopenai](https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/ai/azopenai).
34+
Examples for scenarios specific to Azure can be found on [pkg.go.dev](https://aka.ms/azsdk/go/azopenaiextensions/pkg#pkg-examples) or in the example\*\_test.go files in our GitHub repo for [azopenai](https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/ai/azopenai).
3535

3636
For examples on using the openai-go client, see the examples in the [openai-go](https://github.com/openai/openai-go/tree/main/examples) repository.
3737

@@ -48,6 +48,7 @@ the [Code of Conduct FAQ][coc_faq] or contact [[email protected]][coc_conta
4848
comments.
4949

5050
<!-- LINKS -->
51+
5152
[azure_identity]: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity
5253
[azure_openai_access]: https://learn.microsoft.com/azure/cognitive-services/openai/overview#how-do-i-get-access-to-azure-openai
5354
[azure_openai_quickstart]: https://learn.microsoft.com/azure/cognitive-services/openai/quickstart

sdk/ai/azopenai/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "go",
44
"TagPrefix": "go/ai/azopenai",
5-
"Tag": "go/ai/azopenai_ebc6f204e2"
5+
"Tag": "go/ai/azopenai_998c56e4bc"
66
}

0 commit comments

Comments
 (0)