18 lines
506 B
JavaScript
18 lines
506 B
JavaScript
const {getEnv, SERVICES } = require('@nexusai/shared')
|
|
|
|
const BASE_URL = getEnv('EMBEDDING_SERVICE_URL', SERVICES.EMBEDDING_URL);
|
|
|
|
async function embed(text) {
|
|
const res = await fetch(`${BASE_URL}/embed`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json'},
|
|
body: JSON.stringify({text}),
|
|
})
|
|
|
|
if (!res.ok) throw new Error(`Embedding service error: ${res.status}`);
|
|
|
|
const data = await res.json();
|
|
return data.embedding;
|
|
}
|
|
|
|
module.exports = { embed }; |