@nomyx/assistant
Version:
A powerful assistant library and cli for your AI projects. works with Vertex AI (Claude and Gemini)
31 lines (30 loc) • 1.07 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.embed = embed;
exports.embedBatch = embedBatch;
const axios_1 = __importDefault(require("axios"));
async function embed(config, text) {
const url = config.getApiUrl('embeddings');
const requestBody = { input: text };
const response = await axios_1.default.post(url, requestBody, {
headers: {
'Content-Type': 'application/json',
'api-key': config.apiKey,
},
});
return response.data.data[0].embedding;
}
async function embedBatch(config, texts) {
const url = config.getApiUrl('embeddings');
const requestBody = { input: texts };
const response = await axios_1.default.post(url, requestBody, {
headers: {
'Content-Type': 'application/json',
'api-key': config.apiKey,
},
});
return response.data.data.map(item => item.embedding);
}