feat: add digital-intern live-qa endpoints for pinpoint hearing assistance
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Response } from 'express';
|
||||
import { supabase } from '../lib/supabase';
|
||||
import { AuthenticatedRequest } from '../middleware/auth';
|
||||
import { runIddianameAnalysis, runCaseNarrativeAnalysis, runStatementAnalysis, runDeficiencyAnalysis, runStrategyAnalysis, runMediationAnalysis } from './document.controller';
|
||||
import { runIddianameAnalysis, runCaseNarrativeAnalysis, runStatementAnalysis, runDeficiencyAnalysis, runStrategyAnalysis, runMediationAnalysis, runDigitalInternQa } from './document.controller';
|
||||
import { findOrCreateCaseByTitle } from '../lib/caseLookup';
|
||||
|
||||
export const createCase = async (req: AuthenticatedRequest, res: Response) => {
|
||||
@@ -385,3 +385,51 @@ export const deleteCase = async (req: AuthenticatedRequest, res: Response) => {
|
||||
res.status(500).json({ error: error.message || 'Internal Server Error' });
|
||||
}
|
||||
};
|
||||
|
||||
export const analyzeDigitalIntern = async (req: AuthenticatedRequest, res: Response) => {
|
||||
try {
|
||||
const { caseId } = req.params;
|
||||
const { question, query } = req.body || {};
|
||||
const questionToUse = question || query;
|
||||
|
||||
if (!caseId) {
|
||||
return res.status(400).json({ error: 'Geçersiz caseId' });
|
||||
}
|
||||
|
||||
if (!questionToUse || !String(questionToUse).trim()) {
|
||||
return res.status(400).json({ error: 'Soru (question) girmelisiniz.' });
|
||||
}
|
||||
|
||||
const { data: docs, error: docsError } = await supabase
|
||||
.from('documents')
|
||||
.select('filename, extracted_text')
|
||||
.eq('case_id', caseId)
|
||||
.order('uploaded_at', { ascending: true });
|
||||
if (docsError) throw docsError;
|
||||
|
||||
const targetDocs = (docs || []).filter(d => d.extracted_text && String(d.extracted_text).trim());
|
||||
|
||||
if (targetDocs.length === 0) {
|
||||
return res.status(400).json({ error: 'Bu dosyada arama yapılabilecek evrak bulunamadı.' });
|
||||
}
|
||||
|
||||
const perDocLimit = Math.max(1000, Math.floor(30000 / targetDocs.length));
|
||||
const combinedText = targetDocs
|
||||
.map((d) => `--- ${d.filename} ---\n${String(d.extracted_text).slice(0, perDocLimit)}`)
|
||||
.join('\n\n');
|
||||
|
||||
const analysisInput = `Aşağıdaki belgeler dava dosyasına aittir:\n\n${combinedText}`;
|
||||
|
||||
const { summaryJson, aiModel } = await runDigitalInternQa(analysisInput, questionToUse);
|
||||
|
||||
// İsteğe bağlı olarak arama sonucunu da 'analyses' tablosuna kaydet
|
||||
await supabase
|
||||
.from('analyses')
|
||||
.insert([{ case_id: caseId, document_id: null, summary_json: { digitalInternResult: summaryJson, question: questionToUse }, model_used: aiModel }]);
|
||||
|
||||
res.json({ result: summaryJson, modelUsed: aiModel });
|
||||
} catch (error: any) {
|
||||
console.error('Digital Intern Error:', error);
|
||||
res.status(500).json({ error: error.message || 'Internal Server Error' });
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user