type Openai = {
api_key: string;
organization_id: string;
};
/**
* Create embedding
* Creates an embedding vector representing the input text.
*/
export async function main(
auth: Openai,
body: {
input: string | string[] | number[] | number[][];
model:
| string
| (
| "text-embedding-ada-002"
| "text-embedding-3-small"
| "text-embedding-3-large"
);
encoding_format?: "float" | "base64";
dimensions?: number;
user?: string;
}
) {
const url = new URL(`https://api.openai.com/v1/embeddings`);
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 328 days ago
type Openai = {
api_key: string;
organization_id: string;
};
/**
* Create embedding
* Creates an embedding vector representing the input text.
*/
export async function main(
auth: Openai,
body: {
input: string | string[] | number[] | number[][];
model: string | "text-embedding-ada-002";
encoding_format?: "float" | "base64";
user?: string;
}
) {
const url = new URL(`https://api.openai.com/v1/embeddings`);
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 387 days ago