0
Create fine tuning job
One script reply has been approved by the moderators Verified

Creates a fine-tuning job which begins the process of creating a new model from a given dataset.

Response includes details of the enqueued job including job status and the name of the fine-tuned models once complete.

Learn more about fine-tuning

Created by hugo697 608 days ago Viewed 22486 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 608 days ago
1
type Openai = {
2
  api_key: string;
3
  organization_id: string;
4
};
5
/**
6
 * Create fine tuning job
7
 * Creates a fine-tuning job which begins the process of creating a new model from a given dataset.
8

9
Response includes details of the enqueued job including job status and the name of the fine-tuned models once complete.
10

11
Learn more about fine-tuning
12

13
 */
14
export async function main(
15
  auth: Openai,
16
  body: {
17
    model: string | ("babbage-002" | "davinci-002" | "gpt-3.5-turbo");
18
    training_file: string;
19
    hyperparameters?: {
20
      batch_size?: "auto" | number;
21
      learning_rate_multiplier?: "auto" | number;
22
      n_epochs?: "auto" | number;
23
      [k: string]: unknown;
24
    };
25
    suffix?: string;
26
    validation_file?: string;
27
    [k: string]: unknown;
28
  }
29
) {
30
  const url = new URL(`https://api.openai.com/v1/fine_tuning/jobs`);
31

32
  const response = await fetch(url, {
33
    method: "POST",
34
    headers: {
35
      "OpenAI-Organization": auth.organization_id,
36
      "Content-Type": "application/json",
37
      Authorization: "Bearer " + auth.api_key,
38
    },
39
    body: JSON.stringify(body),
40
  });
41
  if (!response.ok) {
42
    const text = await response.text();
43
    throw new Error(`${response.status} ${text}`);
44
  }
45
  return await response.json();
46
}
47