//native
type Cohere = {
apiKey: string;
};
/**
* Embed
* This endpoint returns text embeddings. An embedding is a list of floating point numbers that captures semantic information about the text that it represents.
Embeddings can be used to create text classifiers as well as empower semantic search. To learn more about embeddings, see the embedding page.
If you want to learn more how to use the embedding model, have a look at the [Semantic Search Guide](https://docs.cohere.com/docs/semantic-search).
*/
export async function main(
auth: Cohere,
body: {
texts?: string[];
images?: string[];
model: string;
input_type:
| "search_document"
| "search_query"
| "classification"
| "clustering"
| "image";
embedding_types: "float" | "int8" | "uint8" | "binary" | "ubinary"[];
truncate?: "NONE" | "START" | "END";
},
) {
const url = new URL(`https://api.cohere.com/v2/embed`);
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