UNPKG

skailan-ai

Version:

Servicio de IA y procesamiento de lenguaje natural para Skailan

57 lines 2.76 kB
import { SentimentAnalysisService } from '../../domain/services/SentimentAnalysisService'; import { LLMConfigPrismaRepository } from '../../infra/database/prisma/LLMConfigPrismaRepository'; export const analyzeSentiment = async (req, res) => { try { const { text, llmConfigName } = req.body; const organizationId = req.organization?.id; if (!organizationId) { return res.status(400).json({ error: 'Organization ID not found in request.' }); } if (!text) { return res.status(400).json({ error: 'Text is required.' }); } const prisma = req.tenantPrisma; if (!prisma) { return res.status(500).json({ error: 'Prisma client not initialized for tenant.' }); } const llmConfigRepository = new LLMConfigPrismaRepository(prisma); const llmConfig = await llmConfigRepository.findByName(llmConfigName || 'default', organizationId); if (!llmConfig || !llmConfig.isActive) { return res.status(400).json({ error: 'LLM configuration not found or inactive.' }); } const sentimentService = new SentimentAnalysisService(llmConfig); const result = await sentimentService.analyzeSentiment(text); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message || 'Error analyzing sentiment.' }); } }; export const analyzeConversationSentiment = async (req, res) => { try { const { messages, llmConfigName } = req.body; const organizationId = req.organization?.id; if (!organizationId) { return res.status(400).json({ error: 'Organization ID not found in request.' }); } if (!messages || !Array.isArray(messages)) { return res.status(400).json({ error: 'Messages array is required.' }); } const prisma = req.tenantPrisma; if (!prisma) { return res.status(500).json({ error: 'Prisma client not initialized for tenant.' }); } const llmConfigRepository = new LLMConfigPrismaRepository(prisma); const llmConfig = await llmConfigRepository.findByName(llmConfigName || 'default', organizationId); if (!llmConfig || !llmConfig.isActive) { return res.status(400).json({ error: 'LLM configuration not found or inactive.' }); } const sentimentService = new SentimentAnalysisService(llmConfig); const result = await sentimentService.analyzeConversationSentiment(messages); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message || 'Error analyzing conversation sentiment.' }); } }; //# sourceMappingURL=sentimentController.js.map