19await init(import.meta.url);
20
21async function handler(req: Request): Promise<Response> {
22 // whatever else you do.
23 return
63```
64
65* `traced` wraps an async function in tracing.
66
67```typescript
68import { traceAsync } from "https://esm.town/v/saolsen/telemetry";
69
70const myTracedFunction: () => Promise<string> = traced(
71 "myTracedFunction",
72 async () => {
73 // await sleep(100);
77```
78
79* `fetch` is a traced version of the builtin `fetch` function that traces the request. Just import it and use it like you would use `fetch`.
80
81* `sqlite` is a traced version of the val town sqlite client. Just import it and use it like you would use [https://www.val.town/v/std/sqlite](https://www.val.town/v/std/sqlite)
9 user: "website that shows the current time",
10 content: `/** @jsxImportSource npm:react */
11export default function() {
12 return <h1>{new Date().toLocaleTimeString()}</h1>;
13}`,
66 );
67});
68export async function compile(description: string) {
69 const messages = [
70 {
74 You write Deno TypeScript.
75 Reply ONLY with valid Typescript.
76 Export the fetch function to run the server.
77 Only use web standard fetch. Export the fetch function to start the server.
78 Add extensive comments`,
79 },
1export default async function handler(req: Request) {
2 if (req.method !== 'POST') {
3 return new Response('Method not allowed', { status: 405 });
5import { Form, hydrate } from "https://esm.town/v/stevekrouse/ssr_react_mini?v=75";
6
7export async function loader(req: Request) {
8 const { sqlite } = await import("https://esm.town/v/std/sqlite?v=4");
9 const [, { columns, rows }] = await sqlite.batch([
20}
21
22export async function action(req: Request) {
23 const { sqlite } = await import("https://esm.town/v/std/sqlite?v=4");
24 const formData = await req.formData();
47}
48
49export function Component({ initialTodos, initialLogs }) {
50 const [todos, setTodos] = useState(initialTodos);
51 const [logs, setLogs] = useState(initialLogs);
54 useEffect(() => addLog(`Client rendered`), []);
55
56 function addTodo() {
57 setTodos([...todos, { text: newTodo }]);
58 setNewTodo("");
64 }
65
66 function toggleTodo(e) {
67 const formData = new FormData(e.target);
68 const id = parseInt(formData.get("id") as string);
71 }
72
73 function deleteTodo(e) {
74 const formData = new FormData(e.target);
75 const id = parseInt(formData.get("id") as string);
9 "latLngOfCity": {
10 openAiTool: {
11 type: "function",
12 function: {
13 name: "latLngOfCity",
14 description: "Get the latitude and longitude of a city",
34 "weatherOfLatLon": {
35 openAiTool: {
36 type: "function",
37 function: {
38 name: "weatherOfLatLon",
39 description: "Get the latitude and longitude of a city",
61 "fetchWebpage": {
62 openAiTool: {
63 type: "function",
64 function: {
65 name: "fetchWebpage",
66 description: "Fetch the weather forecast from the contents of a forecast URL",
87];
88
89function truncate(response: string | object) {
90 const TRUNCATE_LEN = 60
91 const responseStr = typeof response === "string" ? response : JSON.stringify(response)
93}
94
95async function runConversation() {
96 const response = await openai.chat.completions.create({
97 messages: transcript,
105 if (message.tool_calls) {
106 for (let i = 0; i < message.tool_calls.length; i++) {
107 console.log("[CALLING]", message.tool_calls[i].function);
108 const tool = toolbox[message.tool_calls[i].function.name];
109 if (tool) {
110 const result = await tool.call(JSON.parse(message.tool_calls[i].function.arguments));
111 console.log("[RESULT]", truncate(result));
112 transcript.push({
1import { fetchText } from "https://esm.town/v/stevekrouse/fetchText?v=6";
2
3export async function fetchWebpage(args: { url: string }) {
4 const { url } = args;
5 const html = await fetchText(args.url);
1Migrated from folder: openai_function_calling/fetchWebpage
1import { weatherGovGrid } from "https://esm.town/v/stevekrouse/weatherGovGrid?v=4";
2
3export async function weatherOfLatLon(args: { lat: number; lon: number }) {
4 const { lat, lon } = args;
5 const grid = await weatherGovGrid({ lat, lon });
1Migrated from folder: openai_function_calling/weatherOfLatLon
2import { load } from "npm:cheerio";
3
4export async function latLngOfCity(args: { cityName: string }) {
5 const { cityName } = args;
6 const html = await fetchText(
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": "*",