UNPKG

pulse-ai-utils

Version:

Utility functions and helpers for AI-powered applications

54 lines 2.02 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const openai_helper_1 = __importDefault(require("../helpers/openai-helper")); const zod_1 = require("zod"); class LLMQueryHandler { constructor(apiKey, llmHelper) { this.llmHelper = llmHelper || new openai_helper_1.default(apiKey); } async query(req, res) { const bodySchema = zod_1.z.object({ prompt: zod_1.z.string().optional(), categories: zod_1.z.array(zod_1.z.string()).optional(), systemPrompt: zod_1.z.string().optional(), model: zod_1.z.string().optional(), area: zod_1.z.string().optional(), source: zod_1.z.string().optional(), country: zod_1.z.string().optional(), region: zod_1.z.string().optional(), category: zod_1.z.string().optional(), timeline: zod_1.z.string().optional(), strategy: zod_1.z.enum(['web_search', 'rag_vector', 'rag_cache', 'rag_hybrid', 'query_cache', 'vector_only', 'hybrid_only']).optional(), }); let parsed; try { parsed = bodySchema.parse({ ...req.query, ...(req.body || {}) }); } catch (err) { if (res) { return res.status(400).json({ message: 'Missing parameters' }); } throw err; } try { const result = await this.llmHelper.runQuery(parsed); if (res) { res.json(result); } return result; } catch (err) { if (res) { const message = err.message || 'Failed to fetch data'; res.status(400).json({ message }); return; } throw err; } } } exports.default = LLMQueryHandler; //# sourceMappingURL=llm-query.js.map