101 lines
3.2 KiB
Python
101 lines
3.2 KiB
Python
from pydantic import BaseModel, Field, HttpUrl, validator
|
|
from typing import List, Literal, Union
|
|
from datetime import datetime
|
|
from enum import Enum
|
|
|
|
|
|
class VerdictEnum(str, Enum):
|
|
TRUE = "True"
|
|
FALSE = "False"
|
|
PARTIALLY_TRUE = "Partially True"
|
|
UNVERIFIED = "Unverified"
|
|
|
|
|
|
class ConfidenceEnum(str, Enum):
|
|
HIGH = "High"
|
|
MEDIUM = "Medium"
|
|
LOW = "Low"
|
|
|
|
|
|
class FactCheckRequest(BaseModel):
|
|
query: str = Field(
|
|
...,
|
|
min_length=3,
|
|
max_length=500,
|
|
description="The claim or statement to be fact-checked",
|
|
example="Did NASA confirm finding alien structures on Mars in 2024?",
|
|
)
|
|
|
|
|
|
class Source(BaseModel):
|
|
url: str
|
|
name: str = ""
|
|
|
|
@validator("url")
|
|
def validate_url(cls, v):
|
|
# Basic URL validation without requiring HTTP/HTTPS
|
|
if not v or len(v) < 3:
|
|
raise ValueError("URL must not be empty and must be at least 3 characters")
|
|
return v
|
|
|
|
|
|
class FactCheckResponse(BaseModel):
|
|
claim: str = Field(
|
|
...,
|
|
min_length=10,
|
|
max_length=1000,
|
|
description="The exact claim being verified",
|
|
)
|
|
verdict: VerdictEnum = Field(..., description="The verification verdict")
|
|
confidence: ConfidenceEnum = Field(
|
|
..., description="Confidence level in the verdict"
|
|
)
|
|
sources: List[Source] = Field(
|
|
..., min_items=1, description="List of sources used in verification"
|
|
)
|
|
evidence: str = Field(
|
|
...,
|
|
min_length=20,
|
|
max_length=500,
|
|
description="Concise summary of key evidence",
|
|
)
|
|
explanation: str = Field(
|
|
...,
|
|
min_length=50,
|
|
max_length=1000,
|
|
description="Detailed explanation of verification findings",
|
|
)
|
|
additional_context: str = Field(
|
|
...,
|
|
min_length=20,
|
|
max_length=500,
|
|
description="Important context about the verification",
|
|
)
|
|
|
|
class Config:
|
|
json_schema_extra = {
|
|
"example": {
|
|
"claim": "NASA confirmed finding alien structures on Mars in 2024",
|
|
"verdict": "False",
|
|
"confidence": "High",
|
|
"sources": [
|
|
{
|
|
"url": "https://www.nasa.gov/mars-exploration",
|
|
"name": "NASA Mars Exploration",
|
|
},
|
|
{
|
|
"url": "https://factcheck.org/2024/mars-claims",
|
|
"name": "FactCheck.org",
|
|
},
|
|
],
|
|
"evidence": "NASA has made no such announcement. Recent Mars rover images show natural rock formations.",
|
|
"explanation": "Multiple fact-checking organizations investigated this claim. NASA's official communications and Mars mission reports from 2024 contain no mention of alien structures. The viral images being shared are misidentified natural geological formations.",
|
|
"additional_context": "Similar false claims about alien structures on Mars have circulated periodically since the first Mars rovers began sending back images.",
|
|
}
|
|
}
|
|
|
|
|
|
class ErrorResponse(BaseModel):
|
|
detail: str
|
|
error_code: str = Field(..., example="VALIDATION_ERROR")
|
|
path: str = Field(..., example="/check-facts")
|