//native
type Groq = {
api_key: string;
};
/**
* Creates an embedding vector representing the input text.
*
*/
export async function main(
auth: Groq,
body: {
encoding_format?: "float" | "base64";
input: string | string[];
model: string;
user?: string;
},
) {
const url = new URL(`https://api.groq.com/openai/v1/embeddings`);
const response = await fetch(url, {
method: "POST",
headers: {
"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 235 days ago