Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
regismesquita committed Aug 7, 2024
0 parents commit 54371c1
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
1- Add a secret for actions on your github repository with your Telnyx Token at TELNYXAI_TOKEN

2- Create the following file on your repository `.github/workflows/review_pr.yml`

```
name: PR Review
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
pull-requests: write
jobs:
review:
runs-on: ubuntu-latest
steps:
- name: PR Review
uses: team-telnyx/reviewpr@main
with:
telnyxai_token: ${{ secrets.TELNYXAI_TOKEN }}
model_name: 'meta-llama/Meta-Llama-3.1-8B-Instruct'
```

Done , The next time a PR is open it will be automatically reviewed by Telnyx Inference.
63 changes: 63 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: 'PR Review Action'
description: 'A GitHub Action to review pull requests using Telnyx AI'
author: 'team-telnyx'
inputs:
telnyxai_token:
description: 'Telnyx AI Token'
required: true
model_name:
description: 'Model Name'
required: true
runs:
using: 'composite'
steps:
- name: Install prerequisites
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y jq curl
- name: Review PR
shell: bash
run: |
echo "Reviewing PR in $GITHUB_REPOSITORY"
# Get the diff of the current branch against the base branch
pr_diff=$(gh pr diff ${{ github.event.number }} --patch | grep -vE "^$" | jq -Rsa . | sed -E 's/(^.)|(.$)//g')
echo "Building payload"
json_payload=$(cat <<EOF
{
"model": "$MODEL_NAME",
"messages": [{"role": "user", "content": "Review this PR for me, be descriptive but straightforward, tell me what it does, a brief summary of the changes and if there are any reasons to reject this PR: \n$pr_diff"}]
}
EOF
)
# Query TelnyxInference and extract only the response content
response=$(curl -s https://api.telnyx.com/v2/ai/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TELNYXAI_TOKEN" \
-d "$json_payload" | jq -r ".choices[].message.content")
if [ $? -ne '0' ]; then
echo "Unable to contact TelnyxInference"
echo "Exiting with status 0 so we don't block merges and this is probably caused by a large diff"
exit 0
fi
# Publish the review comment using gh CLI
set +e
gh pr comment ${{ github.event.number }} -b "Automated $MODEL_NAME review: $response" --edit-last
if [ $? -ne '0' ]; then
gh pr comment ${{ github.event.number }} -b "Automated $MODEL_NAME review: $response"
fi
set -e
env:
TELNYXAI_TOKEN: ${{ inputs.telnyxai_token }}
MODEL_NAME: ${{ inputs.model_name }}
GITHUB_SHA: ${{ github.sha }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}

0 comments on commit 54371c1

Please sign in to comment.