spagindex.html3 matches
231uploadButton.disabled = true;
232uploadButton.textContent = "Uploading...";
233const response = await fetch("/api/upload", {
234method: "POST",
235body,
252253async function fetchUploads() {
254const response = await fetch("/api/list");
255const data = await response.json();
256return data.rows;
396deleteButton.textContent = "Deleting...";
397const response = await fetch(
398`/api/delete`,
399{
400method: "POST",
18return serveFile(path, import.meta.url);
19}
20if (path.startsWith("/api/list")) {
21// Get all rows from lab_upload_blobs
22const response = await sqlite.execute(`
26return Response.json({ ok: true, rows: response.rows });
27}
28if (path.startsWith("/api/upload")) {
29return upload(req);
30}
31if (path.startsWith("/api/delete")) {
32return _delete(req);
33}
OpenTownieCreateBranch.tsx1 match
43
44try {
45const response = await fetch("/api/create-branch", {
46method: "POST",
47headers: {
apricothello.http.ts2 matches
7<meta name="viewport" content="width=device-width, initial-scale=1.0">
8<title>Cremini</title>
9<link rel="preconnect" href="https://fonts.googleapis.com">
10<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
11<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&display=swap" rel="stylesheet">
12<style>
13body {
HTTP101POSTrequestFormGuide1 match
61I'm being so specific with the name of the variable because that's industry standard.</li>
62<li>The next step is to manipulate the request so it can be useful. There are a lot
63of ways to manipulate the object and if you're curious read <a href="https://developer.mozilla.org/en-US/docs/Web/API/FormData#instance_methodsrun">this documentation</a>.
64The way we're using is .getAll(). The name of the const variable doesn't matter. The input to .getAll()
65is the value of the name attribute. Since I realized my description might not be clear,
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
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({