-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
58 lines (51 loc) · 1.27 KB
/
index.ts
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
import { Github } from './github';
const organization = process.env.ORGANIZATION;
const repo = process.env.REPO;
const token = process.env.GITHUB_PERSONAL_ACCESS_TOKEN;
const author = process.env.AUTHOR;
const until = new Date().toISOString();
const since = until.replace(/T.*/, 'T00:00:00Z');
const reporter = new Github({ token });
const prefix = (report: string) => {
return `
${report}
Can you fix the grammer and make it more natural and detail it?
`;
};
const log = (raw: string, report: string) => {
console.log(`
Raw report:
${raw}
Formatted report:
${report}
`);
};
const report = await reporter.generateDailyReport({
organization,
repo,
author,
since,
until,
});
const gpturl = 'https://api.openai.com/v1/chat/completions';
const params = {
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: prefix(report) }],
temperature: 0.7,
};
try {
const data = await fetch(gpturl, {
verbose: true,
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
},
body: JSON.stringify(params),
});
const chatCompletion = await data.json();
const content = chatCompletion.choices[0].message.content;
log(report, content);
} catch (e) {
console.log({ e });
}