From 8f3af78612d85c1014e27e5cc1f72bd46076e399 Mon Sep 17 00:00:00 2001 From: vagrant Date: Tue, 16 Jul 2024 06:47:13 +0000 Subject: [PATCH] Removed unused items from the configuration file and added the ability to validate subcommands --- cmd/main.go | 17 ++++++++++++----- internal/config/config.yaml | 11 +++-------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 48d0073..e10c76f 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -4,6 +4,7 @@ import ( "flag" "log" "os" + "strings" "github.com/3-shake/alert-menta/internal/ai" "github.com/3-shake/alert-menta/internal/github" @@ -17,10 +18,7 @@ func main() { owner = flag.String("owner", "", "Repository owner") issueNumber = flag.Int("issue", 0, "Issue number") intent = flag.String("intent", "", "Question or intent for the 'ask' command") - command = flag.String("command", "", `Command to be executed by AI - describe: Generate a detailed description of the Issue. - suggest: Provide suggestions for improvement based on the contents of the Issue. - ask: Answer free-text questions.`) + command = flag.String("command", "", "Commands to be executed by AI.Commands defined in the configuration file are available.") configFile = flag.String("config", "./internal/config/config.yaml", "Configuration file") gh_token = flag.String("github-token", "", "GitHub token") oai_key = flag.String("api-key", "", "OpenAI api key") @@ -38,12 +36,21 @@ func main() { log.Ldate|log.Ltime|log.Llongfile|log.Lmsgprefix, ) - // Get configuration + // Load configuration cfg, err := utils.NewConfig(*configFile) if err != nil { logger.Fatalf("Error creating comment: %s", err) } + // Validate command + if _, ok := cfg.Ai.Commands[*command]; !ok { + allowedCommands := make([]string, 0, len(cfg.Ai.Commands)) + for cmd := range cfg.Ai.Commands { + allowedCommands = append(allowedCommands, cmd) + } + logger.Fatalf("Invalid command: %s. Allowed commands are %s.", *command, strings.Join(allowedCommands, ", ")) + } + // Create a GitHub Issues instance. From now on, you can control GitHub from this instance. issue := github.NewIssue(*owner, *repo, *issueNumber, *gh_token) if issue == nil { diff --git a/internal/config/config.yaml b/internal/config/config.yaml index 52ffb96..aa7d1a5 100644 --- a/internal/config/config.yaml +++ b/internal/config/config.yaml @@ -1,12 +1,7 @@ system: debug: - mode: True log_level: debug -github: - owner: "pacificbelt30" - repo: "alert-menta" - ai: provider: "openai" # "openai" or "vertexai" openai: @@ -19,11 +14,11 @@ ai: commands: - describe: - description: "Describe the GitHub Issues" + description: "Generate a detailed description of the Issue." system_prompt: "The following is the GitHub Issue and comments on it. Please Generate a detailed description.\n" - suggest: - description: "Provide suggestions for improvement based on the contents of the Issue" + description: "Provide suggestions for improvement based on the contents of the Issue." system_prompt: "The following is the GitHub Issue and comments on it. Please identify the issues that need to be resolved based on the contents of the Issue and provide three suggestions for improvement.\n" - ask: - description: "Ask a question about the GitHub Issue" + description: "Answer free-text questions." system_prompt: "The following is the GitHub Issue and comments on it. Based on the content provide a detailed response to the following question:\n" \ No newline at end of file