0
List paginated fine tuning jobs
One script reply has been approved by the moderators Verified

List your organization's fine-tuning jobs

Created by hugo697 136 days ago Viewed 3723 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 136 days ago
1
type Openai = {
2
  api_key: string;
3
  organization_id: string;
4
};
5
/**
6
 * List paginated fine tuning jobs
7
 * List your organization's fine-tuning jobs
8

9
 */
10
export async function main(
11
  auth: Openai,
12
  after: string | undefined,
13
  limit: string | undefined
14
) {
15
  const url = new URL(`https://api.openai.com/v1/fine_tuning/jobs`);
16
  for (const [k, v] of [
17
    ["after", after],
18
    ["limit", limit],
19
  ]) {
20
    if (v !== undefined && v !== "") {
21
      url.searchParams.append(k, v);
22
    }
23
  }
24
  const response = await fetch(url, {
25
    method: "GET",
26
    headers: {
27
      "OpenAI-Organization": auth.organization_id,
28
      Authorization: "Bearer " + auth.api_key,
29
    },
30
    body: undefined,
31
  });
32
  if (!response.ok) {
33
    const text = await response.text();
34
    throw new Error(`${response.status} ${text}`);
35
  }
36
  return await response.json();
37
}
38