anthropicCachingmain.tsx8 matches
1/**
2* This val creates an interactive webpage that demonstrates the functionality of the Anthropic API.
3* It uses a React frontend with an input for the API key and buttons to trigger different operations.
4* The Anthropic API key is stored in the frontend state and sent with each API request.
9import { createRoot } from "https://esm.sh/react-dom/client";
1011function App() {
12const [apiKey, setApiKey] = useState("");
13const [outputs, setOutputs] = useState({
82}
8384function client() {
85createRoot(document.getElementById("root")).render(<App />);
86}
90}
9192async function server(request: Request): Promise<Response> {
93const url = new URL(request.url);
94138}
139140async function fetchContent(): Promise<string> {
141const response = await fetch("https://www.gutenberg.org/cache/epub/1342/pg1342.txt");
142const text = await response.text();
146}
147148async function runNonCachedCall(apiKey: string): Promise<string> {
149const { default: anthropic } = await import("npm:@anthropic-ai/sdk@0.26.1");
150const client = new anthropic.Anthropic({ apiKey });
182}
183184async function runCachedCall(apiKey: string): Promise<string> {
185const { default: anthropic } = await import("npm:@anthropic-ai/sdk@0.26.1");
186const client = new anthropic.Anthropic({ apiKey });
221}
222223async function runMultiTurnConversation(apiKey: string): Promise<string> {
224const { default: anthropic } = await import("npm:@anthropic-ai/sdk@0.26.1");
225const client = new anthropic.Anthropic({ apiKey });
1import { OpenAI } from "https://esm.town/v/std/openai";
23export default async function(req: Request): Promise<Response> {
4if (req.method === "OPTIONS") {
5return new Response(null, {
1export default async function(req: Request): Promise<Response> {
2const url =
3"https://global.bing.com/HPImageArchive.aspx?format=js&idx=0&n=9&pid=hp&FORM=BEHPTB&uhd=1&uhdwidth=3840&uhdheight=2160&setmkt=zh-CN&setlang=en";
1/** @jsxImportSource npm:hono/jsx */
2async function createSession(email: string, hostname: string) {
3const { zip } = await import("https://esm.town/v/pomdtr/sql");
4const { sqlite } = await import("https://esm.town/v/std/sqlite");
23}
2425async function getSession(sessionID: string, hostname: string) {
26const { zip } = await import("https://esm.town/v/pomdtr/sql");
27const { sqlite } = await import("https://esm.town/v/std/sqlite");
52}
5354async function deleteSession(sessionID: string) {
55const { sqlite } = await import("https://esm.town/v/std/sqlite");
5664const OAUTH_COOKIE = "oauth_store";
6566export function lastlogin(
67handler: (req: Request) => Response | Promise<Response>,
68) {
9import { v4 as uuidv4 } from 'https://esm.sh/uuid';
1011function html() {
12/*
13<!DOCTYPE html>
100}
101102function css() {
103/*
104body {
229}
230231function js() {
232/*
233import { v4 as uuidv4 } from 'https://esm.sh/uuid';
244addWebClipButton.addEventListener('click', addWebClip);
245246function addWebClip() {
247const webClip = document.createElement('div');
248webClip.className = 'web-clip';
281}
282283function attachIconChoiceListeners(index) {
284const useDefaultIcon = document.getElementById(`useDefaultIcon-${index}`);
285const useCustomIcon = document.getElementById(`useCustomIcon-${index}`);
290}
291292function toggleCustomIconGroup(customIconGroup) {
293customIconGroup.style.display = customIconGroup.style.display === 'none' ? 'block' : 'none';
294}
338});
339340async function convertToBase64(file) {
341return new Promise((resolve, reject) => {
342const reader = new FileReader();
347}
348349function generateMobileConfig(data, webClips) {
350const webClipConfigs = webClips.map((clip, index) => `
351<dict>
markdown_downloadmain.tsx10 matches
16* @returns markdown in string
17*/
18export async function html2markdown(html: string): Promise<string> {
19if (AgentMarkdownImport) {
20// TurndownService doesn't work on cf
34* @returns markdown in string
35*/
36export async function readability2markdown(html: string): Promise<{ title: string; markdown: string }> {
37const doc = await (new DOMParser().parseFromString(html, "text/html"));
3844}
4546function response(message: string, contentType = "text/markdown"): Response {
47const headers = new Headers();
48headers.set("Access-Control-Allow-Origin", "*");
64}
6566function err(msg: string): Response {
67const errorMessage = JSON.stringify({
68error: {
74}
7576function fudgeURL(url: string) {
77try {
78return new URL(url);
83}
8485async function processInput(req: Request) {
86let ret = {
87url: undefined as undefined | URL,
129}
130131export async function youtube2markdown(url: URL): Promise<string | undefined> {
132function getYoutubeVideoID(url: URL): string | null {
133const regExp = /(?:youtube\.com\/(?:[^/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?/\s]{11})/i;
134const match = url.href.match(regExp);
161* Simple UI that takes a url
162*/
163export function generate_ui(input_description: string, link: string, link_text: string): string {
164const html = `
165<!DOCTYPE html>
195}
196197export default async function(req: Request): Promise<Response> {
198const action = await processInput(req);
199const url = action.url;
102];
103104function App() {
105const [selectedItem, setSelectedItem] = useState(null);
106const [showWords, setShowWords] = useState(true);
176}
177178function client() {
179createRoot(document.getElementById("root")).render(<App />);
180}
184}
185186export default async function server(request: Request): Promise<Response> {
187const randomColor = Math.floor(Math.random() * 16777215).toString(16);
188return new Response(
111) Interactive vocabulary grid
12132) Real-time search functionality
14153) Word visibility toggle
RobotBackupCallGraphmain.tsx15 matches
2import { thisWebURL } from "https://esm.town/v/stevekrouse/thisWebURL?v=2";
34export default async function server(req: Request): Promise<Response> {
5// Handle GET requests
6if (req.method === "GET") {
288layout: {
289name: 'preset',
290positions: function(node) {
291return { x: 0, y: 0 }; // Initial positions, will be overwritten
292}
297});
298299// Custom layout function
300function customLayout() {
301const mainGraph = cy.elements().not('#isolated, #isolated > node');
302const isolatedGraph = cy.getElementById('isolated');
349350// Add event listeners for highlighting
351cy.on('mouseover', 'node', function(e) {
352const node = e.target;
353highlightNodeChildrenAndParents(node);
354});
355356cy.on('mouseout', 'node', function(e) {
357unhighlightAll();
358});
359360cy.on('click', 'node', function(e) {
361const node = e.target;
362if (node.hasClass('highlighted') || node.hasClass('parent-highlighted')) {
368});
369370function highlightNodeChildrenAndParents(node) {
371const children = node.outgoers();
372const parents = node.incomers();
376}
377378function unhighlightAll() {
379cy.elements().removeClass('highlighted');
380cy.elements().removeClass('parent-highlighted');
529let match;
530while ((match = callRegex.exec(line)) !== null) {
531const calledFunction = match[1].toLowerCase();
532relationships.get(caller).add(calledFunction);
533allNodes.add(calledFunction);
534}
535});
545546const edges = [];
547relationships.forEach((calledFunctions, file) => {
548calledFunctions.forEach(calledFunction => {
549edges.push({
550data: {
551source: file,
552target: calledFunction,
553},
554});
1if (import.meta.main) Deno.serve(translate);
23export async function translate(req: Request) {
4if (req.method === "POST") {
5const { code: status, data } = await fetch("https://deepl.deno.dev/translate", {
46};
4748translate = async function () {
49this.setState({ loading: true, translation: "" });
50const { text, source_lang, target_lang } = this.state;
53}.bind(this);
5455swap = function () {
56if (this.state.source_lang.toLowerCase() === "auto") {
57this.setState({ source_lang: "en" });
63}.bind(this);
6465handleShortcut = function (e) {
66if (this.state.loading !== true && e.ctrlKey && e.key === "Enter") {
67this.translate();
126render(html\`<\${App} page="All" />\`, document.body);
127128async function translate({ text, source_lang, target_lang }) {
129const Options = z.object({
130text: z.string(),