diff --git a/cmd/main.go b/cmd/main.go index 346f67d..60aa246 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -17,12 +17,13 @@ func main() { owner = flag.String("owner", "", "Repository owner") issueNumber = flag.Int("issue", 0, "Issue number") command = flag.String("command", "", "Command to be executed by AI") - token = flag.String("token", "", "GitHub token") 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") ) flag.Parse() - if *repo == "" || *owner == "" || *issueNumber == 0 || *token == "" || *command == "" { + if *repo == "" || *owner == "" || *issueNumber == 0 || *gh_token == "" || *oai_key == "" || *command == "" { flag.PrintDefaults() os.Exit(1) } @@ -41,7 +42,7 @@ func main() { } // Create GitHub Issues instance - issue := github.NewIssue(*owner, *repo, *issueNumber, *token) + issue := github.NewIssue(*owner, *repo, *issueNumber, *gh_token) // Get Issue's info title, _ := issue.GetTitle() @@ -65,7 +66,7 @@ func main() { // Get response from OpenAI logger.Println("Prompt:", system_prompt, user_prompt) - ai := ai.NewOpenAIClient("", cfg.Ai.Model) + ai := ai.NewOpenAIClient(*oai_key, cfg.Ai.Model) comment, _ := ai.GetResponse(system_prompt + user_prompt) logger.Println("Response:", comment) diff --git a/internal/ai/openai.go b/internal/ai/openai.go index 96f3d68..18817de 100644 --- a/internal/ai/openai.go +++ b/internal/ai/openai.go @@ -3,7 +3,6 @@ package ai import ( "context" "fmt" - "os" "github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai" "github.com/Azure/azure-sdk-for-go/sdk/azcore" @@ -45,13 +44,11 @@ func (ai *OpenAI) GetResponse(prompt string) (string, error) { func NewOpenAIClient(apiKey string, model string) *OpenAI { // Set the OpenAI API key (read from the environment variable) - apiKey = os.Getenv("OPENAI_API_KEY") if apiKey == "" { fmt.Println("Error: OPENAI_API_KEY environment variable not set.") return nil } // Specifying the model to use - model = "gpt-3.5-turbo" return &OpenAI{ apiKey: apiKey, model: model,