Skip to content

Commit

Permalink
[azopenai] Updating doc comments based on feedback from an issue, as …
Browse files Browse the repository at this point in the history
…well as previous PR feedback. (#22642)

Updating doc comments based on feedback from an issue, as well as previous PR feedback. Also, the rev we regen'd from brings in the `ChatCompletions.Model` field that had previously been omitted.

Fixes #22642
Fixes #22664
  • Loading branch information
richardpark-msft committed Apr 2, 2024
1 parent 4116d5d commit e978d51
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 14 deletions.
11 changes: 3 additions & 8 deletions sdk/ai/azopenai/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
# Release History

## 0.5.1 (Unreleased)
## 0.5.1 (2024-04-02)

### Features Added

- Updating to the `2024-03-01-preview` API version. This adds support for using Dimensions with Embeddings as well as the ability to choose the embeddings format. PR(#22603)

### Breaking Changes

### Bugs Fixed

### Other Changes
- Updating to the `2024-03-01-preview` API version. This adds support for using Dimensions with Embeddings as well as the ability to choose the embeddings format.
This update also adds in the `Model` field for ChatCompletions responses. PR(#22603)

## 0.5.0 (2024-03-05)

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_30dc941c69"
"Tag": "go/ai/azopenai_a33cdad878"
}
30 changes: 29 additions & 1 deletion sdk/ai/azopenai/autorest.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,17 @@ directive:
.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: ");
# hack - we have _one_ spot where we want to keep it as Model (ChatCompletions.Model) since
# it is the actual model name, not the deployment, in Azure OpenAI or OpenAI.
- from: models.go
where: $
transform: return $.replace(/(ChatCompletions.+?)DeploymentName/s, "$1Model");
- from: models_serde.go
where: $
transform: |
return $
.replace(/(func \(c ChatCompletions\) MarshalJSON.+?populate\(objectMap, "model", c\.)DeploymentName/s, "$1Model")
.replace(/(func \(c \*ChatCompletions\) UnmarshalJSON.+?unpopulate\(val, "Model", &c\.)DeploymentName/s, "$1Model");
```

## Polymorphic adjustments
Expand Down Expand Up @@ -622,3 +632,21 @@ directive:
where: $
transform: return $.replace(/\/\/ EmbeddingItem - .+?type EmbeddingItem struct \{.+?\n}\n/s, "");
```

Fix some doc comments

```yaml
directive:
- from: models.go
where: $
transform: |
const text = "// NOTE: This field is not available when using [Client.GetChatCompletionsStream].\n$1";
return $.replace(/(Usage \*CompletionsUsage)/, text);
- from: models.go
where: $
transform: |
const text = "// - If using EmbeddingEncodingFormatFloat (the default), the value will be a []float32, in [EmbeddingItem.Embedding]\n" +
"// - If using EmbeddingEncodingFormatBase64, the value will be a base-64 string in [EmbeddingItem.EmbeddingBase64]\n";
return $.replace(/(EncodingFormat \*EmbeddingEncodingFormat)/, `${text}$1`);
```
13 changes: 13 additions & 0 deletions sdk/ai/azopenai/client_chat_completions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ func testGetChatCompletions(t *testing.T, client *azopenai.Client, deployment st
PromptTokens: to.Ptr(int32(42)),
TotalTokens: to.Ptr(int32(71)),
},
// NOTE: this is actually the name of the _model_, not the deployment. They usually match (just
// by convention) but if this fails because they _don't_ match we can just adjust the test.
Model: &deployment,
}

resp, err := client.GetChatCompletions(context.Background(), newTestChatCompletionOptions(deployment), nil)
Expand Down Expand Up @@ -127,13 +130,21 @@ func testGetChatCompletionsStream(t *testing.T, client *azopenai.Client, deploym
// check that the role came back as well.
var choices []azopenai.ChatChoice

modelWasReturned := false

for {
completion, err := streamResp.ChatCompletionsStream.Read()

if errors.Is(err, io.EOF) {
break
}

// NOTE: this is actually the name of the _model_, not the deployment. They usually match (just
// by convention) but if this fails because they _don't_ match we can just adjust the test.
if deployment == *completion.Model {
modelWasReturned = true
}

require.NoError(t, err)

if completion.PromptFilterResults != nil {
Expand All @@ -151,6 +162,8 @@ func testGetChatCompletionsStream(t *testing.T, client *azopenai.Client, deploym
choices = append(choices, completion.Choices[0])
}

require.True(t, modelWasReturned)

var message string

for _, choice := range choices {
Expand Down
2 changes: 1 addition & 1 deletion sdk/ai/azopenai/client_shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func updateModels(azure bool, tv *testVars) {
tv.TextEmbedding3Small = model(azure, "text-embedding-3-small", "text-embedding-3-small")

tv.DallE.Model = model(azure, "dall-e-3", "dall-e-3")
tv.Whisper.Model = model(azure, "whisper", "whisper-1")
tv.Whisper.Model = model(azure, "whisper-deployment", "whisper-1")
tv.Vision.Model = model(azure, "gpt-4-vision-preview", "gpt-4-vision-preview")

// these are Azure-only features
Expand Down
6 changes: 6 additions & 0 deletions sdk/ai/azopenai/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions sdk/ai/azopenai/models_serde.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions sdk/ai/azopenai/testdata/tsp-location.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
directory: specification/cognitiveservices/OpenAI.Inference
# Travis's latest PR adding support for the March preview release.
# https://github.com/Azure/azure-rest-api-specs/pull/28118
commit: 2a71ca6e3097fecb2edacbcc815f47b3dac336b9
commit: 1236daacb3f8c571c0fe97855ac12556d7a38172
repo: Azure/azure-rest-api-specs

0 comments on commit e978d51

Please sign in to comment.