1 |
|
2 | type Ai21 = { |
3 | apiKey: string; |
4 | }; |
5 |
|
6 | * Search |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Ai21, |
11 | body: { |
12 | query: string; |
13 | maxSegments?: number; |
14 | path?: string; |
15 | labels?: string[]; |
16 | labels_filter?: {} | {} | {}; |
17 | labels_filter_mode?: "AND" | "OR"; |
18 | fileIds?: string[]; |
19 | retrievalStrategy?: "segments" | "default" | "add_neighbors" | "full_doc"; |
20 | maxNeighbors?: number; |
21 | retrievalSimilarityThreshold?: number; |
22 | hybridSearchAlpha?: number; |
23 | }, |
24 | ) { |
25 | const url = new URL(`https://api.ai21.com/studio/v1/library/search`); |
26 |
|
27 | const response = await fetch(url, { |
28 | method: "POST", |
29 | headers: { |
30 | "Content-Type": "application/json", |
31 | Authorization: "Bearer " + auth.apiKey, |
32 | }, |
33 | body: JSON.stringify(body), |
34 | }); |
35 | if (!response.ok) { |
36 | const text = await response.text(); |
37 | throw new Error(`${response.status} ${text}`); |
38 | } |
39 | return await response.json(); |
40 | } |
41 |
|