Avatar

sdan

14 public vals
Joined August 21, 2023
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { fetch } from "https://esm.town/v/std/fetch";
export async function chatWithPdfRetriever(query: string, pdf_url: string) {
const loadUrl = "https://cardinal.tail8de85.ts.net/pdf/load";
const queryUrl = "https://cardinal.tail8de85.ts.net/pdf/query";
// First POST request to load the PDF
const loadResponse = await fetch(loadUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
"pdf_url": pdf_url,
}),
});
if (!loadResponse.ok) {
throw new Error(`Failed to load PDF. Status: ${loadResponse.status}`);
}
// Second POST request to query the loaded PDF
const queryResponse = await fetch(queryUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
"query": query,
"pdf_url": pdf_url,
}),
});
if (!queryResponse.ok) {
throw new Error(`Failed to query PDF. Status: ${queryResponse.status}`);
}
// Return the response from the second call
return await queryResponse.json();
}
1
2
3
4
5
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
// Returns NASA's Astronomy Picture of the Day (APOD)
export const nasaAPOD = fetchJSON("cutt.ly/T7ksirK");
// Forked from @iBrokeit.nasaAPOD
1
2
3
4
5
6
import { extractValArgs } from "https://esm.town/v/sdan/extractValArgs";
export async function getArgs(valName: string) {
const rep = await extractValArgs(valName);
return rep;
}
1
2
3
4
5
6
7
import { extractValArgs } from "https://esm.town/v/sdan/extractValArgs";
export async function functionZilla(fnc: string) {
let args = await extractValArgs(fnc);
console.log(args);
return args;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { fetch } from "https://esm.town/v/std/fetch";
export async function getWeather(city: string) {
try {
const response = await fetch(`https://wttr.in/${city}?format=j1`);
if (!response.ok) {
throw new Error(`Failed to fetch data for ${city}`);
}
const jsonData = await response.json();
const feelsLikeF = jsonData.current_condition[0].FeelsLikeF;
const weatherDescription =
jsonData.current_condition[0].weatherDesc[0].value;
return `${city}: feels like ${feelsLikeF}, ${weatherDescription}`;
}
catch (error) {
throw new Error(`Failed to fetch weather data: ${error}`);
}
}
1
2
3
4
5
6
7
8
9
import { extractValArgs } from "https://esm.town/v/sdan/extractValArgs";
export const untitled_coralChimpanzee = (async (fnc: string) => {
console.log(fnc);
const rep = await extractValArgs("sdan.getWeather");
console.log("coral chimp");
console.log(rep);
return rep;
})();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { fetch } from "https://esm.town/v/std/fetch";
export async function valToString(val: string) {
if (val.startsWith("@")) {
val = val.slice(1);
}
const [author, name] = val.split(".");
const resp = await fetch(`https://api.val.town/v1/alias/${author}/${name}`);
if (resp.status !== 200) {
throw new Error(resp.statusText);
}
const { code } = await resp.json();
return code as string;
}
1
2
3
import { extractValArgs } from "https://esm.town/v/pomdtr/extractValArgs?v=17";
export let untitled_blackFox = await extractValArgs("sdan.wikitxt");
1
2
3
4
5
6
7
8
9
10
import { extractArgs } from "https://esm.town/v/sdan/extractArgs";
import { valToString } from "https://esm.town/v/sdan/valToString";
export async function extractValArgs(val: string) {
const code = await valToString(val);
return extractArgs(code) as Promise<{
name: string;
type: string;
}[]>;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { fetch } from "https://esm.town/v/std/fetch";
export async function wikitxt(article: string) {
try {
const wiki = await fetch(
`https://en.wikipedia.org/w/api.php?action=query&format=json&titles=${article}&prop=extracts&explaintext`,
).then((res) => res.json());
if (!wiki.query) {
throw new Error("Please input a correct title");
}
const pages = wiki.query.pages;
const extract = pages[Object.keys(pages)[0]].extract;
return extract;
}
catch (error) {
throw new Error(`Wiki fetch failed: ${error}`);
}
}