Skip to content
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

Implementation of ask command #3

Merged
merged 3 commits into from
Jul 11, 2024
Merged
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
33 changes: 27 additions & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func main() {
repo = flag.String("repo", "", "Repository name")
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")
configFile = flag.String("config", "./internal/config/config.yaml", "Configuration file")
gh_token = flag.String("github-token", "", "GitHub token")
Expand All @@ -34,9 +35,6 @@ func main() {
log.Ldate|log.Ltime|log.Llongfile|log.Lmsgprefix,
)

// Pre-define variables for error handling
var err error

// Get configuration
cfg, err := utils.NewConfig(*configFile)
if err != nil {
Expand All @@ -45,10 +43,19 @@ func main() {

// 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 {
logger.Fatalf("Failed to create GitHub issue instance")
}

// Get Issue's information(e.g. Title, Body) and add them to the user prompt except for comments by Actions.
title, _ := issue.GetTitle()
body, _ := issue.GetBody()
title, err := issue.GetTitle()
if err != nil {
logger.Fatalf("Error getting Title: %v", err)
}
body, err := issue.GetBody()
if err != nil {
logger.Fatalf("Error getting Body: %v", err)
}
if cfg.System.Debug.Log_level == "debug" {
logger.Println("Title:", *title)
logger.Println("Body:", *body)
Expand All @@ -58,6 +65,9 @@ func main() {

// Get comments under the Issue and add them to the user prompt except for comments by Actions.
comments, _ := issue.GetComments()
if err != nil || comments == nil {
logger.Fatalf("Error getting comments: %v", err)
}
for _, v := range comments {
if *v.User.Login == "github-actions[bot]" {
continue
Expand All @@ -69,7 +79,18 @@ func main() {
}

// Set system prompt
system_prompt := cfg.Ai.Commands[*command].System_prompt
var system_prompt string
if *command == "ask" {
if *intent == "" {
log.SetOutput(os.Stdout)
logger.Println("Error: intent is required for 'ask' command")
flag.PrintDefaults()
os.Exit(1)
}
system_prompt = cfg.Ai.Commands[*command].System_prompt + *intent
} else {
system_prompt = cfg.Ai.Commands[*command].System_prompt
}
prompt := ai.Prompt{UserPrompt: user_prompt, SystemPrompt: system_prompt}
logger.Println("\x1b[34mPrompt: |\n", prompt.SystemPrompt, prompt.UserPrompt, "\x1b[0m")

Expand Down
7 changes: 5 additions & 2 deletions internal/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ github:
repo: "alert-menta"

ai:
provider: "vertexai" # "openai" or "vertexai"
provider: "openai" # "openai" or "vertexai"
openai:
model: "gpt-3.5-turbo" # Check the list of available models by `curl https://api.openai.com/v1/models -H "Authorization: Bearer $OPENAI_API_KEY"`

Expand All @@ -23,4 +23,7 @@ ai:
system_prompt: "The following is the GitHub Issue and comments on it. Please summarize the conversation and suggest what issues need to be resolved.\n"
- improve:
description: "Improve the GitHub Issues"
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."
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."
- ask:
description: "Ask a question about the GitHub Issue"
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"
Loading