Skip to content

Commit 3326327

Browse files
authored
compose: ai endpoint (#4966)
Fix `AZURE_OPENAI_ENDPOINT` not showing in add preview. In #4914, we shifted the preview to leverage the newly added resource metadata. Azure OpenAI models had a resource specific show implementation built that wasn't immediately refactored in the change. This change shifts the Azure OpenAI implementation and fixes the add preview. Contributes to #4933
1 parent 7a97195 commit 3326327

File tree

3 files changed

+18
-47
lines changed

3 files changed

+18
-47
lines changed

cli/azd/internal/cmd/show/show.go

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
1818
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
1919
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appcontainers/armappcontainers/v3"
20-
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cognitiveservices/armcognitiveservices"
2120
"github.com/azure/azure-dev/cli/azd/cmd/actions"
2221
"github.com/azure/azure-dev/cli/azd/internal"
2322
"github.com/azure/azure-dev/cli/azd/internal/cmd"
@@ -35,7 +34,6 @@ import (
3534
"github.com/azure/azure-dev/cli/azd/pkg/output"
3635
"github.com/azure/azure-dev/cli/azd/pkg/output/ux"
3736
"github.com/azure/azure-dev/cli/azd/pkg/project"
38-
"github.com/fatih/color"
3937
"github.com/spf13/cobra"
4038
"github.com/spf13/pflag"
4139
)
@@ -313,11 +311,6 @@ func (s *showAction) showResource(ctx context.Context, name string, env *environ
313311
if err != nil {
314312
return err
315313
}
316-
case strings.EqualFold(resType, "Microsoft.CognitiveServices/accounts/deployments"):
317-
err = showModelDeployment(ctx, s.console, credential, id.Parent, resourceOptions)
318-
if err != nil {
319-
return err
320-
}
321314
default:
322315
showRes := showResource{
323316
env: env,
@@ -424,43 +417,6 @@ func showContainerApp(
424417
return service, nil
425418
}
426419

427-
func showModelDeployment(
428-
ctx context.Context,
429-
console input.Console,
430-
cred azcore.TokenCredential,
431-
id *arm.ResourceID,
432-
opts showResourceOptions) error {
433-
client, err := armcognitiveservices.NewAccountsClient(id.SubscriptionID, cred, opts.clientOpts)
434-
if err != nil {
435-
return fmt.Errorf("creating accounts client: %w", err)
436-
}
437-
438-
account, err := client.Get(ctx, id.ResourceGroupName, id.Name, nil)
439-
if err != nil {
440-
return fmt.Errorf("getting account: %w", err)
441-
}
442-
443-
if account.Properties.Endpoint != nil {
444-
console.Message(ctx, color.HiMagentaString("%s (Azure AI Services Model Deployment)", id.Name))
445-
console.Message(ctx, " Endpoint:")
446-
console.Message(ctx,
447-
output.WithHighLightFormat(fmt.Sprintf(" AZURE_OPENAI_ENDPOINT=%s", *account.Properties.Endpoint)))
448-
console.Message(ctx, " Access:")
449-
console.Message(ctx, " Keyless (Microsoft Entra ID)")
450-
//nolint:lll
451-
console.Message(
452-
ctx,
453-
output.WithGrayFormat(
454-
" Hint: To access locally, use DefaultAzureCredential. To learn more, visit https://learn.microsoft.com/en-us/azure/ai-services/openai/supported-languages",
455-
),
456-
)
457-
458-
console.Message(ctx, "")
459-
}
460-
461-
return nil
462-
}
463-
464420
func (s *showAction) serviceEndpoint(
465421
ctx context.Context, subId string, serviceConfig *project.ServiceConfig, env *environment.Environment) string {
466422
resourceManager, err := s.lazyResourceManager.GetValue()

cli/azd/internal/cmd/show/show_resource.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ func (s *showResource) showResourceGeneric(
9999
Variables: envValues,
100100
}
101101

102+
if opts.resourceSpec != nil {
103+
showRes.Name = opts.resourceSpec.Name
104+
}
105+
102106
return &showRes, nil
103107
}
104108

@@ -112,13 +116,15 @@ func getResourceMeta(id arm.ResourceID) (*scaffold.ResourceMeta, arm.ResourceID)
112116
// find the parent resource
113117
parentId := &id
114118
for {
115-
if parentId.Parent != nil {
116-
parentId = parentId.Parent
119+
if parentId == nil {
120+
panic(fmt.Sprintf("'%s' was not found as a parent of '%s'", res.ParentForEval, resourceType))
117121
}
118122

119-
if parentId.ResourceType.Type == res.ParentForEval {
123+
if parentId.ResourceType.String() == res.ParentForEval {
120124
break
121125
}
126+
127+
parentId = parentId.Parent
122128
}
123129

124130
return &res, *parentId

cli/azd/internal/scaffold/resource_meta.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ var Resources = []ResourceMeta{
6060
ResourceType: "Microsoft.CognitiveServices/accounts",
6161
ApiVersion: "2023-05-01",
6262
},
63+
{
64+
ResourceType: "Microsoft.CognitiveServices/accounts/deployments",
65+
ApiVersion: "2023-05-01",
66+
ParentForEval: "Microsoft.CognitiveServices/accounts",
67+
StandardVarPrefix: "AZURE_OPENAI",
68+
Variables: map[string]string{
69+
"endpoint": "${.properties.endpoint}",
70+
},
71+
},
6372
{
6473
ResourceType: "Microsoft.ContainerRegistry/registries",
6574
ApiVersion: "2023-06-01-preview",

0 commit comments

Comments
 (0)