-
Notifications
You must be signed in to change notification settings - Fork 48
88 lines (76 loc) · 3.1 KB
/
assistant.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: Assistant
on:
issue_comment:
types: [created, edited]
jobs:
modify_comment:
runs-on: ubuntu-latest
steps:
- name: Respond to chatbot requests
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
if (context.payload.comment.body.startsWith("/assistant")) {
const issue = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
})
const issueComments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number
})
const dialogue = []
let issueDescription = `# Issue Title: ${issue.data.title}\n\n`
issueDescription += `* **Author**: ${issue.data.user.login}\n`
issueDescription += `* **Date**: ${issue.data.created_at}\n\n`
issueDescription += `## Issue Description\n${issue.data.body}\n\n`
issueDescription += '## Discussion\n\n'
for (const comment of issueComments.data) {
if (comment.id != context.payload.comment.id) {
issueDescription += `### Comment by ${comment.user.login}\n`
issueDescription += `* **Date**: ${comment.created_at}\n\n`
issueDescription += `${comment.body.replace(/^\/assistant\s*/i, "")}\n\n`
} else {
dialogue.push({
role: 'user',
content: issueDescription
})
dialogue.push({
role: 'user',
content: `${comment.body.replace(/^\/assistant\s*/i, "")}`
})
break
}
}
console.log(dialogue)
const post_response = await fetch(
"https://api.openai.com/v1/chat/completions",
{
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${{ secrets.OPENAI_API_KEY }}`
},
body: JSON.stringify({
model: "gpt-4",
messages: [
{
role: "system",
content: "You are a helpful consultant to people in the discussion below."
},
...dialogue
]
})
}
)
const assistant_response = await post_response.json()
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
body: assistant_response.choices[0].message.content
})
}