//native
type Cohere = {
apiKey: string;
};
/**
* Rerank
* This endpoint takes in a query and a list of texts and produces an ordered array with each text assigned a relevance score.
*/
export async function main(
auth: Cohere,
body: {
model: string;
query: string;
documents: string[];
top_n?: number;
max_tokens_per_doc?: number;
},
) {
const url = new URL(`https://api.cohere.com/v2/rerank`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.apiKey,
},
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 428 days ago