0
List fine tune events
One script reply has been approved by the moderators Verified

Get fine-grained status updates for a fine-tune job.

Created by hugo697 156 days ago Viewed 5549 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 156 days ago
1
type Openai = {
2
  api_key: string;
3
  organization_id: string;
4
};
5
/**
6
 * List fine tune events
7
 * Get fine-grained status updates for a fine-tune job.
8

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