From f521e50fa810b2c47885897cc4c3acb8afcf503f Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Tue, 16 Jul 2024 18:49:23 +0200 Subject: [PATCH] ci: add workflow to comment new Opened PRs (#2892) * ci: add workflow to comment new Opened PRs Signed-off-by: Ettore Di Giacinto * Update comment-pr.yaml eliminate a stray ' character that was terminating the shell script by slightly rewriting the prompt Signed-off-by: Dave --------- Signed-off-by: Ettore Di Giacinto Signed-off-by: Dave Co-authored-by: Dave --- .github/workflows/comment-pr.yaml | 75 +++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 .github/workflows/comment-pr.yaml diff --git a/.github/workflows/comment-pr.yaml b/.github/workflows/comment-pr.yaml new file mode 100644 index 00000000..78e3e5ec --- /dev/null +++ b/.github/workflows/comment-pr.yaml @@ -0,0 +1,75 @@ +name: Comment PRs +on: + pull_request: + +jobs: + comment-pr: + env: + MODEL_NAME: hermes-2-theta-llama-3-8b + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # needed to checkout all branches for this Action to work + - name: Start LocalAI + run: | + echo "Starting LocalAI..." + docker run -e -ti -d --name local-ai -p 8080:8080 localai/localai:master-ffmpeg-core run --debug $MODEL_NAME + until [ "`docker inspect -f {{.State.Health.Status}} local-ai`" == "healthy" ]; do echo "Waiting for container to be ready"; docker logs --tail 10 local-ai; sleep 2; done + # Check the PR diff using the current branch and the base branch of the PR + - uses: GrantBirki/git-diff-action@v2.7.0 + id: git-diff-action + with: + json_diff_file_output: diff.json + raw_diff_file_output: diff.txt + file_output_only: "true" + - name: Summarize + env: + DIFF: ${{ steps.git-diff-action.outputs.raw-diff-path }} + id: summarize + run: | + input="$(cat $DIFF)" + + # Define the LocalAI API endpoint + API_URL="http://localhost:8080/chat/completions" + + # Create a JSON payload using jq to handle special characters + json_payload=$(jq -n --arg input "$input" '{ + model: "'$MODEL_NAME'", + messages: [ + { + role: "system", + content: "You are LocalAI-bot in Github that helps understanding PRs and assess complexity. Explain what has changed in this PR diff and why" + }, + { + role: "user", + content: $input + } + ] + }') + + # Send the request to LocalAI + response=$(curl -s -X POST $API_URL \ + -H "Content-Type: application/json" \ + -d "$json_payload") + + # Extract the summary from the response + summary="$(echo $response | jq -r '.choices[0].message.content')" + + # Print the summary + # -H "Authorization: Bearer $API_KEY" \ + echo "Summary:" + echo "$summary" + echo "payload sent" + echo "$json_payload" + { + echo 'message<> "$GITHUB_OUTPUT" + docker logs --tail 10 local-ai + - name: Comment PR with execution number + uses: thollander/actions-comment-pull-request@v2 + with: + message: ${{ steps.summarize.outputs.message }} + comment_tag: execution