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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
id: azure.ai.customtraining
namespace: ai.training
displayName: Azure AI Custom Training (Preview)
description: Extension for Azure AI Foundry custom training jobs. (Preview)
description: Extension for Microsoft Foundry custom training jobs. (Preview)
usage: azd ai training <command> [options]
version: 0.0.1-preview
language: go
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func newJobCommand() *cobra.Command {
cmd.AddCommand(newJobDeleteCommand())
cmd.AddCommand(newJobCancelCommand())
cmd.AddCommand(newJobValidateCommand())
cmd.AddCommand(newJobStreamCommand())

return cmd
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package cmd

import (
"fmt"

"azure.ai.customtraining/internal/service"
"azure.ai.customtraining/internal/utils"
"azure.ai.customtraining/pkg/client"

"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/azure/azure-dev/cli/azd/pkg/azdext"
"github.com/spf13/cobra"
)

func newJobStreamCommand() *cobra.Command {
var name string

cmd := &cobra.Command{
Use: "stream",
Short: "Stream logs from a running training job",
Long: "Stream live log output from a training job. Polls for new log content\nuntil the job reaches a terminal state.\n\nExample:\n azd ai training job stream --name my-job-123",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := azdext.WithAccessToken(cmd.Context())

if name == "" {
return fmt.Errorf("--name is required")
}

azdClient, err := azdext.NewAzdClient()
if err != nil {
return fmt.Errorf("failed to create azd client: %w", err)
}
defer azdClient.Close()

envValues, err := utils.GetEnvironmentValues(ctx, azdClient)
if err != nil {
return fmt.Errorf("failed to get environment values: %w", err)
}

accountName := envValues[utils.EnvAzureAccountName]
projectName := envValues[utils.EnvAzureProjectName]
tenantID := envValues[utils.EnvAzureTenantID]

if accountName == "" || projectName == "" {
return fmt.Errorf("environment not configured. Run 'azd ai training init' first")
}

credential, err := azidentity.NewAzureDeveloperCLICredential(
&azidentity.AzureDeveloperCLICredentialOptions{
TenantID: tenantID,
AdditionallyAllowedTenants: []string{"*"},
},
)
if err != nil {
return fmt.Errorf("failed to create azure credential: %w", err)
}

endpoint := buildProjectEndpoint(accountName, projectName)
apiClient, err := client.NewClient(endpoint, credential)
if err != nil {
return fmt.Errorf("failed to create API client: %w", err)
}
apiClient.SetDebugBody(rootFlags.Debug)

streamSvc := service.NewStreamService(apiClient)
result, err := streamSvc.StreamJobLogs(ctx, name)
if err != nil {
return err
}

fmt.Println()
fmt.Println("Execution Summary")
fmt.Printf("RunId: %s\n", result.JobName)
fmt.Printf("Status: %s\n", result.Status)
if result.StudioURL != "" {
fmt.Printf("Web View: %s\n", result.StudioURL)
}

return nil
},
}

cmd.Flags().StringVar(&name, "name", "", "Job name/ID (required)")

return cmd
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var rootFlags rootFlagsDefinition
func NewRootCommand() *cobra.Command {
rootCmd := &cobra.Command{
Use: "training <command> [options]",
Short: "Extension for Azure AI Foundry custom training jobs. (Preview)",
Short: "Extension for Microsoft Foundry custom training jobs. (Preview)",
SilenceUsage: true,
SilenceErrors: true,
CompletionOptions: cobra.CompletionOptions{
Expand Down
Loading