//native
type Deepinfra = {
token: string;
};
/**
* Openai Chat Completions
*
*/
export async function main(
auth: Deepinfra,
x_deepinfra_source: string,
user_agent: string,
body: {
model: string;
messages:
| { role?: "tool"; content: string; tool_call_id: string }
| {
role?: "assistant";
content?: string;
name?: string;
tool_calls?: {
id: string;
type: string;
function: { name: string; arguments: string };
}[];
}
| {
role?: "user";
content:
| string
| { type: "text"; text: string }
| {
type: "image_url";
image_url: { url: string; detail?: "auto" | "low" | "high" };
}[];
name?: string;
}
| { role?: "system"; content: string; name?: string }[];
stream?: false | true;
temperature?: number;
top_p?: number;
min_p?: number;
top_k?: number;
max_tokens?: number;
stop?: string | string[];
n?: number;
presence_penalty?: number;
frequency_penalty?: number;
tools?: {
type?: string;
function: { name: string; description?: string; parameters?: {} };
}[];
tool_choice?: string;
response_format?: { type?: "text" | "json_object" };
repetition_penalty?: number;
user?: string;
seed?: number;
},
) {
const url = new URL(`https://api.deepinfra.com/v1/openai/chat/completions`);
const response = await fetch(url, {
method: "POST",
headers: {
"x-deepinfra-source": x_deepinfra_source,
"user-agent": user_agent,
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
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 235 days ago