40
41 try {
42 const response = await fetch("/api/chat", {
43 method: "POST",
44 headers: { "Content-Type": "application/json" },
134
135async function server(request: Request): Promise<Response> {
136 if (request.method === "POST" && new URL(request.url).pathname === "/api/chat") {
137 const { messages, model } = await request.json();
138 const client = new Cerebras();
9[](https://www.val.town/v/stevekrouse/blob_admin_app/fork)
10
11It uses [basic authentication](https://www.val.town/v/pomdtr/basicAuth) with your [Val Town API Token](https://www.val.town/settings/api) as the password (leave the username field blank).
12
13# TODO
104
105 try {
106 const response = await fetch("/api/chat", {
107 method: "POST",
108 headers: { "Content-Type": "application/json" },
209
210async function server(request: Request): Promise<Response> {
211 if (request.method === "POST" && new URL(request.url).pathname === "/api/chat") {
212 const { Anthropic } = await import("https://esm.sh/@anthropic-ai/sdk@0.17.1");
213 const { messages } = await request.json();
113. 🤣🤣🤣🤣
12
13## API
14
15This val uses the [icanhazdadjoke API](https://icanhazdadjoke.com/api). You can find [more docs here](https://github.com/15Dkatz/official_joke_api), such as how to [filter by type](https://github.com/15Dkatz/official_joke_api?tab=readme-ov-file#grab-jokes-by-type).
3
4export async function dailyDadJoke() {
5 let { setup, punchline } = await fetchJSON("https://official-joke-api.appspot.com/random_joke");
6 return email({
7 text: punchline,
8
91. Click `Fork`
102. Change `location` (Line 4) to describe your location. It accepts fairly flexible English descriptions which it turns into locations via [nominatim's geocoder API](https://www.val.town/v/stevekrouse/nominatimSearch).
113. Click `Run`
12
1Migrated from folder: group_house/scrapeZillowAPI
1Migrated from folder: group_house/scrapeCraigslistAPI
1Migrated from folder: group_house/calculateTransitAPI
1// This approach uses the Sunset and Sunrise API to get sunset times for New York,
2// and creates a simple form to generate a calendar of events occurring before sunset.
3
107async function getSunsetTime(date: Date): Promise<Date> {
108 const formattedDate = `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`;
109 const response = await fetch(`https://api.sunrise-sunset.org/json?lat=40.7128&lng=-74.0060&date=${formattedDate}&formatted=0`);
110
111 if (!response.ok) {
116
117 if (!data.results || !data.results.sunset) {
118 throw new Error("Invalid response from sunset API");
119 }
120