Public
Back
Version 49
6/12/2024
import { getTweets } from "https://esm.town/v/geoffreylitt/getTweets";
import { email } from "https://esm.town/v/std/email?v=12";
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
import { discordWebhook } from "https://esm.town/v/stevekrouse/discordWebhook";
import { twitterSearch } from "https://esm.town/v/stevekrouse/twitterSearch";
const usernames = ["stevekrouse", "worrydream"];
const openai = new OpenAI();
export async function twitterAlert({ lastRunAt }: Interval) {
let results = [];
for (const username of usernames) {
const tweets = await getTweets(username);
results = results.concat(tweets.data.map(tweet => ({ ...tweet, username })));
}
// Placeholder function for LLM filtering
async function filterTweets(tweets) {
const completion = await openai.chat.completions.create({
messages: [
{
role: "system",
content:
`You'll be given a list of tweets as JSON. I want you to filter the list and return a JSON array of IDs, plus a headline for the filtered list: { headline: string; ids: string[] } The filter criteria are:
I want to hear about important tweets sharing major updates, new projects, new papers or essays, website updates, etc. I don't want to see shitposts or jokes.
The headline should be short for an email subject, like 10 words, tease who said what with specifics of what they said.`,
},
{ role: "user", content: JSON.stringify(results) },
],
model: "gpt-4o",
response_format: { type: "json_object" },
});
const parsed = JSON.parse(completion.choices[0].message.content);
return { tweets: tweets.filter(tweet => parsed.ids.includes(tweet.id)), headline: parsed.headline };
Updated: June 12, 2024