From 70d8979f32545df47055c1b59b4d20becdab6815 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Wed, 3 Jul 2024 20:10:10 +0200 Subject: [PATCH] ci: add pipelines for discord notifications Signed-off-by: Ettore Di Giacinto --- .github/workflows/notify-models.yaml | 88 ++++++++++++++++++++++++++ .github/workflows/notify-releases.yaml | 65 +++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 .github/workflows/notify-models.yaml create mode 100644 .github/workflows/notify-releases.yaml diff --git a/.github/workflows/notify-models.yaml b/.github/workflows/notify-models.yaml new file mode 100644 index 000000000000..a8bb63be0e90 --- /dev/null +++ b/.github/workflows/notify-models.yaml @@ -0,0 +1,88 @@ +name: Notifications for new models +on: + pull_request: + # types: + # - closed + +jobs: + notify-discord: +# if: ${{ (github.event.pull_request.merged == true) && (contains(github.event.pull_request.labels.*.name, 'area/ai-model')) }} + 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: "Write a discord message to notify everyone about the new model from the git diff. Make it informal. An example can include: the URL of the model, the name, and a brief description of the model if exists." + }, + { + 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: Discord notification + env: + DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }} + DISCORD_USERNAME: "LocalAI-Bot" + DISCORD_AVATAR: "https://avatars.githubusercontent.com/u/139863280?v=4" + uses: Ilshidur/action-discord@master + with: + args: ${{ steps.summarize.outputs.message }} + - name: Setup tmate session if fails + if: ${{ failure() }} + uses: mxschmitt/action-tmate@v3.18 + with: + detached: true + connect-timeout-seconds: 180 + limit-access-to-actor: true \ No newline at end of file diff --git a/.github/workflows/notify-releases.yaml b/.github/workflows/notify-releases.yaml new file mode 100644 index 000000000000..b4f1ef62463a --- /dev/null +++ b/.github/workflows/notify-releases.yaml @@ -0,0 +1,65 @@ +name: Release notifications +on: + release: + types: + - published + +jobs: + notify-discord: + runs-on: ubuntu-latest + env: + RELEASE_BODY: ${{ github.event.release.body }} + RELEASE_TITLE: ${{ github.event.release.name }} + RELEASE_TAG_NAME: ${{ github.event.release.tag_name }} + steps: + - 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 + - name: Summarize + id: summarize + run: | + input="$RELEASE_TITLE\b$RELEASE_BODY" + + # 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: "Write a discord message with a bullet point summary of the release notes." + }, + { + role: "user", + content: $input + } + ] + }') + + # Send the request to LocalAI API + 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 'message<> "$GITHUB_OUTPUT" + - name: Discord notification + env: + DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }} + DISCORD_USERNAME: "LocalAI-Bot" + DISCORD_AVATAR: "https://avatars.githubusercontent.com/u/139863280?v=4" + uses: Ilshidur/action-discord@master + with: + args: ${{ steps.summarize.outputs.message }} \ No newline at end of file