multi-llm
Version:
A unified TypeScript/JavaScript package to use LLMs across ALL platforms with support for 17 major providers, streaming, MCP tools, and intelligent response parsing
39 lines • 1.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LLM = void 0;
const retry_1 = require("./utils/retry");
const child_process_1 = require("child_process");
class LLM {
constructor(provider, modelId) {
this.mcpProcesses = [];
this.provider = provider;
this.modelId = modelId;
}
addMCP(startupCommand) {
const [command, ...args] = startupCommand.split(' ');
const process = (0, child_process_1.spawn)(command, args, {
stdio: ['pipe', 'pipe', 'pipe']
});
this.mcpProcesses.push(process);
}
async chat(content, options = {}, streamCallback) {
const messages = [
{ role: 'user', content }
];
if (options.system) {
messages.unshift({ role: 'system', content: options.system });
}
const retryConfig = (0, retry_1.getRetryConfig)(options);
return (0, retry_1.executeWithRetry)(async () => this.provider.chat(this.modelId, messages, options, streamCallback), retryConfig, `${this.provider.constructor.name}:${this.modelId}`);
}
dispose() {
this.mcpProcesses.forEach(process => {
if (!process.killed) {
process.kill();
}
});
this.mcpProcesses = [];
}
}
exports.LLM = LLM;
//# sourceMappingURL=llm.js.map