feat: iddianame-first case summary + remove hardcoded AI endpoint

- summarizeCase: if an iddianame is among the case's documents, run a
  narrow first-pass analysis on it alone (isnatEdilenSuc, iddiaOzeti,
  onemliTarihler), then feed that as context into the general
  case-wide evaluation instead of treating every document equally.
- ANALYSIS_SYSTEM_PROMPT no longer asks the AI to guess "taraflar" -
  that now comes from real UYAP data (cases.parties) instead.
- Removed the hardcoded RunPod proxy URL fallback from every call
  site (document/chat/precedent controllers + lib/openai.ts) - it was
  a real infra endpoint checked into source. New lib/aiConfig.ts
  throws if RUNPOD_API_BASE_URL isn't set rather than silently
  falling back to it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
mstfyldz
2026-08-09 20:00:06 +03:00
co-authored by Claude Sonnet 5
parent af5a03db92
commit c939dcf564
6 changed files with 105 additions and 33 deletions
+6 -6
View File
@@ -1,5 +1,6 @@
import { Request, Response } from 'express';
import { AuthenticatedRequest } from '../middleware/auth';
import { getAiConfig } from '../lib/aiConfig';
export const searchPrecedents = async (req: Request, res: Response) => {
try {
@@ -13,15 +14,15 @@ export const searchPrecedents = async (req: Request, res: Response) => {
// Eğer sorgu 3 kelimeden uzunsa (doğal dil sorusu ise), AI ile anahtar kelimelere dönüştür
if (phrase.split(' ').length > 3) {
const aiModel = process.env.AI_MODEL || 'mizan-fixed';
const runpodUrl = process.env.RUNPOD_API_BASE_URL || 'https://q190env94stwis-11434.proxy.runpod.net';
const systemPrompt = `Sen uzman bir Türk avukatısın. Kullanıcının uzun ve doğal dille yazdığı hukuki soruyu, Yargıtay içtihat arama motorunda en iyi sonucu verecek şekilde 2 ila en fazla 4 temel hukuki terime/anahtar kelimeye çevir.
const systemPrompt = `Sen uzman bir Türk avukatısın. Kullanıcının uzun ve doğal dille yazdığı hukuki soruyu, Yargıtay içtihat arama motorunda en iyi sonucu verecek şekilde 2 ila en fazla 4 temel hukuki terime/anahtar kelimeye çevir.
SADECE anahtar kelimeleri aralarına boşluk koyarak yaz. Noktalama işareti, açıklama veya ek kelimeler (ve, ile, vb.) kullanma.
Örnek Kullanıcı: İşveren tarafından performans düşüklüğü gerekçesiyle iş sözleşmesi feshedilen işçinin işe iade davası açması halinde ispat yükü kime aittir
Örnek Cevap: performans düşüklüğü ispat yükü işe iade`;
// AI ile sorgu optimizasyonu isteğe bağlı bir iyileştirme — config eksikse veya
// istek başarısız olursa arama yine de optimize edilmemiş phrase ile devam eder.
try {
const { runpodUrl, aiModel } = getAiConfig();
const aiResponse = await fetch(`${runpodUrl}/v1/chat/completions`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
@@ -112,8 +113,7 @@ export const analyzePrecedents = async (req: AuthenticatedRequest, res: Response
const systemPrompt = 'Sen uzman bir Türk avukatısın. Kullanıcının anlattığı hukuki durumu, aşağıda listelenen emsal karar arama sonuçları ışığında kısaca değerlendir. Hangi kararların duruma daha yakın olabileceğini belirt ve olası bir hukuki değerlendirme sun. Emin olmadığın noktalarda bunu açıkça belirt, uydurma bilgi verme. Cevabın yaklaşık 150-250 kelime olsun.';
const userPrompt = `DURUM:\n${String(situation).slice(0, 3000)}\n\nBULUNAN KARARLAR:\n${listText}`;
const aiModel = process.env.AI_MODEL || 'mizan-fixed';
const runpodUrl = process.env.RUNPOD_API_BASE_URL || 'https://q190env94stwis-11434.proxy.runpod.net';
const { runpodUrl, aiModel } = getAiConfig();
const response = await fetch(`${runpodUrl}/api/chat`, {
method: 'POST',