dailyDadJokemain.tsx1 match
34export async function dailyDadJoke() {
5let { setup, punchline } = await fetchJSON("https://official-joke-api.appspot.com/random_joke");
6return email({
7text: punchline,
dailyDadJokeREADME.md2 matches
113. 🤣🤣🤣🤣
1213## API
1415This 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).
dailyDadJokemain.tsx1 match
34export async function dailyDadJoke() {
5let { setup, punchline } = await fetchJSON("https://official-joke-api.appspot.com/random_joke");
6return email({
7text: punchline,
blob_adminREADME.md1 match
9[](https://www.val.town/v/stevekrouse/blob_admin_app/fork)
1011It 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).
1213# TODO
dailyDadJokeREADME.md2 matches
113. 🤣🤣🤣🤣
1213## API
1415This 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).
dailyDadJokemain.tsx1 match
34export async function dailyDadJoke() {
5let { setup, punchline } = await fetchJSON("https://official-joke-api.appspot.com/random_joke");
6return email({
7text: punchline,
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.
1112<img width=500 src="https://imagedelivery.net/iHX6Ovru0O7AjmyT5yZRoA/7077d1b5-1fa7-4a9b-4b93-f8d01d3e4f00/public"/>
claudeForwardermain.tsx14 matches
1// This val implements a function to call the Claude API using fetch.
2// It handles the API request and response processing.
3// The Claude API key is expected to be provided in the request headers.
4// CORS is enabled for all origins.
511"Access-Control-Allow-Origin": "*",
12"Access-Control-Allow-Methods": "POST, OPTIONS",
13"Access-Control-Allow-Headers": "Content-Type, x-api-key",
14},
15});
20}
2122const apiKey = req.headers.get("x-api-key");
23if (!apiKey) {
24return new Response("Claude API key not provided in headers", { status: 400 });
25}
2630const systemPrompt = params["system_prompt"];
31const userPrompt = params["user_prompt"];
32const claudeResponse = await callClaudeApi(systemPrompt, userPrompt, apiKey);
33return new Response(claudeResponse, {
34headers: {
48}
4950async function callClaudeApi(systemPrompt: string, userPrompt: string, apiKey: string): Promise<string> {
51const url = "https://api.anthropic.com/v1/messages";
52const headers = {
53"Content-Type": "application/json",
54"x-api-key": apiKey,
55"anthropic-version": "2023-06-01",
56"anthropic-beta": "prompt-caching-2024-07-31",
8384const responseData = await response.json();
85console.log("Claude API response:", responseData);
8687if (response.ok) {
88return responseData.content[0].text;
89} else {
90throw new Error(`API Error: ${response.status}, ${JSON.stringify(responseData)}`);
91}
92} catch (error) {
93console.error("Error calling Claude API:", error);
94throw error;
95}
valleGetValsContextWindowmain.tsx7 matches
13const readmeVals: any = await (await fetch("https://janpaul123-readmevals.web.val.run/")).json();
1415const API_URL = "https://api.val.town";
1617const sections = [
129{
130prompt: "Write a val that accesses environment variables",
131code: `const res = await fetch("${API_URL}/v1/me", {
132headers: {
133Authorization: \`Bearer \${Deno.env.get("valtown")}\`,
141code: `import process from "node:process";
142
143const res = await fetch("${API_URL}/v1/me", {
144headers: {
145Authorization: \`Bearer \${process.env.valtown}\`,
310You can attach files to your emails by using the \`attachments\` field.
311Attachments need to be [Base64](https://en.wikipedia.org/wiki/Base64) encoded,
312which is that the [btoa](https://developer.mozilla.org/en-US/docs/Web/API/btoa)
313method is doing in this example:
314
412\`\`\`
413
414### Lower-level API
415
416We do provide access to the lower-level getter and setters, which are useful if you are storing non-JSON or binary data, need to stream in your response or request data, or do anything else lower-level.
417
418- \`async get(key: string)\`: Retrieves a blob for a given key.
419- \`async set(key: string, value: string | BodyInit)\`: Sets the blob value for a given key. See [BodyInit](https://deno.land/api@v1.38.1?s=BodyInit).
420
421### Limitations
458role: "assistant",
459content:
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{
valleBlogV0README.md1 match
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