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.
50 lines • 1.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommanMethods = void 0;
const logger_1 = require("../utils/logger");
class CommanMethods {
static convertReadableToResponse(readable) {
return new Response(readable, {
headers: new Headers(),
status: 200,
statusText: 'OK',
});
}
static omitModelToAssistantInContents(contents) {
logger_1.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_1.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');
}
}
}
exports.CommanMethods = CommanMethods;
//# sourceMappingURL=comman.js.map