Create edit

Creates a new edit for the provided input, instruction, and parameters.

Script openai Verified

by hugo697 ยท 12/1/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 372 days ago
1
type Openai = {
2
  api_key: string;
3
  organization_id: string;
4
};
5
/**
6
 * Create edit
7
 * Creates a new edit for the provided input, instruction, and parameters.
8
 */
9
export async function main(
10
  auth: Openai,
11
  body: {
12
    instruction: string;
13
    model: string | ("text-davinci-edit-001" | "code-davinci-edit-001");
14
    input?: string;
15
    n?: number;
16
    temperature?: number;
17
    top_p?: number;
18
    [k: string]: unknown;
19
  }
20
) {
21
  const url = new URL(`https://api.openai.com/v1/edits`);
22

23
  const response = await fetch(url, {
24
    method: "POST",
25
    headers: {
26
      "OpenAI-Organization": auth.organization_id,
27
      "Content-Type": "application/json",
28
      Authorization: "Bearer " + auth.api_key,
29
    },
30
    body: JSON.stringify(body),
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