Skip to content

Commit

Permalink
Merge branch 'develop' into feature/insert_image_to_prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
pacificbelt30 committed Jul 25, 2024
2 parents c06cfb0 + 9eef742 commit c494184
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 49 deletions.
19 changes: 7 additions & 12 deletions internal/config/config.yaml β†’ .alert-menta.user.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
system:
debug:
mode: True
log_level: debug

github:
owner: "pacificbelt30"
repo: "alert-menta"

ai:
provider: "openai" # "openai" or "vertexai"
openai:
Expand All @@ -19,11 +14,11 @@ ai:

commands:
- describe:
description: "Describe the GitHub Issues"
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."
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."
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"
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"
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"
54 changes: 30 additions & 24 deletions .github/workflows/alert-menta.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: Reacts to specific labels
run-name: ${{ github.actor }} is testing out GitHub Actions πŸš€
name: "Alert-Menta: Reacts to specific commands"
run-name: LLM responds to issues against the repository.πŸš€

on:
issues:
types: [labeled] # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#issues
issue_comment:
types: [created]

jobs:
Issue_Reaction:
if: contains(github.event.issue.labels.*.name, '/describe') || contains(github.event.issue.labels.*.name, '/improve') # https://docs.github.com/ja/webhooks/webhook-events-and-payloads#issues
runs-on: ubuntu-22.04 # https://docs.github.com/ja/actions/using-jobs/choosing-the-runner-for-a-job
Alert-Menta:
if: startsWith(github.event.comment.body, '/describe') || startsWith(github.event.comment.body, '/suggest') || startsWith(github.event.comment.body, '/ask')
runs-on: ubuntu-22.04
permissions:
issues: write
contents: read
Expand All @@ -20,31 +20,37 @@ jobs:
run: |
curl -sLJO -H 'Accept: application/octet-stream' \
"https://${{ secrets.GH_TOKEN }}@api.github.com/repos/3-shake/alert-menta/releases/assets/$( \
curl -sL "https://${{ secrets.GH_TOKEN }}@api.github.com/repos/3-shake/alert-menta/releases/tags/v0.0.1" \
curl -sL "https://${{ secrets.GH_TOKEN }}@api.github.com/repos/3-shake/alert-menta/releases/tags/v0.0.3" \
| jq '.assets[] | select(.name | contains("Linux_x86")) | .id')"
tar -zxvf alert-menta_Linux_x86_64.tar.gz
- name: Set Command describe
id: describe
if: contains(github.event.issue.labels.*.name, '/describe')
run: |
echo "COMMAND=describe" >> $GITHUB_ENV
- name: Set Command improve
id: improve
if: steps.describe.conclusion == 'skipped' || contains(github.event.issue.labels.*.name, '/improve')
- name: Set Command
id: set_command
run: |
echo "COMMAND=improve" >> $GITHUB_ENV
COMMENT_BODY="${{ github.event.comment.body }}"
if [[ "$COMMENT_BODY" == /ask* ]]; then
COMMAND=ask
INTENT=${COMMENT_BODY:5}
echo "INTENT=$INTENT" >> $GITHUB_ENV
elif [[ "$COMMENT_BODY" == /describe* ]]; then
COMMAND=describe
elif [[ "$COMMENT_BODY" == /suggest* ]]; then
COMMAND=suggest
fi
echo "COMMAND=$COMMAND" >> $GITHUB_ENV
- run: echo "REPOSITORY_NAME=${GITHUB_REPOSITORY#${GITHUB_REPOSITORY_OWNER}/}" >> $GITHUB_ENV

- name: Get user defined config file
id: user_config
if: hashFiles('.alert-menta.user.yaml') != ''
run: |
echo "CONFIG_FILE=.alert-menta.user.yaml" >> $GITHUB_ENV
- name: Get default config file
if: steps.user_config.conclusion == 'skipped' && hashFiles('./internal/config/config.yaml') != ''
run: |
echo "CONFIG_FILE=./internal/config/config.yaml" >> $GITHUB_ENV
curl -H "Authorization: token ${{ secrets.GH_TOKEN }}" -L -o .alert-menta.user.yaml "https://raw.githubusercontent.com/${{ github.repository_owner }}/${{ env.REPOSITORY_NAME }}/main/.alert-menta.user.yaml" && echo "CONFIG_FILE=./.alert-menta.user.yaml" >> $GITHUB_ENV
- name: Add Comment
run: |
./alert-menta -owner ${{ github.repository_owner }} -issue ${{ github.event.issue.number }} -repo ${{ env.REPOSITORY_NAME }} -github-token ${{ secrets.GITHUB_TOKEN }} -api-key ${{ secrets.OPENAI_API_KEY }} -command $COMMAND -config $CONFIG_FILE
if [[ "$COMMAND" == "ask" ]]; then
./alert-menta -owner ${{ github.repository_owner }} -issue ${{ github.event.issue.number }} -repo ${{ env.REPOSITORY_NAME }} -github-token ${{ secrets.GH_TOKEN }} -api-key ${{ secrets.OPENAI_API_KEY }} -command $COMMAND -config $CONFIG_FILE -intent $INTENT
else
./alert-menta -owner ${{ github.repository_owner }} -issue ${{ github.event.issue.number }} -repo ${{ env.REPOSITORY_NAME }} -github-token ${{ secrets.GH_TOKEN }} -api-key ${{ secrets.OPENAI_API_KEY }} -command $COMMAND -config $CONFIG_FILE
fi
31 changes: 18 additions & 13 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"os"
"regexp"
"strings"

"github.com/3-shake/alert-menta/internal/ai"
"github.com/3-shake/alert-menta/internal/github"
Expand All @@ -18,18 +19,14 @@ 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.
analyze: Perform a root cause analysis based on the contents of the Issue.
suggest: Provide suggestions for improvement based on the contents of the Issue.
ask: Answer free-text questions.`)
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")
command = flag.String("command", "", "Commands to be executed by AI.Commands defined in the configuration file are available.")
configFile = flag.String("config", "", "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 || *gh_token == "" || *oai_key == "" || *command == "" {
if *repo == "" || *owner == "" || *issueNumber == 0 || *gh_token == "" || *oai_key == "" || *command == "" || *configFile == "" {
flag.PrintDefaults()
os.Exit(1)
}
Expand All @@ -40,12 +37,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 {
Expand All @@ -70,8 +76,8 @@ func main() {

// Get comments under the Issue and add them to the user prompt except for comments by Actions.
images := []ai.Image{}
comments, _ := issue.GetComments()
if err != nil || comments == nil {
comments, err := issue.GetComments()
if err != nil {
logger.Fatalf("Error getting comments: %v", err)
}
for _, v := range comments {
Expand Down Expand Up @@ -102,7 +108,6 @@ func main() {
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)
Expand Down

0 comments on commit c494184

Please sign in to comment.