File size: 1,392 Bytes
484431d
7fd7594
c56dba2
9fe5e6c
c56dba2
 
 
 
 
 
 
484431d
 
c56dba2
 
 
 
 
 
9fe5e6c
 
c56dba2
9fe5e6c
 
 
 
 
 
 
 
 
c56dba2
 
 
 
9fe5e6c
c56dba2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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()

@router.post(
    "/factcheck", 
    response_model=FactCheckResponse, 
    tags=["Fact-checking"],
    summary="Zweryfikuj prawdziwo艣膰 stwierdzenia",
    dependencies=[Depends(verify_api_key)]
)
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
    )