Spaces:
Running
Running
| from fastapi import APIRouter, Depends, HTTPException | |
| from app.dependencies import verify_api_key | |
| from app.models.factcheck_schemas import FactCheckRequest, FactCheckResponse, FactCheckSource | |
| from app.services.factcheck_service import analyze_with_gemini_grounding | |
| router = APIRouter() | |
| async def fact_check_endpoint(payload: FactCheckRequest): | |
| statement = payload.statement.strip() | |
| if len(statement) < 10: | |
| raise HTTPException(status_code=400, detail="Tekst do weryfikacji musi mie膰 co najmniej 10 znak贸w.") | |
| # Wywo艂ujemy us艂ug臋 integruj膮c膮 Google Search i Gemini | |
| analysis = await analyze_with_gemini_grounding(statement) | |
| # Konwersja s艂ownik贸w na obiekty Pydantic | |
| formatted_sources = [] | |
| for s in analysis.get("sources", []): | |
| formatted_sources.append(FactCheckSource( | |
| title=s["title"], | |
| url=s["url"], | |
| snippet=s["snippet"] | |
| )) | |
| return FactCheckResponse( | |
| verdict=analysis.get("verdict", "SPORNE"), | |
| explanation=analysis.get("explanation", "Brak szczeg贸艂owego uzasadnienia."), | |
| confidence=analysis.get("confidence", 0.5), | |
| sources=formatted_sources | |
| ) |