6* Fork this val to your own profile.
7* Make a folder for the temporary vals that get generated, take the ID from the URL, and put it in `tempValsParentFolderId`.
8* If you want to use OpenAI models you need to set the `OPENAI_API_KEY` [env var](https://www.val.town/settings/environment-variables).
9* If you want to use Anthropic models you need to set the `ANTHROPIC_API_KEY` [env var](https://www.val.town/settings/environment-variables).
10* Create a [Val Town API token](https://www.val.town/settings/api), open the browser preview of this val, and use the API token as the password to log in.
11
12<img width=500 src="https://imagedelivery.net/iHX6Ovru0O7AjmyT5yZRoA/7077d1b5-1fa7-4a9b-4b93-f8d01d3e4f00/public"/>
6* Fork this val to your own profile.
7* Make a folder for the temporary vals that get generated, take the ID from the URL, and put it in `tempValsParentFolderId`.
8* If you want to use OpenAI models you need to set the `OPENAI_API_KEY` [env var](https://www.val.town/settings/environment-variables).
9* If you want to use Anthropic models you need to set the `ANTHROPIC_API_KEY` [env var](https://www.val.town/settings/environment-variables).
10* Create a [Val Town API token](https://www.val.town/settings/api), open the browser preview of this val, and use the API token as the password to log in.
11
12<img width=500 src="https://imagedelivery.net/iHX6Ovru0O7AjmyT5yZRoA/7077d1b5-1fa7-4a9b-4b93-f8d01d3e4f00/public"/>
1* Fork this val to your own profile.
2* Create a [Val Town API token](https://www.val.town/settings/api), open the browser preview of this val, and use the API token as the password to log in.
3
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,
1/**
2 * This code creates a search engine prototype with autocomplete functionality using the Cerebras LLM API.
3 * It uses React for the frontend and the Cerebras API for generating autocomplete suggestions.
4 * The suggestions are cached in the browser to reduce API calls.
5 * It implements a two-step LLM process: first to get initial suggestions, then to filter them for sensibility and ethics.
6 * If the second LLM call fails, it displays "Failed to fetch" instead of showing results.
104 if (request.method === "POST" && new URL(request.url).pathname === "/suggestions") {
105 const { query } = await request.json();
106 const apiKey = Deno.env.get("CEREBRAS_API_KEY");
107 const initialSuggestions: string[] = [];
108
109 if (!apiKey) {
110 return new Response(JSON.stringify({ error: "API key not found" }), {
111 status: 500,
112 headers: { "Content-Type": "application/json" },
115
116 try {
117 const response = await fetch("https://api.cerebras.ai/v1/chat/completions", {
118 method: "POST",
119 headers: {
120 "Content-Type": "application/json",
121 "Authorization": `Bearer ${apiKey}`,
122 },
123 body: JSON.stringify({
137
138 if (!response.ok) {
139 throw new Error("Failed to fetch from Cerebras API");
140 }
141
146
147 // Second LLM call to filter suggestions
148 const filterResponse = await fetch("https://api.cerebras.ai/v1/chat/completions", {
149 method: "POST",
150 headers: {
151 "Content-Type": "application/json",
152 "Authorization": `Bearer ${apiKey}`,
153 },
154 body: JSON.stringify({
189 });
190 } catch (error) {
191 console.error("Error calling Cerebras API:", error);
192 return new Response(JSON.stringify({ error: "Failed to fetch" }), {
193 status: 500,
1/**
2 * This code creates a geocoder widget similar to the Google Maps API search widget.
3 * It uses React for the frontend, the Cerebras API for LLM-based geocoding,
4 * and Leaflet for displaying the map.
5 */
124 const { query } = await request.json();
125
126 const prompt = `You are a geocoding API. Return up to 5 possible matches.
127 Respond with only the completions, separated by newlines.`;
128
129 try {
130 const response = await fetch("https://api.cerebras.ai/v1/chat/completions", {
131 method: "POST",
132 headers: {
133 "Content-Type": "application/json",
134 "Authorization": `Bearer ${Deno.env.get("CEREBRAS_API_KEY")}`,
135 },
136 body: JSON.stringify({
146
147 if (!response.ok) {
148 throw new Error("Failed to fetch from Cerebras API");
149 }
150
157 });
158 } catch (error) {
159 console.error("Error calling Cerebras API:", error);
160 return new Response(JSON.stringify({ error: "Failed to fetch suggestions" }), {
161 status: 500,
2 "name": "Val Town",
3 "urlSquareLogoWithBackground": "https://avatars.githubusercontent.com/u/114268765?s=200&v=4",
4 "description": "Val Town is a website to build apps, APIs, and scheduled functions.",
5 "urlLearnMore": "https://blog.val.town/blog/oss",
6 "annualReports": [
1# Loot Generator API
2
3## How It Works
5### Components
6
7The Loot Generator API creates random loot items by combining:
8
9- 30 adjectives
6 * - Copy button to easily copy the generated data URI
7 *
8 * We'll use the FileReader API for file handling and data URI generation.
9 * The application will be built using HTML, CSS, and JavaScript, served by a Hono app.
10 */