Files
ihaleist/src/services/ai.js
T

32 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Gerçek AI şartname analizi istemcisi (backend /api/ai üzerinden).
*/
import { getToken } from './auth';
export async function getAiConfig() {
try {
const res = await fetch('/api/ai/config');
if (!res.ok) return { configured: false, providers: [] };
return await res.json();
} catch {
return { configured: false, providers: [] };
}
}
export async function analyzeSpecText({ text, fileName, tender, chain, mode, extraction }) {
const res = await fetch('/api/ai/analyze', {
method: 'POST',
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${getToken()}` },
body: JSON.stringify({ text, fileName, tender, chain, mode, extraction }),
});
const data = await res.json().catch(() => ({}));
if (!data.success) {
const proxyMesaj = {
413: 'Doküman metni sunucu sınırını aşıyor; daha küçük bir dosya veya yalnızca ilgili sayfaları deneyin.',
504: 'Analiz zaman aşımına uğradı; tekrar deneyin (derin analiz 1-2 dk sürebilir).',
}[res.status];
throw new Error(data.error || proxyMesaj || `Analiz başarısız (HTTP ${res.status})`);
}
return data;
}