llmforge
Version:
One API, every AI model, instant switching. Change from GPT-4 to Gemini to local models with a single config update. LLMForge is the lightweight, TypeScript-first solution for multi-provider AI applications with zero vendor lock-in.
47 lines • 1.67 kB
JavaScript
export class RunnerClient {
constructor(config) {
this.config = config;
this.LLMClient = [];
}
static async create(config) {
const client = new RunnerClient(config);
await client.loadLLMClient();
return client;
}
async loadLLMClient() {
if (Array.isArray(this.config.llmConfig)) {
const { Factory } = await import('../providers/provider.factory');
for (const llmConfig of this.config.llmConfig) {
const client = await new Factory(llmConfig).create();
this.LLMClient.push(client);
}
}
else {
const { Factory } = await import('../providers/provider.factory');
this.LLMClient = [await new Factory(this.config.llmConfig).create()];
}
}
async run(content) {
if (!Array.isArray(this.LLMClient) || this.LLMClient.length === 0) {
throw new Error('No LLM clients available to run the content.');
}
try {
const responses = [];
for (const client of this.LLMClient) {
try {
const response = await client.generateContent({ contents: content });
responses.push(response);
}
catch (error) {
console.log('Error with client:', error);
}
}
return responses.length > 0 ? responses[0] : null; // Return first successful response
}
catch (error) {
console.log('Error: in methods', error);
throw error;
}
}
}
//# sourceMappingURL=index.js.map