clip-embeddings / huggingFace.js
bberube's picture
More dev
e6b7161
import * as dotenv from "dotenv";
dotenv.config();
const inferenceEndpointUrl = process.env.INFERENCE_ENDPOINT;
const inferenceEndpointToken = process.env.INFERENCE_ENDPOINT_TOKEN;
const getEmbeddings = async (imageBase64, words) => {
const data = {
inputs: {
image: imageBase64,
words: words.length > 0 ? words : ["default"],
},
};
try {
const response = await fetch(inferenceEndpointUrl, {
method: "POST",
headers: {
Authorization: `Bearer ${inferenceEndpointToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
const json = await response.json();
return json.embeddings;
} catch (e) {
console.log("Failed to get embeddings", e);
}
};
export { getEmbeddings };