Skip to content

Commit 5c786c2

Browse files
[azopenai] Updating API version 2024-05-01 (Azure#22967)
Also got to fix some of my recordings so our test percentages aren't abysmal
1 parent 1f9c6f1 commit 5c786c2

20 files changed

+729
-229
lines changed

eng/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
},
4747
{
4848
"Name": "azopenai",
49-
"CoverageGoal": 0.26
49+
"CoverageGoal": 0.22
5050
},
5151
{
5252
"Name": "ai/azopenaiassistants",

sdk/ai/azopenai/CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44

55
### Features Added
66

7-
- Updating to the `2024-04-01-preview` API version for Azure OpenAI. (PR#22798)
7+
- Updating to the `2024-05-01-preview` API version for Azure OpenAI. (PR#22967)
88

99
### Breaking Changes
1010

1111
- ContentFilterResultDetailsForPrompt.CustomBlocklists has been changed from a []ContentFilterBlocklistIDResult to a struct,
1212
containing the slice of []ContentFilterBlocklistIDResult.
13+
- OnYourDataEndpointVectorizationSource.Authentication's type has changed to OnYourDataVectorSearchAuthenticationOptionsClassification
14+
- Casing has been corrected for fields:
15+
- Filepath -> FilePath
16+
- FilepathField -> FilePathField
17+
- CustomBlocklists -> CustomBlockLists
1318

1419
### Bugs Fixed
1520

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_d0d55a804a"
5+
"Tag": "go/ai/azopenai_6996498620"
66
}

sdk/ai/azopenai/autorest.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,44 @@ directive:
133133
transform: return $.replace(/InternalChatCompletionsResponseFormat/g, "respType")
134134
```
135135

136+
Fix casing of some fields
137+
138+
```yaml
139+
directive:
140+
# Filepath -> FilePath
141+
- from: swagger-document
142+
where: $.definitions.AzureChatExtensionRetrievedDocument
143+
transform: $.properties.filepath["x-ms-client-name"] = "FilePath"
144+
- from: swagger-document
145+
where: $.definitions.AzureChatExtensionDataSourceResponseCitation
146+
transform: $.properties.filepath["x-ms-client-name"] = "FilePath"
147+
148+
# FilepathField -> FilePathField
149+
- from: swagger-document
150+
where: $.definitions.AzureCosmosDBFieldMappingOptions
151+
transform: $.properties.filepath_field["x-ms-client-name"] = "FilePathField"
152+
- from: swagger-document
153+
where: $.definitions.AzureSearchIndexFieldMappingOptions
154+
transform: $.properties.filepath_field["x-ms-client-name"] = "FilePathField"
155+
- from: swagger-document
156+
where: $.definitions.ElasticsearchIndexFieldMappingOptions
157+
transform: $.properties.filepath_field["x-ms-client-name"] = "FilePathField"
158+
- from: swagger-document
159+
where: $.definitions.PineconeFieldMappingOptions
160+
transform: $.properties.filepath_field["x-ms-client-name"] = "FilePathField"
161+
162+
# CustomBlocklist -> CustomBlockList
163+
- from: swagger-document
164+
where: $.definitions.ImageGenerationPromptFilterResults
165+
transform: $.properties.custom_blocklists["x-ms-client-name"] = "CustomBlockLists"
166+
- from: swagger-document
167+
where: $.definitions.ContentFilterResultDetailsForPrompt
168+
transform: $.properties.custom_blocklists["x-ms-client-name"] = "CustomBlockLists"
169+
- from: swagger-document
170+
where: $.definitions.ContentFilterResultsForChoice
171+
transform: $.properties.custom_blocklists["x-ms-client-name"] = "CustomBlockLists"
172+
```
173+
136174
## Cleanup the audio transcription APIs
137175

138176
We're wrapping the audio translation and transcription APIs, so we can eliminate some of

sdk/ai/azopenai/client.go

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/ai/azopenai/client_shared_test.go

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"mime"
1414
"net/http"
1515
"os"
16-
"regexp"
1716
"strings"
1817
"testing"
1918

@@ -76,7 +75,7 @@ func getEnvVariable(varName string, playbackValue string) string {
7675
return val
7776
}
7877

79-
var azureOpenAI, openAI, servers = func() (testVars, testVars, []string) {
78+
var azureOpenAI, openAI = func() (testVars, testVars) {
8079
servers := struct {
8180
USEast endpoint
8281
USNorthCentral endpoint
@@ -85,41 +84,32 @@ var azureOpenAI, openAI, servers = func() (testVars, testVars, []string) {
8584
OpenAI endpoint
8685
}{
8786
OpenAI: endpoint{
88-
URL: getEndpoint("OPENAI_ENDPOINT"), // ex: https://api.openai.com/v1/
87+
URL: getEndpoint("OPENAI_ENDPOINT", false), // ex: https://api.openai.com/v1/
8988
APIKey: getEnvVariable("OPENAI_API_KEY", fakeAPIKey),
9089
Azure: false,
9190
},
9291
USEast: endpoint{
93-
URL: getEndpoint("AOAI_ENDPOINT_USEAST"),
92+
URL: getEndpoint("AOAI_ENDPOINT_USEAST", true),
9493
APIKey: getEnvVariable("AOAI_ENDPOINT_USEAST_API_KEY", fakeAPIKey),
9594
Azure: true,
9695
},
9796
USEast2: endpoint{
98-
URL: getEndpoint("AOAI_ENDPOINT_USEAST2"),
97+
URL: getEndpoint("AOAI_ENDPOINT_USEAST2", true),
9998
APIKey: getEnvVariable("AOAI_ENDPOINT_USEAST2_API_KEY", fakeAPIKey),
10099
Azure: true,
101100
},
102101
USNorthCentral: endpoint{
103-
URL: getEndpoint("AOAI_ENDPOINT_USNORTHCENTRAL"),
102+
URL: getEndpoint("AOAI_ENDPOINT_USNORTHCENTRAL", true),
104103
APIKey: getEnvVariable("AOAI_ENDPOINT_USNORTHCENTRAL_API_KEY", fakeAPIKey),
105104
Azure: true,
106105
},
107106
SWECentral: endpoint{
108-
URL: getEndpoint("AOAI_ENDPOINT_SWECENTRAL"),
107+
URL: getEndpoint("AOAI_ENDPOINT_SWECENTRAL", true),
109108
APIKey: getEnvVariable("AOAI_ENDPOINT_SWECENTRAL_API_KEY", fakeAPIKey),
110109
Azure: true,
111110
},
112111
}
113112

114-
// used when we setup the recording policy
115-
endpoints := []string{
116-
servers.OpenAI.URL,
117-
servers.USEast.URL,
118-
servers.USEast2.URL,
119-
servers.USNorthCentral.URL,
120-
servers.SWECentral.URL,
121-
}
122-
123113
newTestVarsFn := func(azure bool) testVars {
124114
return testVars{
125115
ChatCompletions: endpointWithModel{
@@ -172,11 +162,9 @@ var azureOpenAI, openAI, servers = func() (testVars, testVars, []string) {
172162
},
173163
Cognitive: azopenai.AzureSearchChatExtensionConfiguration{
174164
Parameters: &azopenai.AzureSearchChatExtensionParameters{
175-
Endpoint: to.Ptr(recording.GetEnvVariable("COGNITIVE_SEARCH_API_ENDPOINT", fakeCognitiveEndpoint)),
176-
IndexName: to.Ptr(recording.GetEnvVariable("COGNITIVE_SEARCH_API_INDEX", fakeCognitiveIndexName)),
177-
Authentication: &azopenai.OnYourDataAPIKeyAuthenticationOptions{
178-
Key: to.Ptr(recording.GetEnvVariable("COGNITIVE_SEARCH_API_KEY", fakeAPIKey)),
179-
},
165+
Endpoint: to.Ptr(recording.GetEnvVariable("COGNITIVE_SEARCH_API_ENDPOINT", fakeCognitiveEndpoint)),
166+
IndexName: to.Ptr(recording.GetEnvVariable("COGNITIVE_SEARCH_API_INDEX", fakeCognitiveIndexName)),
167+
Authentication: &azopenai.OnYourDataSystemAssignedManagedIdentityAuthenticationOptions{},
180168
},
181169
},
182170
}
@@ -195,8 +183,8 @@ var azureOpenAI, openAI, servers = func() (testVars, testVars, []string) {
195183
"DALLE": azureTestVars.DallE,
196184
"EMBEDDINGS": azureTestVars.Embeddings,
197185
// these resources are oversubscribed and occasionally fail in live testing.
198-
//"VISION": azureTestVars.Vision,
199-
//"WHISPER": azureTestVars.Whisper,
186+
// "VISION": azureTestVars.Vision,
187+
// "WHISPER": azureTestVars.Whisper,
200188
}
201189

202190
for area, epm := range remaps {
@@ -206,7 +194,7 @@ var azureOpenAI, openAI, servers = func() (testVars, testVars, []string) {
206194
}
207195
}
208196

209-
return azureTestVars, newTestVarsFn(false), endpoints
197+
return azureTestVars, newTestVarsFn(false)
210198
}()
211199

212200
type testClientOption func(opt *azopenai.ClientOptions)
@@ -241,9 +229,10 @@ func newTestClient(t *testing.T, ep endpoint, options ...testClientOption) *azop
241229
}
242230
}
243231

244-
const fakeEndpoint = "https://fake-recorded-host.microsoft.com/"
232+
const fakeAzureEndpoint = "https://Sanitized.openai.azure.com/"
233+
const fakeOpenAIEndpoint = "https://Sanitized.openai.com/v1"
245234
const fakeAPIKey = "redacted"
246-
const fakeCognitiveEndpoint = "https://fake-cognitive-endpoint.microsoft.com"
235+
const fakeCognitiveEndpoint = "https://Sanitized.openai.azure.com"
247236
const fakeCognitiveIndexName = "index"
248237

249238
type MultipartRecordingPolicy struct {
@@ -266,23 +255,12 @@ func newRecordingTransporter(t *testing.T) policy.Transporter {
266255
err = recording.AddHeaderRegexSanitizer("Api-Key", fakeAPIKey, "", nil)
267256
require.NoError(t, err)
268257

269-
err = recording.AddHeaderRegexSanitizer("User-Agent", "fake-user-agent", "", nil)
258+
err = recording.AddHeaderRegexSanitizer("Uer-Agent", "fake-user-agent", "", nil)
270259
require.NoError(t, err)
271260

272-
for _, ep := range servers {
273-
err = recording.AddURISanitizer(fakeEndpoint, regexp.QuoteMeta(ep), nil)
274-
require.NoError(t, err)
275-
}
276-
277261
err = recording.AddURISanitizer("/openai/operations/images/00000000-AAAA-BBBB-CCCC-DDDDDDDDDDDD", "/openai/operations/images/[A-Za-z-0-9]+", nil)
278262
require.NoError(t, err)
279263

280-
// there's only one OpenAI endpoint
281-
if openAI.ChatCompletions.Endpoint.URL != "" {
282-
err = recording.AddURISanitizer(fakeEndpoint, regexp.QuoteMeta(openAI.ChatCompletions.Endpoint.URL), nil)
283-
require.NoError(t, err)
284-
}
285-
286264
err = recording.AddGeneralRegexSanitizer(
287265
fmt.Sprintf(`"endpoint": "%s"`, fakeCognitiveEndpoint),
288266
fmt.Sprintf(`"endpoint":\s*"%s"`, *azureOpenAI.Cognitive.Parameters.Endpoint), nil)
@@ -292,11 +270,6 @@ func newRecordingTransporter(t *testing.T) policy.Transporter {
292270
fmt.Sprintf(`"index_name": "%s"`, fakeCognitiveIndexName),
293271
fmt.Sprintf(`"index_name":\s*"%s"`, *azureOpenAI.Cognitive.Parameters.IndexName), nil)
294272
require.NoError(t, err)
295-
296-
err = recording.AddGeneralRegexSanitizer(
297-
fmt.Sprintf(`"key": "%s"`, fakeAPIKey),
298-
fmt.Sprintf(`"key":\s*"%s"`, *azureOpenAI.Cognitive.Parameters.Authentication.(*azopenai.OnYourDataAPIKeyAuthenticationOptions).Key), nil)
299-
require.NoError(t, err)
300273
}
301274

302275
t.Cleanup(func() {
@@ -377,11 +350,17 @@ func assertResponseIsError(t *testing.T, err error) {
377350
require.Truef(t, respErr.StatusCode == http.StatusUnauthorized || respErr.StatusCode == http.StatusTooManyRequests, "An acceptable error comes back (actual: %d)", respErr.StatusCode)
378351
}
379352

380-
func getEndpoint(ev string) string {
381-
v := getEnvVariable(ev, fakeEndpoint)
353+
func getEndpoint(ev string, azure bool) string {
354+
fakeEP := fakeAzureEndpoint
355+
356+
if !azure {
357+
fakeEP = fakeOpenAIEndpoint
358+
}
359+
360+
v := getEnvVariable(ev, fakeEP)
382361

383362
if !strings.HasSuffix(v, "/") {
384-
// (this just makes recording replacement easier)
363+
// (this just makes recording replacement easier)j
385364
v += "/"
386365
}
387366

0 commit comments

Comments
 (0)