query hub scripts by similarity

Script windmill Verified

by admin ยท 10/22/2023

The script

Submitted by admin Typescript (fetch-only)
Verified 370 days ago
1
/**
2
 * query hub scripts by similarity
3
 *
4
 */
5
export async function main(
6
  text: string | undefined,
7
  kind: string | undefined,
8
  limit: string | undefined,
9
  app: string | undefined
10
) {
11
  const url = new URL(`${BASE_URL}/api/embeddings/query_hub_scripts`);
12
  for (const [k, v] of [
13
    ["text", text],
14
    ["kind", kind],
15
    ["limit", limit],
16
    ["app", app],
17
  ]) {
18
    if (v !== undefined && v !== "") {
19
      url.searchParams.append(k, v);
20
    }
21
  }
22
  const response = await fetch(url, {
23
    method: "GET",
24
    headers: {
25
      Authorization: "Bearer " + WM_TOKEN,
26
    },
27
    body: undefined,
28
  });
29
  if (!response.ok) {
30
    const text = await response.text();
31
    throw new Error(`${response.status} ${text}`);
32
  }
33
  return await response.json();
34
}
35