-
Notifications
You must be signed in to change notification settings - Fork 332
Refactoring jobs list command to align with the LLD | Add retry, environment and validation utils #6430
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
Merged
achauhan-scc
merged 10 commits into
Azure:Model-Customization-Dev
from
saanikaguptamicrosoft:saanika/jobslist
Dec 29, 2025
Merged
Refactoring jobs list command to align with the LLD | Add retry, environment and validation utils #6430
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
955f9ee
initial changes
saanikaguptamicrosoft 3982105
Add retry util for exponential backoff with jitter strategy
saanikaguptamicrosoft 5ef4f08
Clean-up
saanikaguptamicrosoft 8315334
Standardize CLI text to lowercase conventions, and remove redundant e…
saanikaguptamicrosoft 3ebf774
Address comments
saanikaguptamicrosoft b41ba1d
Add common util for fetch environment variables
saanikaguptamicrosoft 03c3598
Cosmetic changes
saanikaguptamicrosoft 0026e8d
Cosmetic changes 2
saanikaguptamicrosoft cc5c077
Fix runtime error
saanikaguptamicrosoft d85dc6d
Fix error message format
saanikaguptamicrosoft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
cli/azd/extensions/azure.ai.finetune/internal/cmd/validation.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "azure.ai.finetune/internal/utils" | ||
| "github.com/azure/azure-dev/cli/azd/pkg/azdext" | ||
| ) | ||
|
|
||
| func validateEnvironment(ctx context.Context) error { | ||
| ctx = azdext.WithAccessToken(ctx) | ||
|
|
||
| azdClient, err := azdext.NewAzdClient() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer azdClient.Close() | ||
|
|
||
| envValues, _ := utils.GetEnvironmentValues(ctx, azdClient) | ||
| required := []string{utils.EnvAzureTenantID, utils.EnvAzureSubscriptionID, utils.EnvAzureLocation, utils.EnvAzureAccountName} | ||
|
|
||
| for _, varName := range required { | ||
| if envValues[varName] == "" { | ||
| return fmt.Errorf("required environment variables not set. Please run 'azd ai finetune init' command to configure your environment") | ||
| } | ||
| } | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
cli/azd/extensions/azure.ai.finetune/internal/providers/factory/provider_factory.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package factory | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "azure.ai.finetune/internal/providers" | ||
| azureprovider "azure.ai.finetune/internal/providers/azure" | ||
| openaiprovider "azure.ai.finetune/internal/providers/openai" | ||
| "azure.ai.finetune/internal/utils" | ||
| "github.com/Azure/azure-sdk-for-go/sdk/azcore" | ||
| "github.com/Azure/azure-sdk-for-go/sdk/azidentity" | ||
| "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cognitiveservices/armcognitiveservices" | ||
| "github.com/azure/azure-dev/cli/azd/pkg/azdext" | ||
| "github.com/openai/openai-go/v3" | ||
| "github.com/openai/openai-go/v3/azure" | ||
| "github.com/openai/openai-go/v3/option" | ||
| ) | ||
|
|
||
| const ( | ||
| // OpenAI API version for Azure cognitive services | ||
| apiVersion = "2025-04-01-preview" | ||
| // Azure cognitive services endpoint URL pattern | ||
| azureCognitiveServicesEndpoint = "https://%s.cognitiveservices.azure.com/openai" | ||
| ) | ||
|
|
||
| func GetOpenAIClientFromAzdClient(ctx context.Context, azdClient *azdext.AzdClient) (*openai.Client, error) { | ||
| envValueMap, err := utils.GetEnvironmentValues(ctx, azdClient) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to get environment values: %w", err) | ||
| } | ||
|
|
||
| azureContext := &azdext.AzureContext{ | ||
| Scope: &azdext.AzureScope{ | ||
| TenantId: envValueMap[utils.EnvAzureTenantID], | ||
| SubscriptionId: envValueMap[utils.EnvAzureSubscriptionID], | ||
| Location: envValueMap[utils.EnvAzureLocation], | ||
| }, | ||
| Resources: []string{}, | ||
| } | ||
|
|
||
| credential, err := azidentity.NewAzureDeveloperCLICredential(&azidentity.AzureDeveloperCLICredentialOptions{ | ||
| TenantID: azureContext.Scope.TenantId, | ||
| AdditionallyAllowedTenants: []string{"*"}, | ||
| }) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to create azure credential: %w", err) | ||
| } | ||
|
|
||
| // Get Azure credentials and endpoint - TODO | ||
| // You'll need to get these from your environment or config | ||
| accountName := envValueMap[utils.EnvAzureAccountName] | ||
| endpoint := fmt.Sprintf(azureCognitiveServicesEndpoint, accountName) | ||
| // Create OpenAI client | ||
| client := openai.NewClient( | ||
| //azure.WithEndpoint(endpoint, apiVersion), | ||
| option.WithBaseURL(endpoint), | ||
| option.WithQuery("api-version", apiVersion), | ||
| azure.WithTokenCredential(credential), | ||
| ) | ||
| return &client, nil | ||
| } | ||
|
|
||
| // NewFineTuningProvider creates a FineTuningProvider based on provider type | ||
| func NewFineTuningProvider(ctx context.Context, azdClient *azdext.AzdClient) (providers.FineTuningProvider, error) { | ||
| client, err := GetOpenAIClientFromAzdClient(ctx, azdClient) | ||
| return openaiprovider.NewOpenAIProvider(client), err | ||
| } | ||
|
|
||
| // NewModelDeploymentProvider creates a ModelDeploymentProvider based on provider type | ||
| func NewModelDeploymentProvider(subscriptionId string, credential azcore.TokenCredential) (providers.ModelDeploymentProvider, error) { | ||
| clientFactory, err := armcognitiveservices.NewClientFactory( | ||
| subscriptionId, | ||
| credential, | ||
| nil, | ||
| ) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to create armcognitiveservices client factory: %w", err) | ||
| } | ||
| return azureprovider.NewAzureProvider(clientFactory), err | ||
| } | ||
49 changes: 49 additions & 0 deletions
49
cli/azd/extensions/azure.ai.finetune/internal/providers/openai/conversions.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package openai | ||
|
|
||
| import ( | ||
| "azure.ai.finetune/internal/utils" | ||
| "azure.ai.finetune/pkg/models" | ||
| "github.com/openai/openai-go/v3" | ||
| ) | ||
|
|
||
| // OpenAI Status Constants - matches OpenAI SDK values | ||
| const ( | ||
| OpenAIStatusValidatingFiles = "validating_files" | ||
| OpenAIStatusQueued = "queued" | ||
| OpenAIStatusRunning = "running" | ||
| OpenAIStatusSucceeded = "succeeded" | ||
| OpenAIStatusFailed = "failed" | ||
| OpenAIStatusCancelled = "cancelled" | ||
| ) | ||
|
|
||
| // mapOpenAIStatusToJobStatus converts OpenAI SDK status to domain model JobStatus | ||
| func mapOpenAIStatusToJobStatus(openaiStatus openai.FineTuningJobStatus) models.JobStatus { | ||
| switch openaiStatus { | ||
| case OpenAIStatusValidatingFiles, OpenAIStatusRunning: | ||
| return models.StatusRunning | ||
| case OpenAIStatusQueued: | ||
| return models.StatusQueued | ||
| case OpenAIStatusSucceeded: | ||
| return models.StatusSucceeded | ||
| case OpenAIStatusFailed: | ||
| return models.StatusFailed | ||
| case OpenAIStatusCancelled: | ||
| return models.StatusCancelled | ||
| default: | ||
| return models.StatusPending // Default fallback | ||
| } | ||
| } | ||
|
|
||
| // convertOpenAIJobToModel converts OpenAI SDK job to domain model | ||
| func convertOpenAIJobToModel(openaiJob openai.FineTuningJob) *models.FineTuningJob { | ||
| return &models.FineTuningJob{ | ||
| ID: openaiJob.ID, | ||
| Status: mapOpenAIStatusToJobStatus(openaiJob.Status), | ||
| BaseModel: openaiJob.Model, | ||
| FineTunedModel: openaiJob.FineTunedModel, | ||
| CreatedAt: utils.UnixTimestampToUTC(openaiJob.CreatedAt), | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.