Search
Code3,021
We charge a 50% markup on top of raw LLM costs. If you use $10 in Towniecredits, Anthropic will get $6.66 and we'll get $3.33. We think this is fair,sustainable, and transparent. We don't want to be in the business of havingmurky limits, obfuscated credits, or unsustainable margins.
import { Bot } from "https://deno.land/x/grammy@v1.35.0/mod.ts";import { DateTime } from "https://esm.sh/luxon@3.4.4";import Anthropic from "npm:@anthropic-ai/sdk@0.24.3";import { backstory } from "../backstory.ts";import {} from "../memoryUtils.ts";async function generateBriefingContent(anthropic, memories, today, isSunday) { try { const weekdaysHelp = generateWeekDays(today); }; console.log("Sending prompt to Anthropic...", userMessage); const response = await anthropic.messages.create({ model: "claude-3-7-sonnet-latest", max_tokens: 30000,export async function sendDailyBriefing(chatId?: string, today?: DateTime) { // Get API keys from environment const apiKey = Deno.env.get("ANTHROPIC_API_KEY"); const telegramToken = Deno.env.get("TELEGRAM_TOKEN"); if (!apiKey) { console.error("Anthropic API key is not configured."); return; } } // Initialize Anthropic client const anthropic = new Anthropic({ apiKey }); // Initialize Telegram bot // Generate briefing content const content = await generateBriefingContent( anthropic, memories, today,You'll need to set up some environment variables to make it run.- `ANTHROPIC_API_KEY` for LLM calls- You'll need to follow [these instructions](https://docs.val.town/integrations/telegram/) to make a telegram bot, and set `TELEGRAM_TOKEN`. You'll also need to get a `TELEGRAM_CHAT_ID` in order to have the bot remember chat contents.- For the Google Calendar integration you'll need `GOOGLE_CALENDAR_ACCOUNT_ID` and `GOOGLE_CALENDAR_CALENDAR_ID`. See [these instuctions](https://www.val.town/v/stevekrouse/pipedream) for details.import { DateTime } from "https://esm.sh/luxon@3.4.4";import Anthropic from "npm:@anthropic-ai/sdk@0.24.3";const RECIPIENTS = ["Geoffrey", "Maggie"] as const;async function analyzeHtmlContent( anthropic: Anthropic, htmlContent: string, imageSummaries: ImageSummary[]) { try { const response = await anthropic.messages.create({ model: "claude-3-5-sonnet-latest", max_tokens: 4196, console.log(e.text); // Get Anthropic API key from environment const apiKey = Deno.env.get("ANTHROPIC_API_KEY"); if (!apiKey) { console.error("Anthropic API key is not configured for this val."); return; } // Initialize Anthropic client const anthropic = new Anthropic({ apiKey }); // Process each image attachment serially ); const response = await anthropic.messages.create({ model: "claude-3-5-sonnet-latest", max_tokens: 4196, // Analyze HTML content const htmlAnalysis = await analyzeHtmlContent( anthropic, e.html || "", summaries} from "https://deno.land/x/grammy@v1.35.0/mod.ts";import { DateTime } from "https://esm.sh/luxon@3.4.4";import Anthropic from "npm:@anthropic-ai/sdk@0.24.3";import { backstory } from "../backstory.ts";import {/** * Format chat history for Anthropic API */function formatChatHistoryForAI(history) { */async function analyzeMessageContent( anthropic, username, messageText, console.log({ systemPrompt, formattedHistory }); const response = await anthropic.messages.create({ model: "claude-3-5-sonnet-latest", max_tokens: 4196,bot.on("message", async (ctx) => { try { // Get Anthropic API key from environment const apiKey = Deno.env.get("ANTHROPIC_API_KEY"); if (!apiKey) { console.error("Anthropic API key is not configured."); ctx.reply( "I apologize, but I'm not properly configured at the moment. Please inform the household administrator." } // Initialize Anthropic client const anthropic = new Anthropic({ apiKey }); // Get message text and user info // Analyze message content with chat history context const analysis = await analyzeMessageContent( anthropic, username, messageText,} from "https://esm.town/v/geoffreylitt/getWeather";import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";import Anthropic from "npm:@anthropic-ai/sdk@0.24.3";const TABLE_NAME = `memories`; try { // Get API key from environment const apiKey = Deno.env.get("ANTHROPIC_API_KEY"); if (!apiKey) { console.error("Anthropic API key is not configured."); return null; } // Initialize Anthropic client const anthropic = new Anthropic({ apiKey }); const response = await anthropic.messages.create({ model: "claude-3-5-sonnet-latest", max_tokens: 150,import { nanoid } from "https://esm.sh/nanoid@5.0.5";import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";import Anthropic from "npm:@anthropic-ai/sdk@0.24.3";const TABLE_NAME = `memories`; try { // Get API key from environment const apiKey = Deno.env.get("ANTHROPIC_API_KEY"); if (!apiKey) { console.error("Anthropic API key is not configured."); return null; } // Initialize Anthropic client const anthropic = new Anthropic({ apiKey }); // Format previous facts for the prompt console.log({ message }); const response = await anthropic.messages.create({ model: "claude-3-5-sonnet-latest", max_tokens: 1000,import { Bot } from "https://deno.land/x/grammy@v1.35.0/mod.ts";import { DateTime } from "https://esm.sh/luxon@3.4.4";import Anthropic from "npm:@anthropic-ai/sdk@0.24.3";import { backstory } from "../backstory.ts";import {} from "../memoryUtils.ts";async function generateBriefingContent(anthropic, memories, today, isSunday) { try { const weekdaysHelp = generateWeekDays(today); }; console.log("Sending prompt to Anthropic...", userMessage); const response = await anthropic.messages.create({ model: "claude-3-7-sonnet-latest", max_tokens: 30000,export async function sendDailyBriefing(chatId?: string, today?: DateTime) { // Get API keys from environment const apiKey = Deno.env.get("ANTHROPIC_API_KEY"); const telegramToken = Deno.env.get("TELEGRAM_TOKEN"); if (!apiKey) { console.error("Anthropic API key is not configured."); return; } } // Initialize Anthropic client const anthropic = new Anthropic({ apiKey }); // Initialize Telegram bot // Generate briefing content const content = await generateBriefingContent( anthropic, memories, today,You'll need to set up some environment variables to make it run.- `ANTHROPIC_API_KEY` for LLM calls- You'll need to follow [these instructions](https://docs.val.town/integrations/telegram/) to make a telegram bot, and set `TELEGRAM_TOKEN`. You'll also need to get a `TELEGRAM_CHAT_ID` in order to have the bot remember chat contents.- For the Google Calendar integration you'll need `GOOGLE_CALENDAR_ACCOUNT_ID` and `GOOGLE_CALENDAR_CALENDAR_ID`. See [these instuctions](https://www.val.town/v/stevekrouse/pipedream) for details.import { DateTime } from "https://esm.sh/luxon@3.4.4";import Anthropic from "npm:@anthropic-ai/sdk@0.24.3";const RECIPIENTS = ["Geoffrey", "Maggie"] as const;async function analyzeHtmlContent( anthropic: Anthropic, htmlContent: string, imageSummaries: ImageSummary[]) { try { const response = await anthropic.messages.create({ model: "claude-3-5-sonnet-latest", max_tokens: 4196, console.log(e.text); // Get Anthropic API key from environment const apiKey = Deno.env.get("ANTHROPIC_API_KEY"); if (!apiKey) { console.error("Anthropic API key is not configured for this val."); return; } // Initialize Anthropic client const anthropic = new Anthropic({ apiKey }); // Process each image attachment serially ); const response = await anthropic.messages.create({ model: "claude-3-5-sonnet-latest", max_tokens: 4196, // Analyze HTML content const htmlAnalysis = await analyzeHtmlContent( anthropic, e.html || "", summaries