AIvidence Documentation

AI-powered fact checking tool for fighting misinformation

fact_check_engine

FactCheckEngine for analyzing content and checking its factual accuracy.
FactCheckEngine Class
Main engine for analyzing content and checking its factual accuracy. Orchestrates the full pipeline from content retrieval to final report generation.
__init__ Method
def __init__(self, model_name: str = 'gpt-4o-mini', api_key: Optional[str] = None, base_url: Optional[str] = None, verbose: bool = False, brave_api_key: str = 'your_brave_search_key_here'):
Initialize the fact check engine.

Parameters

Parameter Description
model_name Name of the LLM to use
api_key API key for the language model
base_url Base URL for the language model (for Ollama models)
verbose Whether to enable verbose logging
brave_api_key API key for Brave Search
analyze_content Method
def analyze_content(self, source: str, source_type: Optional[str] = None, max_claims: int = 5) -> aividence.models.content_analysis_report.ContentAnalysisReport:
Analyze content from a URL or HTML file for misinformation. ContentAnalysisReport with analysis details

Parameters

Parameter Description
source Source of content (URL or file path)
source_type Type of source ('url' or 'file'). If None, type is auto-detected.
max_claims Maximum number of claims to verify

Returns

ContentAnalysisReport with analysis details

analyze_website Method
def analyze_website(self, url: str, max_claims: int = 5) -> aividence.models.content_analysis_report.ContentAnalysisReport:
Legacy method to maintain backward compatibility. ContentAnalysisReport with analysis details

Parameters

Parameter Description
url Website URL to analyze
max_claims Maximum number of claims to verify

Returns

ContentAnalysisReport with analysis details

domain_analyzer

DomainAnalyzer agent for analyzing website domains and content topics.
DomainAnalyzer Class
Agent for analyzing website domains and determining their topics, required expertise, and verification strategies.
__init__ Method
def __init__(self, model_client: aividence.clients.model_client.ModelClient, verbose: bool = False):
Initialize the domain analyzer.

Parameters

Parameter Description
model_client ModelClient instance for querying language models
verbose Whether to enable verbose logging
analyze_domain Method
def analyze_domain(self, url: str, content: str) -> Dict[str, Any]:
Analyze the website domain and determine its topic, expertise required, and what to verify. Dictionary with domain analysis results

Parameters

Parameter Description
url Website URL
content Website content

Returns

Dictionary with domain analysis results

claim_extractor

ClaimExtractor agent for extracting verifiable claims from content.
ClaimExtractor Class
Agent for extracting verifiable factual claims from website content.
__init__ Method
def __init__(self, model_client: aividence.clients.model_client.ModelClient, verbose: bool = False):
Initialize the claim extractor.

Parameters

Parameter Description
model_client ModelClient instance for querying language models
verbose Whether to enable verbose logging
extract_claims Method
def extract_claims(self, content: str, domain_analysis: Dict[str, Any], max_claims: int = 10) -> List[aividence.models.fact_claim.FactClaim]:
Extract verifiable claims from the website content. List of FactClaim objects

Parameters

Parameter Description
content Website content
domain_analysis Results from domain analysis
max_claims Maximum number of claims to extract

Returns

List of FactClaim objects

claim_verifier

ClaimVerifier agent for verifying factual claims using web search.
ClaimVerifier Class
Agent for verifying factual claims by searching for evidence and analyzing results.
__init__ Method
def __init__(self, model_client: aividence.clients.model_client.ModelClient, search_client: aividence.clients.web_search_client.WebSearchClient, verbose: bool = False):
Initialize the claim verifier.

Parameters

Parameter Description
model_client ModelClient instance for querying language models
search_client WebSearchClient instance for searching the web
verbose Whether to enable verbose logging
verify_claim Method
def verify_claim(self, claim: aividence.models.fact_claim.FactClaim, domain_analysis: Dict[str, Any]) -> aividence.models.fact_check_result.FactCheckResult:
Verify a single claim by searching for evidence and analyzing results. FactCheckResult with the verification details

Parameters

Parameter Description
claim The claim to verify
domain_analysis Domain analysis results for context

Returns

FactCheckResult with the verification details

content_scraper

ContentScraper client for loading content from websites or HTML files.
ContentScraper Class
A class to load website content from URLs or HTML files using multiple fallback methods.
__init__ Method
def __init__(self, user_agent=None, timeout=30, verbose=False):
Initialize the scraper with configurable parameters.
load_content Method
def load_content(self, source, source_type=None):
Load content from either a website URL or an HTML file. str: The website content as text Raises: ValueError: If the content could not be loaded after all attempts

Parameters

Parameter Description
source The URL of the website or path to HTML file
source_type Optional type specifier ('url' or 'file'). If None, type is auto-detected.

Returns

str: The website content as text

load_website_content Method
def load_website_content(self, url):
Legacy method to maintain backward compatibility. str: The website content as text

Parameters

Parameter Description
url The URL of the website to load

Returns

str: The website content as text

model_client

ModelClient for handling interactions with language models.
ModelClient Class
A wrapper class to handle interactions with different language models. Supports OpenAI, Anthropic, and Ollama models.
__init__ Method
def __init__(self, model_name: str, api_key: Optional[str] = None, base_url: Optional[str] = None, verbose: bool = False):
Initialize the model client.

Parameters

Parameter Description
model_name Name of the model to use
api_key API key for the model service
base_url Base URL for the model service (used with Ollama models)
verbose Whether to enable verbose logging
run Method
def run(self, prompt: str, system_prompt: Optional[str] = None) -> str:
Run a chat completion. The model's response as a string

Parameters

Parameter Description
prompt The user prompt to send to the model
system_prompt Optional system prompt to set context

Returns

The model's response as a string

web_search_client

WebSearchClient for searching the web using Brave Search API.
WebSearchClient Class
Tool for searching the web using Brave Search API with direct HTTP requests
__init__ Method
def __init__(self, api_key: str, max_results: int = 5, verbose: bool = False, timeout: int = 10, max_retries: int = 3, retry_delay: int = 10):
Initialize the web search client.

Parameters

Parameter Description
api_key Brave Search API key
max_results Maximum number of results to return
verbose Whether to enable verbose logging
timeout Request timeout in seconds
max_retries Maximum number of retry attempts
retry_delay Delay between retries in seconds
search Method
def search(self, query: str) -> List[aividence.models.search_result.SearchResult]:
Perform a search using Brave Search API with timeout handling and retries. List of SearchResult objects

Parameters

Parameter Description
query Search query string

Returns

List of SearchResult objects

fact_claim

FactClaim model for representing claims to be verified.
FactClaim Class
A factual claim extracted from content that needs verification. Attributes: id: Unique identifier for the claim claim: The actual claim text topic: Topic category of the claim keywords: List of keywords relevant to the claim importance: Importance score of the claim (1-10)
Inherits from: BaseModel
__init__ Method
def __init__(self, /, **data: 'Any') -> 'None':
Create a new model by parsing and validating input data from keyword arguments. Raises [`ValidationError`][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model. `self` is explicitly positional-only to allow `self` as a field name.

search_result

SearchResult model for representing search results.
SearchResult Class
Represents a search result from a web search. Attributes: title: Title of the search result body: Body text or description of the search result url: URL of the search result source: Source domain of the search result
__init__ Method
def __init__(self, title: str, body: str, url: str, source: str):
Initialize self. See help(type(self)) for accurate signature.

fact_check_result

FactCheckResult model for representing verification results.
FactCheckResult Class
Represents the result of verifying a factual claim. Attributes: claim_id: ID of the claim being verified claim: The claim text score: Truthfulness score (0-5, where 0 is completely false and 5 is completely true) confidence: Confidence in the verification (0-1) evidence: List of evidence supporting the verification contradictions: List of evidence contradicting the claim sources: List of sources used for verification search_queries: List of search queries used for verification explanation: Explanation of the verification result is_recent_news: Flag indicating if the claim is about very recent events
Inherits from: BaseModel
__init__ Method
def __init__(self, /, **data: 'Any') -> 'None':
Create a new model by parsing and validating input data from keyword arguments. Raises [`ValidationError`][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model. `self` is explicitly positional-only to allow `self` as a field name.

content_analysis_report

ContentAnalysisReport model for representing the final analysis results.
ContentAnalysisReport Class
The complete analysis report for a website or content source. Attributes: url: URL of the analyzed content domain: Domain name of the content source topic: Main topic of the content domain_expertise_required: List of expertise domains required to verify the content overall_score: Overall truthfulness score of the content (0-5) claims: List of factual claims extracted from the content verification_results: List of verification results for the claims summary: Summary of the analysis recommendations: List of recommendations for the reader analysis_date: Date when the analysis was performed
Inherits from: BaseModel
__init__ Method
def __init__(self, /, **data: 'Any') -> 'None':
Create a new model by parsing and validating input data from keyword arguments. Raises [`ValidationError`][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model. `self` is explicitly positional-only to allow `self` as a field name.
to_markdown_report Method
def to_markdown_report(self) -> str:
Generate a markdown report from the analysis results.