fix: update workflow to use OpenAI for PR description generation

This commit is contained in:
faris Aljohari
2025-07-16 00:28:20 -06:00
parent 61348aa351
commit 7e2c3136cf

View File

@ -1,4 +1,4 @@
name: 🤖 AI PR Description with HuggingFace Falcon
name: 🤖 AI PR Description Commenter (100% Safe with jq)
on:
pull_request:
@ -27,23 +27,26 @@ jobs:
env:
GH_TOKEN: ${{ secrets.GH_PERSONAL_TOKEN }}
- name: Generate PR Description with HuggingFace Falcon
- name: Generate PR Description with OpenAI (Safe JSON with jq)
run: |
REQUEST_BODY=$(jq -n \
--arg inputs "Given the following commit messages:\n\n${commits}\n\nGenerate a clear and professional pull request description." \
'{ inputs: $inputs }'
--arg model "gpt-4o" \
--arg content "Given the following commit messages:\n\n${commits}\n\nGenerate a clear and professional pull request description." \
'{
model: $model,
messages: [{ role: "user", content: $content }]
}'
)
RESPONSE=$(curl -s https://api-inference.huggingface.co/models/tiiuae/falcon-7b-instruct \
-H "Authorization: Bearer $HUGGINGFACE_API_KEY" \
RESPONSE=$(curl -s https://api.openai.com/v1/chat/completions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d "$REQUEST_BODY")
echo "---------- HuggingFace Raw Response ----------"
DESCRIPTION=$(echo "$RESPONSE" | jq -r '.choices[0].message.content')
echo "---------- OpenAI Raw Response ----------"
echo "$RESPONSE"
DESCRIPTION=$(echo "$RESPONSE" | jq -r 'if type=="array" then .[0].generated_text else .error else "Error: Unexpected response" end')
echo "---------- Extracted Description ----------"
echo "$DESCRIPTION"
@ -51,7 +54,7 @@ jobs:
echo "$DESCRIPTION" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
env:
HUGGINGFACE_API_KEY: ${{ secrets.HUGGINGFACE_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
commits: ${{ env.commits }}
- name: Post AI Generated Description as Comment