1import { qrcode } from "https://deno.land/x/qrcode/mod.ts";
2
3export async function generateQR(req: Request) {
4 let url: URL;
5 try {
2import { default as ical } from "npm:ical-generator";
3
4export default async function(req: Request): Promise<Response> {
5 const url = `https://api.phish.net/v5/shows/artist/phish.json?order_by=showdate&direction=desc&apikey=${
6 Deno.env.get("PHISH_NET_API_KEY")
4const cacheBlobKey = "getValsContextWindowCache3";
5
6export default async function getValsContextWindow(model: any) {
7 const fullCacheBlobKey = `${cacheBlobKey}-${model}`;
8 const cached = await blob.getJSON(fullCacheBlobKey);
194 import { render } from "npm:preact-render-to-string";
195
196 export default async function(req: Request) {
197 return new Response(
198 render(
223 const FLAT_TEMPLATES = sections.flatMap((section) => section.templates);
224
225 function tsResponse(code) {
226 return "```ts\n" + code + "\n```";
227 }
394 ### Utilities
395
396 Our Blob SDK also includes some utility functions to make working with blobs easier.
397
398 ##### Copy
432 role: "assistant",
433 content:
434 "\n```ts\nexport default async function (req: Request): Promise<Response> {\n return Response.json(\"Hello world\")\n}\n```",
435 },
436 {
441 role: "assistant",
442 content:
443 "\n```ts\nexport default async function(req: Request): Promise<Response> {\n const query = new URL(req.url).searchParams;\n\n // Read name from the querystring or body. Defaults to \"you\" if not present.\n const name = query.get(\"name\") || (await req.json().catch(() => ({}))).name || \"you\";\n\n // Returns the HTML response\n return new Response(`<h1>Hi ${name}!</h1>`, {\n headers: { \"Content-Type\": \"text/html\" },\n });\n}\n```",
444 },
445 {
458 role: "assistant",
459 content:
460 "```ts\nexport default async function(req: Request): Promise<Response> {\n const apiKey = Deno.env.get(\"METEO_KEY\");\n const apiUrl = `https://api.open-meteo.com/v1/forecast?latitude=40.6782&longitude=-73.9442&hourly=temperature_2m¤t_weather=true&apikey=${apiKey}`;\n\n const response = await fetch(apiUrl);\n const weatherData = await response.json();\n\n return new Response(JSON.stringify(weatherData), { headers: { \"Content-Type\": \"application/json\" } });\n}\n```",
461 },
462 {
3import { ComputeJSON, ComputeText, GenerateImage, sb, Substrate } from "npm:substrate";
4
5async function handler(req: Request): Promise<Response> {
6 const searchParams = new URL(req.url).searchParams;
7 const { prompt = "modernism" } = Object.fromEntries(searchParams);
23 const stream = await substrate.stream(haiku);
24
25 async function* content() {
26 yield new TextEncoder().encode(promptHeader());
27 for await (const event of stream) {
30`;
31
32function getHREF(mod) {
33 const url = new URL(mod);
34 return `https://val.town${url.pathname}`;
35}
36
37export function getBadgeLink(url: string): string {
38 const href = getHREF(url);
39 return `<div>
42}
43
44function handler(req: Request): Response {
45 return new Response(badge, {
46 headers: {
50}
51
52export default function htmlOrResponse(args: Request | string): string | Response {
53 if (typeof args === "string") return getBadgeLink(args);
54 if (args instanceof Request) return handler(args);
13};
14
15async function getResults(q: string, n: number): Promise<ShotResult[]> {
16 const substrate = new Substrate({
17 apiKey: process.env.SUBSTRATE_API_KEY,
4import { zodToJsonSchema } from "npm:zod-to-json-schema";
5
6async function handler(req: Request): Promise<Response> {
7 const searchParams = new URL(req.url).searchParams;
8 const { prompt = "modernism" } = Object.fromEntries(searchParams);
116 </div>
117 <script>
118 function source() {
119 const currentUrl = window.location.href;
120 return currentUrl.replace(
124 }
125
126 function go() {
127 const input = document.getElementById('inputField').value;
128 const encodedInput = encodeURIComponent(input);
130 window.location.href = link;
131 }
132 document.getElementById('inputField').addEventListener('keyup', function(event) {
133 if (event.key === 'Enter') {
134 go();
1import valTownBadge from "https://esm.town/v/substrate/substrateBadge";
2
3export default function badgeMiddleware(handler, url: string) {
4 return async function(req: Request): Promise<Response> {
5 if (req.method !== "GET") return await handler(req);
6
4import wrapper from "https://esm.town/v/substrate/substrateBadgeMiddleware";
5
6async function handler(req: Request): Promise<Response> {
7 const html = `
8 <h1>Hello, world</h1>
10import substrateBadge from "https://esm.town/v/substrate/substrateBadge";
11
12export default async function(req: Request): Promise<Response> {
13 const badge = substrateBadge(import.meta.url);
14 const html = `
A helper function to build a file's email
Simple functional CSS library for Val Town
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",