openlit
Version:
OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications, facilitating the integration of observability into your GenAI-driven projects
39 lines • 1.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseLlmResponse = parseLlmResponse;
exports.formatPrompt = formatPrompt;
exports.formatCustomCategories = formatCustomCategories;
function parseLlmResponse(response) {
try {
return JSON.parse(response);
}
catch (err) {
// Log the error and the original response for debugging
console.error('Failed to parse model response:', err, 'Original response:', response);
return {
verdict: 'no',
evaluation: 'Hallucination',
score: 0,
classification: 'none',
explanation: `Failed to parse model response: ${(err instanceof Error) ? err.message : String(err)}`
};
}
}
function formatPrompt(systemPrompt, input) {
let prompt = systemPrompt;
if (input.prompt)
prompt += `\nPrompt: ${input.prompt}`;
if (input.contexts)
prompt += `\nContexts: ${input.contexts.join(' | ')}`;
if (input.text)
prompt += `\nText: ${input.text}`;
return prompt;
}
function formatCustomCategories(customCategories, sectionLabel) {
if (!customCategories || Object.keys(customCategories).length === 0)
return '';
const label = sectionLabel ? `Additional ${sectionLabel} Categories:` : 'Additional Categories:';
const lines = Object.entries(customCategories).map(([key, value]) => `- ${key}: ${value}`);
return `\n${label}\n${lines.join('\n')}`;
}
//# sourceMappingURL=utils.js.map