Search
Code3,144
// Test specific modelimport { testModel } from './ai-model-test.ts';await testModel('anthropic/claude-3.5-sonnet', 'Test message');// Manual webhook testing: Visit webhook URLs in browser for config
export const AI_MODELS: AIModel[] = [ { id: "anthropic/claude-3.5-sonnet", name: "Claude 3.5 Sonnet", provider: "Anthropic", maxTokens: 8192, costPer1kTokens: { input: 0.003, output: 0.015 }, }, { id: "anthropic/claude-3-opus", name: "Claude 3 Opus", provider: "Anthropic", maxTokens: 4096, costPer1kTokens: { input: 0.015, output: 0.075 }, groq: { order: ["groq"] }, openai: { order: ["openai"] }, anthropic: { order: ["anthropic"] }, auto: {} // Let OpenRouter choose automatically },import { anthropic } from "npm:@ai-sdk/anthropic";import { openai } from "npm:@ai-sdk/openai";import { generateText, streamText } from "npm:ai"; const maxSteps = 10; const model = Deno.env.get("ANTHROPIC_API_KEY") ? anthropic("claude-3-7-sonnet-latest") : openai("gpt-5");It is easy to reconfigure the agent to work with other providers that are supported by Vercel's AI SDK, though not all models support tool calling.Anthropic's models should work well, but the system prompt would need to be retuned to work with Claude.Learn more: https://ai-sdk.dev/docs/foundations/providers-and-models
}; const r = await fetch("https://api.anthropic.com/v1/messages", { method: "POST", headers: { "content-type": "application/json", "x-api-key": Deno.env.get("ANTHROPIC_API_KEY") ?? "", "anthropic-version": "2023-06-01", }, body: JSON.stringify(body), }; const r = await fetch("https://api.anthropic.com/v1/messages", { method: "POST", headers: { "content-type": "application/json", "x-api-key": Deno.env.get("ANTHROPIC_API_KEY") ?? "", "anthropic-version": "2023-06-01", }, body: JSON.stringify(body),import { z } from "npm:zod@4.0.5";import { generateText, stepCountIs, tool } from "npm:ai@5.0.15";import { anthropic } from "npm:@ai-sdk/anthropic@2.0.4";import { Sandbox } from "npm:@e2b/code-interpreter";const result = await generateText({ model: anthropic("claude-sonnet-4-20250514"), stopWhen: stepCountIs(10), tools: { project, branchId, // anthropicApiKey, // bearerToken, selectedFiles,- [x] Add a "view source" / "send me a PR" link- [x] Show the HTTP preview in second column if there is one (and let the user pick which one to preview in the iframe)- [x] Figure out a convention to teach in the anthropic prompt mod where the LLM always checks the readme for the scope (if not provided) and keeps it up to take with every change- [x] Ability to create new projects from the interface- [x] Figure out why OpenTownie can't create HTTP vals. Maybe give it a seperate tool for it?- [x] Start a timer for messages- [x] Add more indicators that it's "still working"- [x] Require users supply their own Anthropic token?- [x] Add cost indications on messages- [x] Add a bell noise when the message is done to let us knowimport { readFile } from "https://esm.town/v/std/utils/index.ts";import { createAnthropic } from "npm:@ai-sdk/anthropic@1.2.12";import { convertToCoreMessages, } = await c.req.json(); const apiKey = Deno.env.get("ANTHROPIC_API_KEY"); if (await hasInsufficientCredits({ bearerToken })) { }); const anthropic = createAnthropic({ apiKey }); let tracedModel = anthropic(model); if (Deno.env.get("POSTHOG_PROJECT_API_KEY")) { const traceId = `townie_${rowid}_${Date.now()}`; // Wrap the Anthropic model with PostHog tracing tracedModel = withTracing(anthropic(model), phClient, { posthogDistinctId: user.id, posthogTraceId: traceId, // @ts-ignore lastMessage.content.at(-1).providerOptions = { anthropic: { cacheControl: { type: "ephemeral" } }, }; } output_tokens: result.usage.completionTokens, cache_read_tokens: result.providerMetadata.anthropic.cacheReadInputTokens, cache_write_tokens: result.providerMetadata.anthropic.cacheCreationInputTokens, }); output_tokens: result.usage.completionTokens, cache_read_tokens: result.providerMetadata.anthropic.cacheReadInputTokens, cache_write_tokens: result.providerMetadata.anthropic.cacheCreationInputTokens, }); },