Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[azopenai] Fixing some issues with incorrect/incomplete types in generation #22119

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_9ed7d01267"
"Tag": "go/ai/azopenai_4b8f565947"
}
16 changes: 15 additions & 1 deletion sdk/ai/azopenai/autorest.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ These settings apply only when `--go` is specified on the command line.

``` yaml
input-file:
- https://github.com/Azure/azure-rest-api-specs/blob/d402f685809d6d08be9c0b45065cadd7d78ab870/specification/cognitiveservices/data-plane/AzureOpenAI/inference/preview/2023-12-01-preview/generated.json
- https://github.com/Azure/azure-rest-api-specs/blob/3e0e2a93ddb3c9c44ff1baf4952baa24ca98e9db/specification/cognitiveservices/data-plane/AzureOpenAI/inference/preview/2023-12-01-preview/generated.json

output-folder: ../azopenai
clear-output-folder: false
Expand Down Expand Up @@ -98,6 +98,20 @@ directive:
transform: return $.replace(/InternalOYDAuthTypeRename/g, "configType")
```

`ChatCompletionsResponseFormat.Type`

```yaml
directive:
- from: swagger-document
where: $.definitions.ChatCompletionsResponseFormat
transform: $.properties.type["x-ms-client-name"] = "InternalChatCompletionsResponseFormat"
- from:
- models.go
- models_serde.go
where: $
transform: return $.replace(/InternalChatCompletionsResponseFormat/g, "respType")
```

## Model -> DeploymentName

```yaml
Expand Down
38 changes: 38 additions & 0 deletions sdk/ai/azopenai/client_chat_completions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package azopenai_test

import (
"context"
"encoding/json"
"errors"
"io"
"net/http"
Expand Down Expand Up @@ -262,3 +263,40 @@ func TestClient_OpenAI_GetChatCompletions_Vision(t *testing.T) {

t.Logf(*resp.Choices[0].Message.Content)
}

func TestGetChatCompletions_usingResponseFormatForJSON(t *testing.T) {
testFn := func(t *testing.T, chatClient *azopenai.Client, deploymentName string) {
body := azopenai.ChatCompletionsOptions{
DeploymentName: &deploymentName,
Messages: []azopenai.ChatRequestMessageClassification{
&azopenai.ChatRequestSystemMessage{Content: to.Ptr("You are a helpful assistant designed to output JSON.")},
&azopenai.ChatRequestUserMessage{
Content: azopenai.NewChatRequestUserMessageContent("List capital cities and their states"),
},
},
// Without this format directive you end up getting JSON, but with a non-JSON preamble, like this:
// "I'm happy to help! Here are some examples of capital cities and their corresponding states:\n\n```json\n{\n" (etc)
ResponseFormat: &azopenai.ChatCompletionsJSONResponseFormat{},
Temperature: to.Ptr[float32](0.0),
}

resp, err := chatClient.GetChatCompletions(context.Background(), body, nil)
require.NoError(t, err)

// validate that it came back as JSON data
var v any
err = json.Unmarshal([]byte(*resp.Choices[0].Message.Content), &v)
require.NoError(t, err)
require.NotEmpty(t, v)
}

t.Run("OpenAI", func(t *testing.T) {
chatClient := newOpenAIClientForTest(t)
testFn(t, chatClient, "gpt-3.5-turbo-1106")
})

t.Run("AzureOpenAI", func(t *testing.T) {
chatClient := newTestClient(t, azureOpenAI.DallE.Endpoint)
testFn(t, chatClient, "gpt-4-1106-preview")
})
}
20 changes: 0 additions & 20 deletions sdk/ai/azopenai/constants.go

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

9 changes: 9 additions & 0 deletions sdk/ai/azopenai/interfaces.go

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

42 changes: 41 additions & 1 deletion sdk/ai/azopenai/models.go

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

83 changes: 82 additions & 1 deletion sdk/ai/azopenai/models_serde.go

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

23 changes: 23 additions & 0 deletions sdk/ai/azopenai/polymorphic_helpers.go

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

Loading