1# Val Town Project Utilities
23These utils are very rapidly developing, so expect breaking changes.
45* file - reading files and directories in Projects
27<a href="https://github.com/wkrouse">Github</a>
28</nav>
29<h1>How to make a PUT request with the Fetch API</h1>
30<p> This page is a guide on how to PUT request with the Fetch API. First I'm going to
31explain what why we're using the Fetch API. Then I'll explain what it is and the Val Town variant.
32Finally I'll walk you through modifying the code example so that it allows you to replacing name with a
33different name.</p>
34
35<p>The reason we need to use the Fetch API is that the HTML form only works
36for GET and POST methods. </p>
37
spacex_migratedmain.tsx2 matches
1/** @jsxImportSource npm:hono@3/jsx */
2import { frameHtml } from "https://esm.town/v/moe/frameHtml";
3import { getLaunches } from "https://esm.town/v/moe/spacexapi";
4import { spacexCalendar } from "https://esm.town/v/moe/spacexcalendar";
5import { getChartUrl } from "https://esm.town/v/moe/spacexchart";
83{
84/* <div class="mb-3">
85<a href="/api" target="_blank">API</a>
86</div>
87<div class="mb-4">
1# askSMHI
2Using OpenAI chat completion with function calls to [SMHI](https://en.wikipedia.org/wiki/Swedish_Meteorological_and_Hydrological_Institute) api
34The API is instructed to use the current time in Europe/Stockholm timezone.
5If the message can not be handled with the weather API endpoint, the Open AI assistant will reply instead.
678## Relevant API documentation
9* [SMHI, forecast documentation](https://opendata.smhi.se/apidocs/metfcst/get-forecast.html)
10* [OPEN AI, GPT function calling documentation](https://platform.openai.com/docs/guides/function-calling?api-mode=chat&lang=javascript)
1112## How to use this endpoint
17```typescript
18{
19answer?: string // If the message could not be answered with the SMHI API
20error?:string //
21data?: unknown // the actual data returned from SMHI, if the API is called
22summary?: string // a summary of the data, by GPT API
23}
24```
2627### Examples
28* How is the weather in the Capital of Sweden tomorrow.
29* How is the weather at Liseberg on Friday.
3031## How it works
321. Handle the API request and count the tokens in the question.
332. Send the question to Open AI API moderation
343. Create tool calling by converting schema to JSON schema
354. Send the question to Open AI Chat Completion and expose tool calling
365. Make the API call to the SMHI API with parameters from OPEN AI
376. Add additional information to the SMHI response (converting numerical categories to text)
387. Remove data from the response that was not requested by the Open AI parameters.
398. Send the modified response to Open AI API together with the SMHI response JSON Schema.
409. Send a summary of the forcast (by Open AI API) together with the forecast data as a response to the initial request.
4142## Enviroment variables
43* OPENAI_CHAT: Needs to be authorized to write chat completions and to the moderation API.
44## Packages used
45* openai: For typesafe API request and responses
46* valibot: for describing the SMHI API response and function API input
47* valibot/to-json-schema: Transform the schema to json schema (readable by the GPT API)
48* gpt-tokenizer: count the number of tokens
49* formkit/temporal: To handle dates in a specific timezone (Europe/Stockholm)
42}[],
43};
44const openai = new OpenAI({ apiKey: process.env.OPENAI_CHAT });
4546const completion = await openai.chat.completions.create({
11}
12const response = await fetch(
13`https://opendata-download-metfcst.smhi.se/api/category/pmp3g/version/2/geotype/point/lon/${lon}/lat/${lat}/data.json`,
14);
15
askSMHImoderation1 match
9Authorization: `Bearer ${openAIKey}`,
10};
11const openai = new OpenAI({ apiKey: process.env.OPENAI_CHAT });
12const responseData = await openai.moderations.create({ input: publicMessages });
13return { flagged: responseData.results.some((r) => r.flagged) };
newCerebrasModelAlertmain.tsx2 matches
7const historicalModels = await blob.getJSON("cerebras-models.json");
89const currentModels = await fetchJSON("https://api.cerebras.ai/v1/models", {
10bearer: Deno.env.get("CEREBRAS_API_KEY"),
11});
12await blob.setJSON("cerebras-models.json", currentModels);
OpenTowniesoundEffects.ts4 matches
45/**
6* Plays a bell sound notification using the Web Audio API
7* @returns A Promise that resolves when the sound has started playing
8*/
13const AudioContext = window.AudioContext || (window as any).webkitAudioContext;
14if (!AudioContext) {
15console.warn("Web Audio API not supported in this browser");
16resolve();
17return;
6566/**
67* Plays a simple notification sound using the Web Audio API
68* This is a simpler, shorter bell sound
69* @returns A Promise that resolves when the sound has started playing
75const AudioContext = window.AudioContext || (window as any).webkitAudioContext;
76if (!AudioContext) {
77console.warn("Web Audio API not supported in this browser");
78resolve();
79return;
instagramScrapingREADME.md1 match
67- `/` - Main application page
8- `/extract?url={instagram_url}` - API endpoint to extract post data
9- `/extract?url={instagram_url}&proxyImage=true` - Endpoint to proxy Instagram images
10