-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_quote.ts
41 lines (31 loc) · 946 Bytes
/
generate_quote.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
import { getQuoteConfig } from "../_lib/quote_config.ts";
import { isQuoteUnseen } from "../_lib/quote_store.ts";
import { setQuote } from "../_lib/quote_store.ts";
import OpenAI from "openai";
export const name = "Generate a new quote of the moment";
const config = getQuoteConfig();
export const schedule = config.schedule;
export default async function generateQuote() {
if (await isQuoteUnseen()) {
console.log("Skipping quote generation");
return;
}
console.log("Generating a new quote...");
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
model: config.model,
temperature: config.temperature,
messages: [
{
role: "user",
content: config.prompt,
},
],
});
const content = completion?.choices[0]?.message.content;
if (content) {
console.log(content);
await setQuote(content);
}
}
export const init = generateQuote;