//native
type Cohere = {
apiKey: string;
};
/**
* Detokenize
* This endpoint takes tokens using byte-pair encoding and returns their text representation. To learn more about tokenization and byte pair encoding, see the tokens page.
*/
export async function main(
auth: Cohere,
body: { tokens: number[]; model: string },
) {
const url = new URL(`https://api.cohere.com/v1/detokenize`);
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