-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add pipelines for discord notifications
Signed-off-by: Ettore Di Giacinto <[email protected]>
- Loading branch information
Showing
2 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
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: | ||
- name: Start LocalAI | ||
run: | | ||
echo "Starting LocalAI..." | ||
docker run -e -ti -d --name local-ai -p 8080:8080 localai/localai:latest-aio-cpu run --debug $MODEL_NAME | ||
until [ "`docker inspect -f {{.State.Health.Status}} local-ai`"=="healthy" ]; do | ||
echo "Waiting for container to be ready" | ||
sleep 2; | ||
done; | ||
# Check the PR diff using the current branch and the base branch of the PR | ||
- uses: GrantBirki/[email protected] | ||
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: | | ||
# Read the content of file.txt | ||
input="$DIFF" | ||
# Define the OpenAI 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." | ||
}, | ||
{ | ||
role: "user", | ||
content: $input | ||
} | ||
] | ||
}') | ||
# Send the request to OpenAI 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 "Summary:" | ||
echo "$summary" | ||
echo "message=$summary\n" >> $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 }} | ||
- name: Setup tmate session if fails | ||
if: ${{ failure() }} | ||
uses: mxschmitt/[email protected] | ||
with: | ||
detached: true | ||
connect-timeout-seconds: 180 | ||
limit-access-to-actor: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
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:latest-aio-cpu run --debug $MODEL_NAME | ||
until [ "`docker inspect -f {{.State.Health.Status}} local-ai`"=="healthy" ]; do | ||
echo "Waiting for container to be ready" | ||
sleep 2; | ||
done; | ||
- name: Summarize | ||
id: summarize | ||
run: | | ||
# Read the content of file.txt | ||
input="$RELEASE_TITLE\b$RELEASE_BODY" | ||
# Define the OpenAI 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 OpenAI 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 "Summary:" | ||
echo "$summary" | ||
echo "message=$summary\n" >> $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 }} |