Public
Back
Version 2
9/28/2023
const rateArticleRelevance = async (interests: string, article: any) => {
const { default: OpenAI } = await import("npm:openai");
const openai = new OpenAI({ apiKey: me.secrets.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;
}
};
Updated: October 23, 2023