type Openai = {
api_key: string;
organization_id: string;
};
/**
* Create chat completion
* Creates a model response for the given chat conversation.
*/
export async function main(
auth: Openai,
body: {
messages: (
| { content: string; role: "system"; name?: string; [k: string]: unknown }
| {
content:
| string
| (
| { type: "text"; text: string; [k: string]: unknown }
| {
type: "image_url";
image_url: {
url: string;
detail?: "auto" | "low" | "high";
[k: string]: unknown;
};
[k: string]: unknown;
}
)[];
role: "user";
name?: string;
[k: string]: unknown;
}
| {
content?: string;
role: "assistant";
name?: string;
tool_calls?: {
id: string;
type: "function";
function: { name: string; arguments: string; [k: string]: unknown };
[k: string]: unknown;
}[];
function_call?: {
arguments: string;
name: string;
[k: string]: unknown;
};
[k: string]: unknown;
}
| {
role: "tool";
content: string;
tool_call_id: string;
[k: string]: unknown;
}
| {
role: "function";
content: string;
name: string;
[k: string]: unknown;
}
)[];
model:
| string
| (
| "gpt-4-0125-preview"
| "gpt-4-turbo-preview"
| "gpt-4-1106-preview"
| "gpt-4-vision-preview"
| "gpt-4"
| "gpt-4-0314"
| "gpt-4-0613"
| "gpt-4-32k"
| "gpt-4-32k-0314"
| "gpt-4-32k-0613"
| "gpt-3.5-turbo"
| "gpt-3.5-turbo-16k"
| "gpt-3.5-turbo-0301"
| "gpt-3.5-turbo-0613"
| "gpt-3.5-turbo-1106"
| "gpt-3.5-turbo-0125"
| "gpt-3.5-turbo-16k-0613"
);
frequency_penalty?: number;
logit_bias?: { [k: string]: number };
logprobs?: boolean;
top_logprobs?: number;
max_tokens?: number;
n?: number;
presence_penalty?: number;
response_format?: { type?: "text" | "json_object"; [k: string]: unknown };
seed?: number;
stop?: string | string[];
stream?: boolean;
temperature?: number;
top_p?: number;
tools?: {
type: "function";
function: {
description?: string;
name: string;
parameters?: { [k: string]: unknown };
[k: string]: unknown;
};
[k: string]: unknown;
}[];
tool_choice?:
| ("none" | "auto")
| {
type: "function";
function: { name: string; [k: string]: unknown };
[k: string]: unknown;
};
user?: string;
function_call?: ("none" | "auto") | { name: string; [k: string]: unknown };
functions?: {
description?: string;
name: string;
parameters?: { [k: string]: unknown };
[k: string]: unknown;
}[];
[k: string]: unknown;
}
) {
const url = new URL(`https://api.openai.com/v1/chat/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 255 days ago
type Openai = {
api_key: string;
organization_id: string;
};
/**
* Create chat completion
* Creates a model response for the given chat conversation.
*/
export async function main(
auth: Openai,
body: {
messages: (
| { content: string; role: "system"; name?: string; [k: string]: unknown }
| {
content:
| string
| (
| { type: "text"; text: string; [k: string]: unknown }
| {
type: "image_url";
image_url: {
url: string;
detail?: "auto" | "low" | "high";
[k: string]: unknown;
};
[k: string]: unknown;
}
)[];
role: "user";
name?: string;
[k: string]: unknown;
}
| {
content?: string;
role: "assistant";
name?: string;
tool_calls?: {
id: string;
type: "function";
function: { name: string; arguments: string; [k: string]: unknown };
[k: string]: unknown;
}[];
function_call?: {
arguments: string;
name: string;
[k: string]: unknown;
};
[k: string]: unknown;
}
| {
role: "tool";
content: string;
tool_call_id: string;
[k: string]: unknown;
}
| {
role: "function";
content: string;
name: string;
[k: string]: unknown;
}
)[];
model:
| string
| (
| "gpt-4-0125-preview"
| "gpt-4-turbo-preview"
| "gpt-4-1106-preview"
| "gpt-4-vision-preview"
| "gpt-4"
| "gpt-4-0314"
| "gpt-4-0613"
| "gpt-4-32k"
| "gpt-4-32k-0314"
| "gpt-4-32k-0613"
| "gpt-3.5-turbo"
| "gpt-3.5-turbo-16k"
| "gpt-3.5-turbo-0301"
| "gpt-3.5-turbo-0613"
| "gpt-3.5-turbo-1106"
| "gpt-3.5-turbo-16k-0613"
);
frequency_penalty?: number;
logit_bias?: { [k: string]: number };
logprobs?: boolean;
top_logprobs?: number;
max_tokens?: number;
n?: number;
presence_penalty?: number;
response_format?: { type?: "text" | "json_object"; [k: string]: unknown };
seed?: number;
stop?: string | string[];
stream?: boolean;
temperature?: number;
top_p?: number;
tools?: {
type: "function";
function: {
description?: string;
name: string;
parameters?: { [k: string]: unknown };
[k: string]: unknown;
};
[k: string]: unknown;
}[];
tool_choice?:
| ("none" | "auto")
| {
type: "function";
function: { name: string; [k: string]: unknown };
[k: string]: unknown;
};
user?: string;
function_call?: ("none" | "auto") | { name: string; [k: string]: unknown };
functions?: {
description?: string;
name: string;
parameters?: { [k: string]: unknown };
[k: string]: unknown;
}[];
[k: string]: unknown;
}
) {
const url = new URL(`https://api.openai.com/v1/chat/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 291 days ago
type Openai = {
api_key: string;
organization_id: string;
};
/**
* Create chat completion
* Creates a model response for the given chat conversation.
*/
export async function main(
auth: Openai,
body: {
messages: (
| { content: string; role: "system"; name?: string; [k: string]: unknown }
| {
content:
| string
| (
| { type: "text"; text: string; [k: string]: unknown }
| {
type: "image_url";
image_url: {
url: string;
detail?: "auto" | "low" | "high";
[k: string]: unknown;
};
[k: string]: unknown;
}
)[];
role: "user";
name?: string;
[k: string]: unknown;
}
| {
content: string;
role: "assistant";
name?: string;
tool_calls?: {
id: string;
type: "function";
function: { name: string; arguments: string; [k: string]: unknown };
[k: string]: unknown;
}[];
function_call?: {
arguments: string;
name: string;
[k: string]: unknown;
};
[k: string]: unknown;
}
| {
role: "tool";
content: string;
tool_call_id: string;
[k: string]: unknown;
}
| {
role: "function";
arguments: string;
name?: string;
[k: string]: unknown;
}
)[];
model:
| string
| (
| "gpt-4-1106-preview"
| "gpt-4-vision-preview"
| "gpt-4"
| "gpt-4-0314"
| "gpt-4-0613"
| "gpt-4-32k"
| "gpt-4-32k-0314"
| "gpt-4-32k-0613"
| "gpt-3.5-turbo"
| "gpt-3.5-turbo-16k"
| "gpt-3.5-turbo-0301"
| "gpt-3.5-turbo-0613"
| "gpt-3.5-turbo-1106"
| "gpt-3.5-turbo-16k-0613"
);
frequency_penalty?: number;
logit_bias?: { [k: string]: number };
max_tokens?: number & string;
n?: number;
presence_penalty?: number;
response_format?: { type?: "text" | "json_object"; [k: string]: unknown };
seed?: number;
stop?: string | string[];
stream?: boolean;
temperature?: number;
top_p?: number;
tools?: {
type: "function";
function: {
description?: string;
name: string;
parameters: { [k: string]: unknown };
[k: string]: unknown;
};
[k: string]: unknown;
}[];
tool_choice?:
| ("none" | "auto")
| {
type?: "function";
function?: { name: string; [k: string]: unknown };
[k: string]: unknown;
};
user?: string;
function_call?: ("none" | "auto") | { name: string; [k: string]: unknown };
functions?: {
description?: string;
name: string;
parameters: { [k: string]: unknown };
[k: string]: unknown;
}[];
[k: string]: unknown;
}
) {
const url = new URL(`https://api.openai.com/v1/chat/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 351 days ago