Skip to content

Commit

Permalink
[azopenai] Updating for the 2024-02-15-preview (#22447)
Browse files Browse the repository at this point in the history
Generating based off the latest preview surface (2024-02-15).

TTS is the big feature for this revision and there have been some minor renames for some of the BYOD options.

Fixes #22444
  • Loading branch information
richardpark-msft authored Mar 5, 2024
1 parent 986b63c commit 465e3a2
Show file tree
Hide file tree
Showing 36 changed files with 2,309 additions and 1,199 deletions.
2 changes: 1 addition & 1 deletion eng/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},
{
"Name": "azopenai",
"CoverageGoal": 0.32
"CoverageGoal": 0.28
},
{
"Name": "aztemplate",
Expand Down
3 changes: 3 additions & 0 deletions sdk/ai/azopenai/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# generated apiview output
azopenai.json

13 changes: 13 additions & 0 deletions sdk/ai/azopenai/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Release History

## 0.5.0 (2024-03-05)

### Features Added

- Updating to the `2024-02-15-preview` API version.
- `GetAudioSpeech` enables translating text to speech.

### Breaking Changes

- Citations, previously returned as an unparsed JSON blob, are now deserialized into a real type in `ChatResponseMessage.Citations`.
- `AzureCognitiveSearchChatExtensionConfiguration` has been renamed to `AzureSearchChatExtensionConfiguration`.
- `AzureCognitiveSearchChatExtensionParameters` has been renamed to `AzureSearchChatExtensionParameters`.

## 0.4.1 (2024-01-16)

### Bugs Fixed
Expand Down
5 changes: 4 additions & 1 deletion sdk/ai/azopenai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

NOTE: this client can be used with Azure OpenAI and OpenAI.

Azure OpenAI Service provides access to OpenAI's powerful language models including the GPT-4, GPT-35-Turbo, and Embeddings model series, as well as image generation using DALL-E.
Azure OpenAI Service provides access to OpenAI's features:
- Language models including the GPT-4, GPT-35-Turbo, and Embeddings model series.
- Image generation using DALL-E.
- Speech transcription and speech generation.

[Source code][azopenai_repo] | [Package (pkg.go.dev)][azopenai_pkg_go] | [REST API documentation][openai_rest_docs] | [Product documentation][openai_docs]

Expand Down
2 changes: 1 addition & 1 deletion sdk/ai/azopenai/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "go",
"TagPrefix": "go/ai/azopenai",
"Tag": "go/ai/azopenai_85a01b7ac6"
"Tag": "go/ai/azopenai_05b058e350"
}
153 changes: 81 additions & 72 deletions sdk/ai/azopenai/autorest.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ These settings apply only when `--go` is specified on the command line.

``` yaml
input-file:
- https://github.com/Azure/azure-rest-api-specs/blob/3e0e2a93ddb3c9c44ff1baf4952baa24ca98e9db/specification/cognitiveservices/data-plane/AzureOpenAI/inference/preview/2023-12-01-preview/generated.json
# this file is generated using the ./testdata/genopenapi.ps1 file.
- ./testdata/generated/openapi.json
output-folder: ../azopenai
clear-output-folder: false
module: github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai
license-header: MICROSOFT_MIT_NO_VERSION
openapi-type: data-plane
go: true
use: "@autorest/go@4.0.0-preview.52"
use: "@autorest/go@4.0.0-preview.63"
title: "OpenAI"
slice-elements-byval: true
# can't use this since it removes an innererror type that we want ()
Expand Down Expand Up @@ -40,14 +41,25 @@ directive:
```yaml
directive:
- from: swagger-document
where: $.definitions
where: $.definitions.GenerateSpeechFromTextOptions.properties
transform: |
$["model"] = {
"type": "string",
"description": "The model to use for this request."
}
return $;
- from:
- models.go
- models_serde.go
- options.go
- client.go
where: $
transform: |
$["AudioTranscriptionOptions"].properties["model"]["x-ms-client-name"] = "DeploymentName";
$["AudioTranslationOptions"].properties["model"]["x-ms-client-name"] = "DeploymentName";
$["ChatCompletionsOptions"].properties["model"]["x-ms-client-name"] = "DeploymentName";
$["CompletionsOptions"].properties["model"]["x-ms-client-name"] = "DeploymentName";
$["EmbeddingsOptions"].properties["model"]["x-ms-client-name"] = "DeploymentName";
$["ImageGenerationOptions"].properties["model"]["x-ms-client-name"] = "DeploymentName";
return $.replace(/Model \*string/g, 'DeploymentName *string')
.replace(/populate\(objectMap, "model", (.)\.Model\)/g, 'populate(objectMap, "model", $1.DeploymentName)')
.replace(/err = unpopulate\(val, "Model", &(.)\.Model\)/g, 'err = unpopulate(val, "Model", &$1.DeploymentName)')
.replace(/Model:/g, "DeploymentName: ");
```

## Polymorphic adjustments
Expand Down Expand Up @@ -111,21 +123,6 @@ directive:
transform: return $.replace(/InternalChatCompletionsResponseFormat/g, "respType")
```

## Model -> DeploymentName

```yaml
directive:
- from: swagger-document
where: $.definitions
transform: |
$["AudioTranscriptionOptions"].properties["model"]["x-ms-client-name"] = "DeploymentName";
$["AudioTranslationOptions"].properties["model"]["x-ms-client-name"] = "DeploymentName";
$["ChatCompletionsOptions"].properties["model"]["x-ms-client-name"] = "DeploymentName";
$["CompletionsOptions"].properties["model"]["x-ms-client-name"] = "DeploymentName";
$["EmbeddingsOptions"].properties["model"]["x-ms-client-name"] = "DeploymentName";
$["ImageGenerationOptions"].properties["model"]["x-ms-client-name"] = "DeploymentName";
```

## Cleanup the audio transcription APIs

We're wrapping the audio translation and transcription APIs, so we can eliminate some of
Expand All @@ -139,21 +136,52 @@ directive:
- models_serde.go
where: $
transform: |
return $
.replace(/type XMSPathsHksgfdDeploymentsDeploymentidAudioTranscriptionsOverloadGetaudiotranscriptionasresponseobjectPostRequestbodyContentMultipartFormDataSchema struct.+?\n}/s, "")
.replace(/\/\/ MarshalJSON implements the json.Marshaller interface for type XMSPathsHksgfdDeploymentsDeploymentidAudioTranscriptionsOverloadGetaudiotranscriptionasresponseobjectPostRequestbodyContentMultipartFormDataSchema.+?\n}/s, "")
.replace(/\/\/ UnmarshalJSON implements the json.Unmarshaller interface for type XMSPathsHksgfdDeploymentsDeploymentidAudioTranscriptionsOverloadGetaudiotranscriptionasresponseobjectPostRequestbodyContentMultipartFormDataSchema.+?\n}/s, "")
.replace(/type XMSPaths1Ak7Ov3DeploymentsDeploymentidAudioTranslationsOverloadGetaudiotranslationasresponseobjectPostRequestbodyContentMultipartFormDataSchema struct.+?\n}/s, "")
.replace(/\/\/ MarshalJSON implements the json.Marshaller interface for type XMSPaths1Ak7Ov3DeploymentsDeploymentidAudioTranslationsOverloadGetaudiotranslationasresponseobjectPostRequestbodyContentMultipartFormDataSchema.+?\n}/s, "")
.replace(/\/\/ UnmarshalJSON implements the json.Unmarshaller interface for type XMSPaths1Ak7Ov3DeploymentsDeploymentidAudioTranslationsOverloadGetaudiotranslationasresponseobjectPostRequestbodyContentMultipartFormDataSchema.+?\n}/s, "");
const typesToRemove = [
'XMSPathsHksgfdDeploymentsDeploymentidAudioTranscriptionsOverloadGetaudiotranscriptionasresponseobjectPostRequestbodyContentMultipartFormDataSchema',
'XMSPaths1Ak7Ov3DeploymentsDeploymentidAudioTranslationsOverloadGetaudiotranslationasresponseobjectPostRequestbodyContentMultipartFormDataSchema',
'Paths1G1Yr9HDeploymentsDeploymentidAudioTranslationsPostRequestbodyContentMultipartFormDataSchema',
'Paths1MlipaDeploymentsDeploymentidAudioTranscriptionsPostRequestbodyContentMultipartFormDataSchema'
];
for (let name of typesToRemove) {
$ = $.replace(new RegExp(`type ${name} struct.+?\n}`, "s"), "")
.replace(new RegExp(`// MarshalJSON implements the json.Marshaller interface for type ${name}.+?\n}`, "s"), "")
.replace(new RegExp(`// UnmarshalJSON implements the json.Unmarshaller interface for type ${name}.+?\n}`, "s"), "");
}
return $;
# kill API functions
- from:
- client.go
where: $
transform: |
return $.replace(/\/\/ GetAudioTranscriptionAsPlainText -.+?\n\}\n/s, "")
.replace(/\/\/ GetAudioTranslationAsPlainText -.+?\n\}\n/s, "")
.replace(/\/\/ getAudioTranscriptionAsPlainTextCreateRequest.+?\n}\n/s, "")
.replace(/\/\/ getAudioTranscriptionAsPlainTextHandleResponse.+?\n}\n/s, "")
.replace(/\/\/ getAudioTranslationAsPlainTextCreateRequest.+?\n}\n/s, "")
.replace(/\/\/ getAudioTranslationAsPlainTextHandleResponse.+?\n}\n/s, "");
# remove other plain text models/options
- from:
- options.go
where: $
transform: |
return $.replace(/\/\/ ClientGetAudioTranslationAsPlainTextOptions .+?\n\}\n/s, "")
.replace(/\/\/ ClientGetAudioTranscriptionAsPlainTextOptions .+?\n\}\n/s, "");
# remove other plain text models/options
- from:
- responses.go
where: $
transform: |
return $.replace(/\/\/ ClientGetAudioTranscriptionAsPlainTextResponse .+?\n\}\n/s, "")
.replace(/\/\/ ClientGetAudioTranslationAsPlainTextResponse .+?\n\}\n/s, "");
# fix any calls that don't use 'deploymentID'
- from: client.go
where: $
transform: |
return $
.replace(/\/\/ GetAudioTranscriptionAsPlainText -.+?\n}/s, "")
.replace(/\/\/ GetAudioTransclationAsPlainText -.+?\n}/s, "");
.replace(/, deploymentID string,/g, ",")
.replace(/ctx, deploymentID, /g, "ctx, ")
```
## Move the Azure extensions into their own section of the options
Expand All @@ -168,7 +196,7 @@ We've moved these 'extension' data types into their own field.
```yaml
directive:
- from: swagger-document
where: $.definitions.ChatCompletionsOptions.properties.dataSources
where: $.definitions.ChatCompletionsOptions.properties.data_sources
transform: $["x-ms-client-name"] = "AzureExtensionsOptions"
```
Expand Down Expand Up @@ -266,7 +294,7 @@ directive:
- client.go
- models.go
- models_serde.go
- response_types.go
- responses.go
- options.go
where: $
transform: |
Expand Down Expand Up @@ -314,7 +342,7 @@ directive:
- models.go
- models_serde.go
- options.go
- response_types.go
- responses.go
where: $
transform: return $.replace(/Logprobs/g, "LogProbs")
```
Expand Down Expand Up @@ -386,18 +414,18 @@ directive:
- client.go
- models.go
- options.go
- response_types.go
- responses.go
where: $
transform: return $.replace(/Client(\w+)((?:Options|Response))/g, "$1$2");

# Make the Azure extensions internal - we expose these through the GetChatCompletions*() functions
# and just treat which endpoint we use as an implementation detail.
- from: client.go
where: $
transform: |
return $
.replace(/GetChatCompletionsWithAzureExtensions([ (])/g, "getChatCompletionsWithAzureExtensions$1")
.replace(/GetChatCompletions([ (])/g, "getChatCompletions$1");
# - from: client.go
# where: $
# transform: |
# return $
# .replace(/GetChatCompletionsWithAzureExtensions([ (])/g, "getChatCompletionsWithAzureExtensions$1")
# .replace(/GetChatCompletions([ (])/g, "getChatCompletions$1");
```

## Workarounds
Expand Down Expand Up @@ -556,35 +584,6 @@ directive:
`}\n`);
```

Add in the older style of function call as that's still the only way to talk to older models.

```yaml
directive:
- from: models.go
where: $
transform: |
const text =
`// Controls how the model responds to function calls. "none" means the model does not call a function, and responds to the\n` +
`// end-user. "auto" means the model can pick between an end-user or calling a\n` +
`// function. Specifying a particular function via {"name": "my_function"} forces the model to call that function. "none" is\n` +
`// the default when no functions are present. "auto" is the default if functions\n` +
`// are present.\n` +
`FunctionCall *ChatCompletionsOptionsFunctionCall\n` +
`\n` +
`// A list of functions the model may generate JSON inputs for.\n` +
`Functions []FunctionDefinition\n`;
return $.replace(/(type ChatCompletionsOptions struct \{.+?FrequencyPenalty \*float32)/s, "$1\n\n" + text);
- from: models_serde.go
where: $
transform: |
const populateLines =
`populate(objectMap, "function_call", c.FunctionCall)\n` +
`populate(objectMap, "functions", c.Functions)`;
return $.replace(/(func \(c ChatCompletionsOptions\) MarshalJSON\(\).+?populate\(objectMap, "frequency_penalty", c.FrequencyPenalty\))/s, "$1\n" + populateLines)
```
Fix ToolChoice discriminated union

```yaml
Expand All @@ -602,3 +601,13 @@ directive:
.replace(/ToolChoiceRenameMe/g, "ToolChoice") // rename all other references
.replace(/populateAny\(objectMap, "tool_choice", c\.ToolChoice\)/, 'populate(objectMap, "tool_choice", c.ToolChoice)'); // treat field as typed so nil means omit.
```
```yaml
directive:
- from: models.go
where: $
transform: return $.replace(/FunctionCall any/, "FunctionCall *ChatCompletionsOptionsFunctionCall");
- from: models_serde.go
where: $
transform: return $.replace(/populateAny\(objectMap, "function_call", c\.FunctionCall\)/, 'populate(objectMap, "function_call", c.FunctionCall)');
```
9 changes: 4 additions & 5 deletions sdk/ai/azopenai/build.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
//go:build go1.18
// +build go1.18

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

//go:generate pwsh ./testdata/genopenapi.ps1
//go:generate autorest ./autorest.md
//go:generate go mod tidy
//go:generate goimports -w .

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

package azopenai
Loading

0 comments on commit 465e3a2

Please sign in to comment.