Skip to content
Merged
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
102 changes: 30 additions & 72 deletions cli/azd/extensions/azure.ai.agents/internal/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -1485,94 +1484,53 @@ func (a *InitAction) addToProject(ctx context.Context, targetDir string, agentMa
}

func (a *InitAction) populateContainerSettings(ctx context.Context) (*project.ContainerSettings, error) {
if a.flags.NoPrompt {
fmt.Printf("No prompt mode enabled, using default container settings\n")
return &project.ContainerSettings{
Resources: &project.ResourceSettings{
Memory: project.DefaultMemory,
Cpu: project.DefaultCpu,
},
Scale: &project.ScaleSettings{
MinReplicas: project.DefaultMinReplicas,
MaxReplicas: project.DefaultMaxReplicas,
},
}, nil
type resourceTier struct {
label string
cpu string
memory string
}

// Default values
defaultMemory := project.DefaultMemory
defaultCpu := project.DefaultCpu
defaultMinReplicas := fmt.Sprintf("%d", project.DefaultMinReplicas)
defaultMaxReplicas := fmt.Sprintf("%d", project.DefaultMaxReplicas)

// Prompt for memory allocation
memoryResp, err := a.azdClient.Prompt().Prompt(ctx, &azdext.PromptRequest{
Options: &azdext.PromptOptions{
Message: "Enter desired container memory allocation (e.g., '1Gi', '512Mi')",
DefaultValue: defaultMemory,
tiers := []resourceTier{
{
label: fmt.Sprintf("%s cores, %s memory", project.DefaultCpu, project.DefaultMemory),
cpu: project.DefaultCpu,
memory: project.DefaultMemory,
},
})
if err != nil {
return nil, fmt.Errorf("prompting for memory allocation: %w", err)
{label: "0.5 cores, 1Gi memory", cpu: "0.5", memory: "1Gi"},
{label: "1 core, 2Gi memory", cpu: "1", memory: "2Gi"},
{label: "2 cores, 4Gi memory", cpu: "2", memory: "4Gi"},
}
Comment thread
trangevi marked this conversation as resolved.
Outdated

// Prompt for CPU allocation
cpuResp, err := a.azdClient.Prompt().Prompt(ctx, &azdext.PromptRequest{
Options: &azdext.PromptOptions{
Message: "Enter desired container CPU allocation (e.g., '1', '500m')",
DefaultValue: defaultCpu,
},
})
if err != nil {
return nil, fmt.Errorf("prompting for CPU allocation: %w", err)
}

// Prompt for minimum replicas
minReplicasResp, err := a.azdClient.Prompt().Prompt(ctx, &azdext.PromptRequest{
Options: &azdext.PromptOptions{
Message: "Enter desired container minimum number of replicas",
DefaultValue: defaultMinReplicas,
},
})
if err != nil {
return nil, fmt.Errorf("prompting for minimum replicas: %w", err)
choices := make([]*azdext.SelectChoice, len(tiers))
for i, t := range tiers {
choices[i] = &azdext.SelectChoice{
Label: t.label,
Value: fmt.Sprintf("%d", i),
}
}

// Prompt for maximum replicas
maxReplicasResp, err := a.azdClient.Prompt().Prompt(ctx, &azdext.PromptRequest{
Options: &azdext.PromptOptions{
Message: "Enter desired container maximum number of replicas",
DefaultValue: defaultMaxReplicas,
defaultIndex := int32(0)
resp, err := a.azdClient.Prompt().Select(ctx, &azdext.SelectRequest{
Options: &azdext.SelectOptions{
Message: "Select container resource allocation (CPU and Memory) for your agent. You can adjust these settings later in the azure.yaml file if needed.",
Choices: choices,
SelectedIndex: &defaultIndex,
},
})
Comment thread
trangevi marked this conversation as resolved.
if err != nil {
return nil, fmt.Errorf("prompting for maximum replicas: %w", err)
}

// Convert string values to appropriate types
minReplicas, err := strconv.Atoi(minReplicasResp.Value)
if err != nil {
return nil, fmt.Errorf("invalid minimum replicas value: %w", err)
return nil, fmt.Errorf("prompting for container resources: %w", err)
}

maxReplicas, err := strconv.Atoi(maxReplicasResp.Value)
if err != nil {
return nil, fmt.Errorf("invalid maximum replicas value: %w", err)
}

// Validate that max replicas >= min replicas
if maxReplicas < minReplicas {
return nil, fmt.Errorf("maximum replicas (%d) must be greater than or equal to minimum replicas (%d)", maxReplicas, minReplicas)
}
selected := tiers[*resp.Value]

return &project.ContainerSettings{
Resources: &project.ResourceSettings{
Memory: memoryResp.Value,
Cpu: cpuResp.Value,
Memory: selected.memory,
Cpu: selected.cpu,
},
Scale: &project.ScaleSettings{
MinReplicas: minReplicas,
MaxReplicas: maxReplicas,
MinReplicas: project.DefaultMinReplicas,
MaxReplicas: project.DefaultMaxReplicas,
},
Comment thread
trangevi marked this conversation as resolved.
}, nil
}
Expand Down
Loading