Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 0 deletions sdk/ai/azopenai/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Breaking Changes

- ChatCompletionsOptions, CompletionsOptions, EmbeddingsOptions `DeploymentID` field renamed to `Deployment`.

### Bugs Fixed

### Other Changes
Expand Down
10 changes: 5 additions & 5 deletions sdk/ai/azopenai/autorest.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ directive:
where: $
transform: |
return $
.replace(/runtime\.JoinPaths\(client.endpoint, urlPath\)/g, "client.formatURL(urlPath, getDeploymentID(body))");
.replace(/runtime\.JoinPaths\(client.endpoint, urlPath\)/g, "client.formatURL(urlPath, getDeployment(body))");

# Some ImageGenerations hackery to represent the ImageLocation/ImagePayload polymorphism.
# - Remove the auto-generated ImageGenerationsDataItem.
Expand Down Expand Up @@ -280,18 +280,18 @@ directive:
transform: return $.replace(/runtime\.NewResponseError/sg, "client.newError");

#
# rename `Model` to `DeploymentID`
# rename `Model` to `Deployment`
#
- from: models.go
where: $
transform: |
return $
.replace(/\/\/ The model name.*?Model \*string/sg, "// REQUIRED: DeploymentID specifies the name of the deployment (for Azure OpenAI) or model (for OpenAI) to use for this request.\nDeploymentID string");
.replace(/\/\/ The model name.*?Model \*string/sg, "// REQUIRED: Deployment specifies the name of the deployment (for Azure OpenAI) or model (for OpenAI) to use for this request.\nDeployment string");

- from: models_serde.go
where: $
transform: |
return $
.replace(/populate\(objectMap, "model", (c|e).Model\)/g, 'populate(objectMap, "model", &$1.DeploymentID)')
.replace(/err = unpopulate\(val, "Model", &(c|e).Model\)/g, 'err = unpopulate(val, "Model", &$1.DeploymentID)');
.replace(/populate\(objectMap, "model", (c|e).Model\)/g, 'populate(objectMap, "model", &$1.Deployment)')
.replace(/err = unpopulate\(val, "Model", &(c|e).Model\)/g, 'err = unpopulate(val, "Model", &$1.Deployment)');
```
8 changes: 4 additions & 4 deletions sdk/ai/azopenai/client.go

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

12 changes: 6 additions & 6 deletions sdk/ai/azopenai/client_chat_completions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ func newTestChatCompletionOptions(tv testVars) azopenai.ChatCompletionsOptions {
Content: to.Ptr("Count to 10, with a comma between each number, no newlines and a period at the end. E.g., 1, 2, 3, ..."),
},
},
MaxTokens: to.Ptr(int32(1024)),
Temperature: to.Ptr(float32(0.0)),
DeploymentID: tv.ChatCompletions,
MaxTokens: to.Ptr(int32(1024)),
Temperature: to.Ptr(float32(0.0)),
Deployment: tv.ChatCompletions,
}
}

Expand Down Expand Up @@ -202,9 +202,9 @@ func TestClient_GetChatCompletions_InvalidModel(t *testing.T) {
Content: to.Ptr("Count to 100, with a comma between each number and no newlines. E.g., 1, 2, 3, ..."),
},
},
MaxTokens: to.Ptr(int32(1024)),
Temperature: to.Ptr(float32(0.0)),
DeploymentID: "invalid model name",
MaxTokens: to.Ptr(int32(1024)),
Temperature: to.Ptr(float32(0.0)),
Deployment: "invalid model name",
}, nil)

var respErr *azcore.ResponseError
Expand Down
8 changes: 4 additions & 4 deletions sdk/ai/azopenai/client_completions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ func testGetCompletions(t *testing.T, client *azopenai.Client, isAzure bool) {
}

resp, err := client.GetCompletions(context.Background(), azopenai.CompletionsOptions{
Prompt: []string{"What is Azure OpenAI?"},
MaxTokens: to.Ptr(int32(2048 - 127)),
Temperature: to.Ptr(float32(0.0)),
DeploymentID: deploymentID,
Prompt: []string{"What is Azure OpenAI?"},
MaxTokens: to.Ptr(int32(2048 - 127)),
Temperature: to.Ptr(float32(0.0)),
Deployment: deploymentID,
}, nil)
require.NoError(t, err)

Expand Down
6 changes: 3 additions & 3 deletions sdk/ai/azopenai/client_embeddings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestClient_GetEmbeddings_InvalidModel(t *testing.T) {
require.NoError(t, err)

_, err = chatClient.GetEmbeddings(context.Background(), azopenai.EmbeddingsOptions{
DeploymentID: "thisdoesntexist",
Deployment: "thisdoesntexist",
}, nil)

var respErr *azcore.ResponseError
Expand Down Expand Up @@ -69,8 +69,8 @@ func testGetEmbeddings(t *testing.T, client *azopenai.Client, modelOrDeploymentI
ctx: context.TODO(),
deploymentID: modelOrDeploymentID,
body: azopenai.EmbeddingsOptions{
Input: []string{"\"Your text string goes here\""},
DeploymentID: modelOrDeploymentID,
Input: []string{"\"Your text string goes here\""},
Deployment: modelOrDeploymentID,
},
options: nil,
},
Expand Down
2 changes: 1 addition & 1 deletion sdk/ai/azopenai/client_functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestGetChatCompletions_usingFunctions(t *testing.T) {

func testChatCompletionsFunctions(t *testing.T, chatClient *azopenai.Client, tv testVars) {
body := azopenai.ChatCompletionsOptions{
DeploymentID: tv.ChatCompletions,
Deployment: tv.ChatCompletions,
Messages: []azopenai.ChatMessage{
{
Role: to.Ptr(azopenai.ChatRoleUser),
Expand Down
20 changes: 10 additions & 10 deletions sdk/ai/azopenai/client_rai_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ func TestClient_GetCompletions_AzureOpenAI_ContentFilter_Response(t *testing.T)
client := newAzureOpenAIClientForTest(t, azureOpenAI)

resp, err := client.GetCompletions(context.Background(), azopenai.CompletionsOptions{
Prompt: []string{"How do I rob a bank?"},
MaxTokens: to.Ptr(int32(2048 - 127)),
Temperature: to.Ptr(float32(0.0)),
DeploymentID: azureOpenAI.Completions,
Prompt: []string{"How do I rob a bank?"},
MaxTokens: to.Ptr(int32(2048 - 127)),
Temperature: to.Ptr(float32(0.0)),
Deployment: azureOpenAI.Completions,
}, nil)

require.Empty(t, resp)
Expand All @@ -40,9 +40,9 @@ func TestClient_GetChatCompletions_AzureOpenAI_ContentFilterWithError(t *testing
{Role: to.Ptr(azopenai.ChatRoleSystem), Content: to.Ptr("You are a helpful assistant.")},
{Role: to.Ptr(azopenai.ChatRoleUser), Content: to.Ptr("How do I rob a bank?")},
},
MaxTokens: to.Ptr(int32(2048 - 127)),
Temperature: to.Ptr(float32(0.0)),
DeploymentID: azureOpenAICanary.ChatCompletions,
MaxTokens: to.Ptr(int32(2048 - 127)),
Temperature: to.Ptr(float32(0.0)),
Deployment: azureOpenAICanary.ChatCompletions,
}, nil)
require.Empty(t, resp)
assertContentFilterError(t, err, true)
Expand All @@ -55,9 +55,9 @@ func TestClient_GetChatCompletions_AzureOpenAI_ContentFilter_WithResponse(t *tes
Messages: []azopenai.ChatMessage{
{Role: to.Ptr(azopenai.ChatRoleUser), Content: to.Ptr("How do I cook a bell pepper?")},
},
MaxTokens: to.Ptr(int32(2048 - 127)),
Temperature: to.Ptr(float32(0.0)),
DeploymentID: azureOpenAICanary.ChatCompletions,
MaxTokens: to.Ptr(int32(2048 - 127)),
Temperature: to.Ptr(float32(0.0)),
Deployment: azureOpenAICanary.ChatCompletions,
}, nil)

require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion sdk/ai/azopenai/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestClient_OpenAI_InvalidModel(t *testing.T) {
Content: to.Ptr("hello"),
},
},
DeploymentID: "non-existent-model",
Deployment: "non-existent-model",
}, nil)

var respErr *azcore.ResponseError
Expand Down
8 changes: 4 additions & 4 deletions sdk/ai/azopenai/custom_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,14 @@ type clientData struct {
azure bool
}

func getDeploymentID[T ChatCompletionsOptions | CompletionsOptions | EmbeddingsOptions | ImageGenerationOptions](v T) string {
func getDeployment[T ChatCompletionsOptions | CompletionsOptions | EmbeddingsOptions | ImageGenerationOptions](v T) string {
switch a := any(v).(type) {
case ChatCompletionsOptions:
return a.DeploymentID
return a.Deployment
case CompletionsOptions:
return a.DeploymentID
return a.Deployment
case EmbeddingsOptions:
return a.DeploymentID
return a.Deployment
case ImageGenerationOptions:
return ""
default:
Expand Down
16 changes: 8 additions & 8 deletions sdk/ai/azopenai/custom_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ func TestGetCompletionsStream_OpenAI(t *testing.T) {

func testGetCompletionsStream(t *testing.T, client *azopenai.Client, tv testVars) {
body := azopenai.CompletionsOptions{
Prompt: []string{"What is Azure OpenAI?"},
MaxTokens: to.Ptr(int32(2048)),
Temperature: to.Ptr(float32(0.0)),
DeploymentID: tv.Completions,
Prompt: []string{"What is Azure OpenAI?"},
MaxTokens: to.Ptr(int32(2048)),
Temperature: to.Ptr(float32(0.0)),
Deployment: tv.Completions,
}

response, err := client.GetCompletionsStream(context.TODO(), body, nil)
Expand Down Expand Up @@ -154,10 +154,10 @@ func TestClient_GetCompletions_Error(t *testing.T) {

doTest := func(t *testing.T, client *azopenai.Client, model string) {
streamResp, err := client.GetCompletionsStream(context.Background(), azopenai.CompletionsOptions{
Prompt: []string{"What is Azure OpenAI?"},
MaxTokens: to.Ptr(int32(2048 - 127)),
Temperature: to.Ptr(float32(0.0)),
DeploymentID: model,
Prompt: []string{"What is Azure OpenAI?"},
MaxTokens: to.Ptr(int32(2048 - 127)),
Temperature: to.Ptr(float32(0.0)),
Deployment: model,
}, nil)
require.Empty(t, streamResp)
assertResponseIsError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions sdk/ai/azopenai/example_client_embeddings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func ExampleClient_GetEmbeddings() {
}

resp, err := client.GetEmbeddings(context.TODO(), azopenai.EmbeddingsOptions{
Input: []string{"The food was delicious and the waiter..."},
DeploymentID: modelDeploymentID,
Input: []string{"The food was delicious and the waiter..."},
Deployment: modelDeploymentID,
}, nil)

if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions sdk/ai/azopenai/example_client_getchatcompletions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func ExampleClient_GetChatCompletions() {
resp, err := client.GetChatCompletions(context.TODO(), azopenai.ChatCompletionsOptions{
// This is a conversation in progress.
// NOTE: all messages count against token usage for this API.
Messages: messages,
DeploymentID: modelDeploymentID,
Messages: messages,
Deployment: modelDeploymentID,
}, nil)

if err != nil {
Expand Down Expand Up @@ -111,7 +111,7 @@ func ExampleClient_GetChatCompletions_functions() {
}

resp, err := client.GetChatCompletions(context.Background(), azopenai.ChatCompletionsOptions{
DeploymentID: modelDeploymentID,
Deployment: modelDeploymentID,
Messages: []azopenai.ChatMessage{
{
Role: to.Ptr(azopenai.ChatRoleUser),
Expand Down Expand Up @@ -220,9 +220,9 @@ func ExampleClient_GetChatCompletionsStream() {
resp, err := client.GetChatCompletionsStream(context.TODO(), azopenai.ChatCompletionsOptions{
// This is a conversation in progress.
// NOTE: all messages count against token usage for this API.
Messages: messages,
N: to.Ptr[int32](1),
DeploymentID: modelDeploymentID,
Messages: messages,
N: to.Ptr[int32](1),
Deployment: modelDeploymentID,
}, nil)

if err != nil {
Expand Down
20 changes: 10 additions & 10 deletions sdk/ai/azopenai/example_client_getcompletions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import (

func ExampleClient_GetCompletions() {
azureOpenAIKey := os.Getenv("AOAI_API_KEY")
modelDeploymentID := os.Getenv("AOAI_COMPLETIONS_MODEL_DEPLOYMENT")
modelDeployment := os.Getenv("AOAI_COMPLETIONS_MODEL_DEPLOYMENT")

// Ex: "https://<your-azure-openai-host>.openai.azure.com"
azureOpenAIEndpoint := os.Getenv("AOAI_ENDPOINT")

if azureOpenAIKey == "" || modelDeploymentID == "" || azureOpenAIEndpoint == "" {
if azureOpenAIKey == "" || modelDeployment == "" || azureOpenAIEndpoint == "" {
fmt.Fprintf(os.Stderr, "Skipping example, environment variables missing\n")
return
}
Expand All @@ -41,10 +41,10 @@ func ExampleClient_GetCompletions() {
}

resp, err := client.GetCompletions(context.TODO(), azopenai.CompletionsOptions{
Prompt: []string{"What is Azure OpenAI, in 20 words or less"},
MaxTokens: to.Ptr(int32(2048)),
Temperature: to.Ptr(float32(0.0)),
DeploymentID: modelDeploymentID,
Prompt: []string{"What is Azure OpenAI, in 20 words or less"},
MaxTokens: to.Ptr(int32(2048)),
Temperature: to.Ptr(float32(0.0)),
Deployment: modelDeployment,
}, nil)

if err != nil {
Expand Down Expand Up @@ -85,10 +85,10 @@ func ExampleClient_GetCompletionsStream() {
}

resp, err := client.GetCompletionsStream(context.TODO(), azopenai.CompletionsOptions{
Prompt: []string{"What is Azure OpenAI, in 20 words or less?"},
MaxTokens: to.Ptr(int32(2048)),
Temperature: to.Ptr(float32(0.0)),
DeploymentID: modelDeploymentID,
Prompt: []string{"What is Azure OpenAI, in 20 words or less?"},
MaxTokens: to.Ptr(int32(2048)),
Temperature: to.Ptr(float32(0.0)),
Deployment: modelDeploymentID,
}, nil)

if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions sdk/ai/azopenai/models.go

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

Loading