1 | |
2 | * run script by path in openai format |
3 | * |
4 | */ |
5 | export async function main( |
6 | workspace: string, |
7 | path: string, |
8 | parent_job: string | undefined, |
9 | job_id: string | undefined, |
10 | include_header: string | undefined, |
11 | queue_limit: string | undefined, |
12 | body: { [k: string]: unknown } |
13 | ) { |
14 | const url = new URL( |
15 | `${BASE_URL}/api/w/${workspace}/jobs/openai_sync/p/${path}` |
16 | ); |
17 | for (const [k, v] of [ |
18 | ["parent_job", parent_job], |
19 | ["job_id", job_id], |
20 | ["include_header", include_header], |
21 | ["queue_limit", queue_limit], |
22 | ]) { |
23 | if (v !== undefined && v !== "") { |
24 | url.searchParams.append(k, v); |
25 | } |
26 | } |
27 | const response = await fetch(url, { |
28 | method: "POST", |
29 | headers: { |
30 | "Content-Type": "application/json", |
31 | Authorization: "Bearer " + WM_TOKEN, |
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 |
|