-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathai.js
38 lines (31 loc) · 1.14 KB
/
ai.js
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
import OpenAI from 'openai';
export async function proposeLabels(issue, availableLabels, { apiKey = null, logger = console }) {
const system_prompt = `
You have a role to manage a GitHub repository. Given an issue information (subject and body), choose suitable labels to it from the labels available for the repository.
Use the following format:
LABELS: "the names of the chosen labels, each name must not be surrounded double quotes, separated by a comma"
Only use the following labels:
\`\`\`
${JSON.stringify(availableLabels, null, 2)}
\`\`\`
`
const user_prompt = `
## ISSUE ##
SUBJECT: ${issue.title}
BODY: ${issue.body}
`;
const client = new OpenAI({ apiKey });
const completion = await client.chat.completions.create({
model: "gpt-4o",
messages: [
{ role: 'system', content: system_prompt },
{ role: 'user', content: user_prompt }
],
temperature: 0,
});
logger.debug(completion.choices[0].message.content);
let labels = /LABELS\: (.+)/g.exec(completion.choices[0].message.content)
labels = labels[1].trim().split(/,\s*/)
logger.debug(labels)
return labels
}