type Openai = {
api_key: string;
organization_id: string;
};
/**
* Create completion
* Creates a completion for the provided prompt and parameters.
*/
export async function main(
auth: Openai,
body: {
model: string | ("gpt-3.5-turbo-instruct" | "davinci-002" | "babbage-002");
prompt: string | string[] | number[] | number[][];
best_of?: number;
echo?: boolean;
frequency_penalty?: number;
logit_bias?: { [k: string]: number };
logprobs?: number;
max_tokens?: number;
n?: number;
presence_penalty?: number;
seed?: number;
stop?: string | string[];
stream?: boolean;
suffix?: string;
temperature?: number;
top_p?: number;
user?: string;
[k: string]: unknown;
}
) {
const url = new URL(`https://api.openai.com/v1/completions`);
const response = await fetch(url, {
method: "POST",
headers: {
"OpenAI-Organization": auth.organization_id,
"Content-Type": "application/json",
Authorization: "Bearer " + auth.api_key,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 311 days ago
type Openai = {
api_key: string;
organization_id: string;
};
/**
* Create completion
* Creates a completion for the provided prompt and parameters.
*/
export async function main(
auth: Openai,
body: {
model:
| string
| (
| "babbage-002"
| "davinci-002"
| "gpt-3.5-turbo-instruct"
| "text-davinci-003"
| "text-davinci-002"
| "text-davinci-001"
| "code-davinci-002"
| "text-curie-001"
| "text-babbage-001"
| "text-ada-001"
);
prompt: string | string[] | number[] | number[][];
best_of?: number;
echo?: boolean;
frequency_penalty?: number;
logit_bias?: { [k: string]: number };
logprobs?: number;
max_tokens?: number;
n?: number;
presence_penalty?: number;
seed?: number;
stop?: string | string[];
stream?: boolean;
suffix?: string;
temperature?: number;
top_p?: number;
user?: string;
[k: string]: unknown;
}
) {
const url = new URL(`https://api.openai.com/v1/completions`);
const response = await fetch(url, {
method: "POST",
headers: {
"OpenAI-Organization": auth.organization_id,
"Content-Type": "application/json",
Authorization: "Bearer " + auth.api_key,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 371 days ago