Search
Code1,513
import { DateTime } from "https://esm.sh/luxon@3.4.4";import Anthropic from "npm:@anthropic-ai/sdk@0.24.3";async function analyzeHtmlContent( anthropic: Anthropic, htmlContent: string, try { const response = await anthropic.messages.create({ model: "claude-3-5-sonnet-latest", // 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 }); const response = await anthropic.messages.create({ model: "claude-3-5-sonnet-latest", const htmlAnalysis = await analyzeHtmlContent( anthropic, e.html || "",import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";import Anthropic from "npm:@anthropic-ai/sdk@0.24.3"; // 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",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";async function generateBriefingContent(anthropic, memories, today, isSunday) { try { console.log("Sending prompt to Anthropic...", userMessage); const response = await anthropic.messages.create({ model: "claude-3-7-sonnet-latest", // 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 }); const content = await generateBriefingContent( anthropic, memories,import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";import Anthropic from "npm:@anthropic-ai/sdk@0.24.3"; // 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",To get Townie running in your Val Town account, click the **Remix** button and then add your ANTHROPIC_API_KEY. You can leave all the other environment variables blank.import { readFile } from "https://esm.town/v/std/utils/index.ts";import { createAnthropic } from "npm:@ai-sdk/anthropic@1.2.12";import { const apiKey = Deno.env.get("ANTHROPIC_API_KEY"); const anthropic = createAnthropic({ apiKey }); let tracedModel = anthropic(model); // Wrap the Anthropic model with PostHog tracing tracedModel = withTracing(anthropic(model), phClient, { posthogDistinctId: user.id, lastMessage.content.at(-1).providerOptions = { anthropic: { cacheControl: { type: "ephemeral" } }, }; cache_read_tokens: result.providerMetadata.anthropic.cacheReadInputTokens, cache_write_tokens: result.providerMetadata.anthropic.cacheCreationInputTokens, }); cache_read_tokens: result.providerMetadata.anthropic.cacheReadInputTokens, cache_write_tokens: result.providerMetadata.anthropic.cacheCreationInputTokens, }); branchId, // anthropicApiKey, // bearerToken, branchId, // anthropicApiKey, // bearerToken,To get Townie running in your Val Town account, click the **Remix** button and then add your ANTHROPIC_API_KEY. You can leave all the other environment variables blank.import { readFile } from "https://esm.town/v/std/utils/index.ts";import { createAnthropic } from "npm:@ai-sdk/anthropic@1.2.12";import { const apiKey = Deno.env.get("ANTHROPIC_API_KEY"); const anthropic = createAnthropic({ apiKey }); let tracedModel = anthropic(model); // Wrap the Anthropic model with PostHog tracing tracedModel = withTracing(anthropic(model), phClient, { posthogDistinctId: user.id, lastMessage.content.at(-1).providerOptions = { anthropic: { cacheControl: { type: "ephemeral" } }, }; cache_read_tokens: result.providerMetadata.anthropic.cacheReadInputTokens, cache_write_tokens: result.providerMetadata.anthropic.cacheCreationInputTokens, }); cache_read_tokens: result.providerMetadata.anthropic.cacheReadInputTokens, cache_write_tokens: result.providerMetadata.anthropic.cacheCreationInputTokens, });import { readFile } from "https://esm.town/v/std/utils/index.ts";import { createAnthropic } from "npm:@ai-sdk/anthropic@1.2.12";import { const apiKey = Deno.env.get("ANTHROPIC_API_KEY"); const anthropic = createAnthropic({ apiKey }); let tracedModel = anthropic(model); // Wrap the Anthropic model with PostHog tracing tracedModel = withTracing(anthropic(model), phClient, { posthogDistinctId: user.id, lastMessage.content.at(-1).providerOptions = { anthropic: { cacheControl: { type: "ephemeral" } }, }; cache_read_tokens: result.providerMetadata.anthropic.cacheReadInputTokens, cache_write_tokens: result.providerMetadata.anthropic.cacheCreationInputTokens, }); cache_read_tokens: result.providerMetadata.anthropic.cacheReadInputTokens, cache_write_tokens: result.providerMetadata.anthropic.cacheCreationInputTokens, }); branchId, // anthropicApiKey, // bearerToken,// BEFORE (v4):import { createAnthropic } from "npm:@ai-sdk/anthropic@1.2.12";import {// AFTER (v5):import { createAnthropic } from "npm:@ai-sdk/anthropic@2.0.0";import { - `npm:ai@4.3.19` - `npm:@ai-sdk/anthropic@1.2.12` - `@ai-sdk/react@1.2.12`import { readFile } from "https://esm.town/v/std/utils/index.ts";import { createAnthropic } from "npm:@ai-sdk/anthropic@1.2.12";import { const apiKey = Deno.env.get("ANTHROPIC_API_KEY"); const anthropic = createAnthropic({ apiKey }); let tracedModel = anthropic(model); // Wrap the Anthropic model with PostHog tracing tracedModel = withTracing(anthropic(model), phClient, { posthogDistinctId: user.id, lastMessage.content.at(-1).providerOptions = { anthropic: { cacheControl: { type: "ephemeral" } }, }; cache_read_tokens: result.providerMetadata.anthropic.cacheReadInputTokens, cache_write_tokens: result.providerMetadata.anthropic.cacheCreationInputTokens, }); cache_read_tokens: result.providerMetadata.anthropic.cacheReadInputTokens, cache_write_tokens: result.providerMetadata.anthropic.cacheCreationInputTokens, }); branchId, // anthropicApiKey, // bearerToken,