seraph-agent
Version:
An extremely lightweight, SRE autonomous AI agent for seamless integration with common observability tasks.
50 lines (49 loc) • 1.77 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HuggingFaceEmbeddings = void 0;
const embeddings_1 = require("@langchain/core/embeddings");
const https_1 = __importDefault(require("https"));
class HuggingFaceEmbeddings extends embeddings_1.Embeddings {
serviceUrl;
agent;
constructor(model = 'sentence-transformers/all-MiniLM-L6-v2') {
super({ modelName: model });
this.serviceUrl = 'https://127.0.0.1:5001/embed';
this.agent = new https_1.default.Agent({
rejectUnauthorized: false,
});
}
async callService(texts) {
try {
const response = await fetch(this.serviceUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ texts }),
agent: this.agent,
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return data.embeddings;
}
catch (error) {
console.error('Error calling embedding service:', error);
// Return a list of zero vectors as a fallback
return texts.map(() => new Array(384).fill(0));
}
}
async embedDocuments(texts) {
return this.callService(texts);
}
async embedQuery(text) {
const embeddings = await this.callService([text]);
return embeddings[0];
}
}
exports.HuggingFaceEmbeddings = HuggingFaceEmbeddings;