/** * @copyright nhcarrigan * @license Naomi's Public License * @author Naomi Carrigan */ // eslint-disable-next-line @typescript-eslint/naming-convention -- 'Tis a class. import Anthropic from "@anthropic-ai/sdk"; /** * Summarises an announcement using AI, to condense the content for platforms like Bluesky and Twitter. * @param title - The title of the announcement. * @param content - The main body of the announcement. * @returns A message indicating the success or failure of the operation. */ export const summarisePost = async( title: string, content: string, ): Promise => { if (process.env.ANTHROPIC_KEY === undefined) { return null; } const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_KEY, timeout: 5 * 60 * 1000, }); const response = await anthropic.messages.create({ // eslint-disable-next-line @typescript-eslint/naming-convention -- API requirement max_tokens: 1000, messages: [ { content: `# ${title}\n\n${content}`, role: "user", }, ], model: "claude-4-sonnet-20250514", // eslint-disable-next-line stylistic/max-len -- This is a long system message. system: "Summarise the post the user provides into a concise message suitable for social media platforms like Bluesky and Twitter. The summary should be engaging and informative, capturing the essence of the announcement. You may use no more than 280 characters, and should include relevant hashtags if appropriate.", }); const text = response.content.find((m) => { return m.type === "text"; }); return text?.text ?? null; };