File tree Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change
1
+ name : AI Issue Responder
2
+
3
+ on :
4
+ issues :
5
+ types : [opened]
6
+
7
+ permissions :
8
+ issues : write
9
+
10
+ jobs :
11
+ ai-respond :
12
+ if : github.actor != 'dependabot[bot]'
13
+ runs-on : ubuntu-latest
14
+
15
+ steps :
16
+ - name : Get issue content
17
+ id : get_issue
18
+ run : |
19
+ title=$(echo "${{ github.event.issue.title }}" | jq -Rsa .)
20
+ body=$(echo "${{ github.event.issue.body }}" | jq -Rsa .)
21
+ echo "title=$title" >> "$GITHUB_OUTPUT"
22
+ echo "body=$body" >> "$GITHUB_OUTPUT"
23
+
24
+ - name : Call OpenAI API
25
+ id : ai
26
+ env :
27
+ OPENAI_API_KEY : ${{ secrets.OPENAI_API_KEY }}
28
+ run : |
29
+ prompt="You're a helpful AI assistant. Reply concisely to the following GitHub issue."
30
+ input="${{ steps.get_issue.outputs.title }} - ${{ steps.get_issue.outputs.body }}"
31
+
32
+ json=$(jq -n \
33
+ --arg model "gpt-4o" \
34
+ --arg system "$prompt" \
35
+ --arg user "$input" \
36
+ '{
37
+ model: $model,
38
+ messages: [
39
+ {role: "system", content: $system},
40
+ {role: "user", content: $user}
41
+ ],
42
+ temperature: 0.5
43
+ }')
44
+
45
+ response=$(curl -s https://api.openai.com/v1/chat/completions \
46
+ -H "Authorization: Bearer $OPENAI_API_KEY" \
47
+ -H "Content-Type: application/json" \
48
+ -d "$json" | jq -r '.choices[0].message.content')
49
+
50
+ echo "reply=$response" >> "$GITHUB_OUTPUT"
51
+
52
+ - name : Reply to issue
53
+ run : |
54
+ curl -s -X POST \
55
+ -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
56
+ -H "Accept: application/vnd.github.v3+json" \
57
+ https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments \
58
+ -d "$(jq -n --arg body "${{ steps.ai.outputs.reply }}" '{body: $body}')"
You can’t perform that action at this time.
0 commit comments