Skip to content
Open
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
51 changes: 40 additions & 11 deletions cli/azd/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/azure/azure-dev/cli/azd/internal/tracing"
"github.com/azure/azure-dev/cli/azd/internal/tracing/fields"
"github.com/azure/azure-dev/cli/azd/pkg/alpha"
"github.com/azure/azure-dev/cli/azd/pkg/config"
"github.com/azure/azure-dev/cli/azd/pkg/environment"
"github.com/azure/azure-dev/cli/azd/pkg/environment/azdcontext"
"github.com/azure/azure-dev/cli/azd/pkg/exec"
Expand Down Expand Up @@ -141,6 +142,7 @@ type initAction struct {
azd workflow.AzdCommandRunner
agentFactory *agent.AgentFactory
consentManager consent.ConsentManager
configManager config.UserConfigManager
}

func newInitAction(
Expand All @@ -157,6 +159,7 @@ func newInitAction(
azd workflow.AzdCommandRunner,
agentFactory *agent.AgentFactory,
consentManager consent.ConsentManager,
configManager config.UserConfigManager,
) actions.Action {
return &initAction{
lazyAzdCtx: lazyAzdCtx,
Expand All @@ -172,6 +175,7 @@ func newInitAction(
azd: azd,
agentFactory: agentFactory,
consentManager: consentManager,
configManager: configManager,
}
}

Expand Down Expand Up @@ -252,7 +256,7 @@ func (i *initAction) Run(ctx context.Context) (*actions.ActionResult, error) {
initTypeSelect = initEnvironment
} else {
// Prompt for init type for new projects
initTypeSelect, err = promptInitType(i.console, ctx, i.featuresManager)
initTypeSelect, err = promptInitType(i.console, ctx, i.featuresManager, i.configManager)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -590,15 +594,16 @@ const (
initWithAgent
)

func promptInitType(console input.Console, ctx context.Context, featuresManager *alpha.FeatureManager) (initType, error) {
func promptInitType(
console input.Console,
ctx context.Context,
featuresManager *alpha.FeatureManager,
configManager config.UserConfigManager,
) (initType, error) {
options := []string{
"Scan current directory", // This now covers minimal project creation too
"Select a template",
}

// Only include AZD agent option if the LLM feature is enabled
if featuresManager.IsEnabled(llm.FeatureLlm) {
options = append(options, fmt.Sprintf("Use agent mode %s", color.YellowString("(Alpha)")))
fmt.Sprintf("Use agent mode %s", color.YellowString("(Alpha)")),
}

selection, err := console.Select(ctx, input.ConsoleOptions{
Expand All @@ -615,11 +620,35 @@ func promptInitType(console input.Console, ctx context.Context, featuresManager
case 1:
return initAppTemplate, nil
case 2:
// Only return initWithCopilot if the LLM feature is enabled and we have 3 options
if featuresManager.IsEnabled(llm.FeatureLlm) {
return initWithAgent, nil
if !featuresManager.IsEnabled(llm.FeatureLlm) {
azdConfig, err := configManager.Load()
if err != nil {
return initUnknown, fmt.Errorf("failed to load config: %w", err)
}

err = azdConfig.Set("alpha.llm", "on")
if err != nil {
return initUnknown, fmt.Errorf("failed to set alpha.llm config: %w", err)
}

err = configManager.Save(azdConfig)
if err != nil {
return initUnknown, fmt.Errorf("failed to save config: %w", err)
}

console.Message(ctx, "\nThe azd agent feature has been enabled to support this new experience."+
" To turn off in the future run `azd config unset alpha.llm`.")

err = azdConfig.Set("ai.agent.model.type", "github-copilot")
if err != nil {
return initUnknown, fmt.Errorf("failed to set ai.agent.model.type config: %w", err)
}
Comment on lines +642 to +645
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be called before calling configManager.Save(...) ???

I don't see a new call to save the config after this, so the setting might be applied only on memory but not persisted?


console.Message(ctx, "\nGitHub Copilot has been enabled to support this new experience."+
" To turn off in the future run `azd config unset ai.agent.model.type`.")
}
fallthrough

return initWithAgent, nil
default:
panic("unhandled selection")
}
Expand Down
3 changes: 2 additions & 1 deletion cli/azd/pkg/llm/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ func (m Manager) GetDefaultModel(ctx context.Context, opts ...ModelOption) (*Mod

defaultModelType, ok := userConfig.GetString("ai.agent.model.type")
if !ok {
return nil, fmt.Errorf("Default model type has not been set")
return nil, fmt.Errorf("Default model type has not been set. Set the agent model type with" +
" `azd config set ai.agent.model.type github-copilot`.")
}

return m.ModelFactory.CreateModelContainer(ctx, LlmType(defaultModelType), opts...)
Expand Down
Loading