From 9aec1b3a61acd1425f5e7a18a5ddb3d24a1cf239 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Thu, 4 Jul 2024 17:50:53 +0200 Subject: [PATCH] ci: try to add twitter notifications for new models Signed-off-by: Ettore Di Giacinto --- .github/workflows/notify-models.yaml | 80 ++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/.github/workflows/notify-models.yaml b/.github/workflows/notify-models.yaml index d5f0cb8c..c215c76f 100644 --- a/.github/workflows/notify-models.yaml +++ b/.github/workflows/notify-models.yaml @@ -86,3 +86,83 @@ jobs: detached: true connect-timeout-seconds: 180 limit-access-to-actor: true + notify-twitter: + 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: "You are LocalAI-bot. Write a twitter message to notify everyone about the new model from the git diff. Make it informal and really short. An example can include: the name, and a brief description of the model if exists. Also add an hint on how to install it in LocalAI. For example: local-ai run model_name_here" + }, + { + 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 + - uses: ethomson/send-tweet-action@v1 + with: + status: ${{ steps.summarize.outputs.message }} + consumer-key: ${{ secrets.TWITTER_CONSUMER_API_KEY }} + consumer-secret: ${{ secrets.TWITTER_CONSUMER_API_SECRET }} + access-token: ${{ secrets.TWITTER_ACCESS_TOKEN }} + access-token-secret: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} + - 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