Compare commits

..

No commits in common. "bc30973ae5d8a66fdb0ee6bafee05d9110ffd08d" and "f7b2d77ce485c3b1baafc2d0e723ba62bfbd53c2" have entirely different histories.

View file

@ -167,7 +167,7 @@ async def process_fact_check(query: str) -> Union[FactCheckResponse, UnverifiedF
verdict=VerdictEnum.UNVERIFIED, verdict=VerdictEnum.UNVERIFIED,
confidence=ConfidenceEnum.LOW, confidence=ConfidenceEnum.LOW,
sources=[], sources=[],
evidence='No fact check results found.', evidence=str(e),
explanation="Failed to contact Perplexity AI or parse its response.", explanation="Failed to contact Perplexity AI or parse its response.",
additional_context="Possible API issue or malformed response." additional_context="Possible API issue or malformed response."
) )
@ -497,109 +497,53 @@ async def check_facts(request: FactCheckRequest):
""" """
Fetch fact check results and generate a comprehensive report. Fetch fact check results and generate a comprehensive report.
Handles both query-based and URL-based fact checking. Handles both query-based and URL-based fact checking.
Always returns a 200 response with appropriate content, never an error.
""" """
try: url_text = None
url_text = None query_result = None
query_result = None url_result = None
url_result = None
# If URL is provided, try to extract text # If URL is provided, try to extract text
if request.url: if request.url:
try: url_text = await process_url_content(request.url)
url_text = await process_url_content(request.url) if not url_text and not request.query:
except Exception as e: # Only return early if URL text extraction failed and no query provided
logger.error(f"Error extracting text from URL: {str(e)}") return UnverifiedFactCheckResponse(
url_text = None claim=f"URL check requested: {request.url}",
verdict=VerdictEnum.UNVERIFIED,
confidence=ConfidenceEnum.LOW,
sources=[],
evidence="Unable to extract text from the provided URL.",
explanation="The system could not process the content from the provided URL. The URL might be invalid or inaccessible.",
additional_context="Please provide a valid URL or a text query for fact-checking."
)
if not url_text and not request.query: # If URL text was successfully extracted, process it
# Only return early if URL text extraction failed and no query provided if url_text:
return UnverifiedFactCheckResponse( logger.info(f"Processing fact check for extracted text: {url_text}")
claim=f"URL check requested: {request.url}", url_result = await process_fact_check(url_text)
verdict=VerdictEnum.UNVERIFIED,
confidence=ConfidenceEnum.LOW,
sources=[],
evidence="No fact check results found",
explanation="The system encountered errors while processing the fact checks.",
additional_context="Please try again with different input or contact support if the issue persists."
)
# If URL text was successfully extracted, process it # Process query if provided
if url_text: if request.query:
logger.info(f"Processing fact check for extracted text: {url_text}") query_result = await process_fact_check(request.query)
try:
url_result = await process_fact_check(url_text)
except Exception as e:
logger.error(f"Error processing fact check for URL text: {str(e)}")
url_result = UnverifiedFactCheckResponse(
claim=f"URL: {request.url}",
verdict=VerdictEnum.UNVERIFIED,
confidence=ConfidenceEnum.LOW,
sources=[],
evidence="No fact check results found",
explanation="The system encountered errors while processing the fact checks.",
additional_context="Please try again with different input or contact support if the issue persists."
)
# Process query if provided # If both results are available, combine them
if request.query: if query_result and url_result and url_text:
try: return await combine_fact_reports(request.query, url_text,
query_result = await process_fact_check(request.query) query_result.dict(), url_result.dict())
except Exception as e:
logger.error(f"Error processing fact check for query: {str(e)}")
query_result = UnverifiedFactCheckResponse(
claim=request.query,
verdict=VerdictEnum.UNVERIFIED,
confidence=ConfidenceEnum.LOW,
sources=[],
evidence="No fact check results found",
explanation="The system encountered errors while processing the fact checks.",
additional_context="Please try again with different input or contact support if the issue persists."
)
# If both results are available, combine them # If only one result is available
if query_result and url_result and url_text: if query_result:
try: return query_result
return await combine_fact_reports(request.query, url_text, if url_result:
query_result.dict(), url_result.dict()) return url_result
except Exception as e:
logger.error(f"Error combining fact reports: {str(e)}")
return UnverifiedFactCheckResponse(
claim=request.query or f"URL: {request.url}",
verdict=VerdictEnum.UNVERIFIED,
confidence=ConfidenceEnum.LOW,
sources=[],
evidence="No fact check results found",
explanation="The system encountered errors while processing the fact checks.",
additional_context="Please try again with different input or contact support if the issue persists."
)
# If only one result is available # If no valid results
if query_result: return UnverifiedFactCheckResponse(
return query_result claim=request.query or f"URL: {request.url}",
if url_result: verdict=VerdictEnum.UNVERIFIED,
return url_result confidence=ConfidenceEnum.LOW,
sources=[],
# If no valid results evidence="Failed to process fact-checking request.",
return UnverifiedFactCheckResponse( explanation="The system encountered errors while processing the fact checks.",
claim=request.query or f"URL: {request.url}", additional_context="Please try again with different input or contact support if the issue persists."
verdict=VerdictEnum.UNVERIFIED, )
confidence=ConfidenceEnum.LOW,
sources=[],
evidence="No fact check results found",
explanation="The system encountered errors while processing the fact checks.",
additional_context="Please try again with different input or contact support if the issue persists."
)
except Exception as e:
# Catch-all exception handler to ensure we always return a 200 response
logger.error(f"Unexpected error in check_facts: {str(e)}")
return UnverifiedFactCheckResponse(
claim=request.query or f"URL: {request.url}",
verdict=VerdictEnum.UNVERIFIED,
confidence=ConfidenceEnum.LOW,
sources=[],
evidence="No fact check results found",
explanation="The system encountered errors while processing the fact checks.",
additional_context="Please try again with different input or contact support if the issue persists."
)