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
import process from "node:process";
export const rateArticleRelevance = async (interests: string, article: any) => {
const { default: OpenAI } = await import("npm:openai");
const openai = new OpenAI({ apiKey: process.env.OPENAI_KEY });
try {
const prompt = `I am interested in ${interests}.
Am I going to like this article?
Article Title: ${article.title}.
Article Description: ${article.description}.
Give a score from 0 to 10. Why did you give this score? Respond with the score only.
`;
const response = await openai.chat.completions.create({
messages: [
{
role: "system",
content: `You are a helpful assistant who rates RSS feeds for possible interest to a user,
they will list their interests and you produce a score,
further detail will be provided in the user prompt`,
},
{ role: "user", content: prompt },
],
model: "gpt-3.5-turbo",
temperature: 0.7,
});
const score = parseInt(response.choices[0].message.content, 10);
if (isNaN(score)) {
throw new Error("Failed to parse the score as a number.");
}
return score;
}
catch (error) {
return 0;
}
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 25, 2023