//native
type Cohere = {
apiKey: string;
};
/**
* Classify
* This endpoint makes a prediction about which label fits the specified text inputs best. To make a prediction, Classify uses the provided `examples` of text + label pairs as a reference.
Note: [Fine-tuned models](https://docs.cohere.com/docs/classify-fine-tuning) trained on classification examples don't require the `examples` parameter to be passed in explicitly.
*/
export async function main(
auth: Cohere,
body: {
inputs: string[];
examples?: { text?: string; label?: string }[];
model?: string;
preset?: string;
truncate?: "NONE" | "START" | "END";
},
) {
const url = new URL(`https://api.cohere.com/v1/classify`);
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