UNPKG

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.

46 lines 1.77 kB
import { logger } from '../utils/logger'; export class CommanMethods { static convertReadableToResponse(readable) { return new Response(readable, { headers: new Headers(), status: 200, statusText: 'OK', }); } static omitModelToAssistantInContents(contents) { logger.info('content before omitting model to assistant:', JSON.stringify(contents, null, 2)); const result = contents.map(content => { const role = content.role === 'model' ? 'assistant' : content.role || 'user'; const message = { role: role, content: Array.isArray(content.parts) ? content.parts .map((part) => { if (part && typeof part === 'object' && 'text' in part && typeof part.text === 'string') { return part.text; } return ''; }) .join('\n') : '', }; return message; }); logger.info('content after omitting model to assistant:', JSON.stringify(result, null, 2)); return result; } static validateContents(contents) { if (!contents || contents.length === 0) { throw new Error('Contents array cannot be empty'); } for (const content of contents) { CommanMethods.validateContent(content); } } static validateContent(content) { if (!content || typeof content !== 'object' || !('role' in content) || !('parts' in content)) { throw new Error('Invalid content object'); } } } //# sourceMappingURL=comman.js.map