-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
37 lines (31 loc) · 928 Bytes
/
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
import OpenAI from "openai";
import dotenv from "dotenv";
import { consolidateNews } from "./functions/recentNews"
dotenv.config();
const openai = new OpenAI({
organization: 'org-poO0RFtzdp5bFNMdsdDTefbV',
apiKey: process.env.OPENAI_API_KEY,
});
async function main() {
const recentNews: string = await consolidateNews(
{
source: 'ann',
numArticles: 3
}
);
// AI stuff
const stream = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
messages: [
{
role: "user",
content: "Summarize the following news articles. Each summary should be 2 to 3 sentences and separated into its own paragraph:\n" + recentNews
}
],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || "");
}
}
main();