Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/?q=function&page=650&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=function

Returns an array of strings in format "username" or "username/projectName"

Found 10262 results for "function"(571ms)

askSMHI

askSMHIservice17 matches

@ljus•Updated 1 month ago
10import { zodToJSONSchema } from "./smhi/toolSchema";
11
12export async function callWeatherGPT(question: string) {
13 if (!question?.length) {
14 return { error: "Ask something" };
22 return { error: "Be nice in your question" };
23 }
24 const weatherFunction = await zodToJSONSchema();
25 const max_completion_tokens = 256;
26 const now = new Date();
52 temperature: 0.7,
53 tools: [{
54 type: "function",
55 function: {
56 name: "getWeather",
57 description: weatherFunction.description,
58 parameters: {
59 type: weatherFunction.type,
60 properties: weatherFunction.properties,
61 required: weatherFunction.required,
62 },
63 },
71 tool_calls: v.array(v.object({
72 id: v.string(),
73 type: v.literal("function"),
74 function: v.object({ name: v.string(), arguments: v.string() }),
75 })),
76 }),
92 });
93 const matchingMessage = completion.choices?.find((choice) => choice.finish_reason === "tool_calls")?.message;
94 const functionCall = matchingMessage?.tool_calls?.at(0);
95 if (!functionCall) {
96 const firstMessage = completion.choices[0].message;
97 const answer = "content" in firstMessage ? firstMessage.content : null;
98 return answer ? { answer } : { error: "Ask questions about the weather" };
99 }
100 const { name: functionName, arguments: argumentsString } = functionCall.function;
101 if (!argumentsString) {
102 return {
115 paramaters: dataPoints,
116 });
117 const functionMessageContent = `
118 The following is the response schema
119 \`\`\`\n${JSON.stringify(zodSchema.schema)}\`\`\`\n
127 "role": "tool" as const,
128 "tool_call_id": matchingMessage.tool_calls?.at(0)!.id!,
129 content: functionMessageContent,
130 }]
131 : [];
132 const formattedFunctionResponseData = await openai.chat.completions.create({
133 model: completionOptions.model,
134 store: completionOptions.store,
138 });
139 return {
140 summary: formattedFunctionResponseData.choices[0].message.content
141 ?? "something went wrong",
142 data: forecastResponse,
askSMHI

askSMHIservice1 match

@ljus•Updated 1 month ago
1import { offset, removeOffset } from "npm:@formkit/tempo";
2import { fetchWeatherAtCoordinate } from "./fetcher";
3export async function getWeatherAtCoordinate(
4 lon: number,
5 lat: number,
askSMHI

askSMHIschema1 match

@ljus•Updated 1 month ago
1import { toJsonSchema } from "npm:@valibot/to-json-schema";
2import * as v from "npm:valibot";
3export async function getSmhiForecastResponseZodSchema(
4 arg: {
5 option: "parse";
askSMHI

askSMHIdescribe2 matches

@ljus•Updated 1 month ago
1export function describeWeatherSymbolCode(code: number) {
2 const weatherSymbols = [
3 "Clear sky",
31 return weatherSymbols[code - 1];
32}
33export function describePcat(code: number) {
34 const categories = [
35 "No precipitation",
askSMHI

askSMHIfetcher1 match

@ljus•Updated 1 month ago
3import { describePcat, describeWeatherSymbolCode } from "./describe";
4
5export async function fetchWeatherAtCoordinate(lon: number, lat: number) {
6 if (!lon || isNaN(lon)) {
7 return null;
askSMHI

askSMHImoderation1 match

@ljus•Updated 1 month ago
3import { OpenAI } from "npm:openai";
4
5export async function openAIModeration(publicMessages: string[]) {
6 const openAIKey = process.env.OPENAI_CHAT;
7 const headers = {

newCerebrasModelAlertmain.tsx1 match

@stevekrouse•Updated 1 month ago
3import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
4
5export default async function(interval: Interval) {
6 try {
7 const historicalModels = await blob.getJSON("cerebras-models.json");

TodoAppmain.tsx6 matches

@stevekrouse•Updated 1 month ago
4// import { Form, hydrate } from "https://esm.town/v/stevekrouse/ssr_react_mini?v=75";
5
6// export async function loader(req: Request) {
7// const { sqlite } = await import("https://esm.town/v/std/sqlite?v=4");
8// const [, { columns, rows }] = await sqlite.batch([
19// }
20
21// export async function action(req: Request) {
22// const { sqlite } = await import("https://esm.town/v/std/sqlite?v=4");
23// const formData = await req.formData();
46// }
47
48// export function Component({ initialTodos, initialLogs }) {
49// const [todos, setTodos] = useState(initialTodos);
50// const [logs, setLogs] = useState(initialLogs);
53// useEffect(() => addLog(`Client rendered`), []);
54
55// function addTodo() {
56// setTodos([...todos, { text: newTodo }]);
57// setNewTodo("");
63// }
64
65// function toggleTodo(e) {
66// const formData = new FormData(e.target);
67// const id = parseInt(formData.get("id") as string);
70// }
71
72// function deleteTodo(e) {
73// const formData = new FormData(e.target);
74// const id = parseInt(formData.get("id") as string);

SSEDemomain.tsx1 match

@stevekrouse•Updated 1 month ago
1const msg = new TextEncoder().encode("data: hello\r\n\r\n");
2
3export default async function(req: Request): Promise<Response> {
4 let timerId: number | undefined;
5 try {

annual_feedbackmain.tsx1 match

@stevekrouse•Updated 1 month ago
17)`);
18
19async function addFeedback(req: Request) {
20 const formData = await req.formData();
21 let data = Object.fromEntries(formData.entries());

getFileEmail4 file matches

@shouser•Updated 1 week ago
A helper function to build a file's email

TwilioHelperFunctions

@vawogbemi•Updated 2 months ago