|
| 1 | +# Fact Checker CLI |
| 2 | + |
| 3 | +A command-line tool that identifies false or misleading claims in articles or statements using Perplexity's Sonar API for web research. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Analyze claims or entire articles for factual accuracy |
| 8 | +- Identify false, misleading, or unverifiable claims |
| 9 | +- Provide explanations and corrections for inaccurate information |
| 10 | +- Output results in human-readable format or structured JSON |
| 11 | +- Cite reliable sources for fact-checking assessments |
| 12 | +- Leverages Perplexity's structured outputs for reliable JSON parsing (for Tier 3+ users) |
| 13 | + |
| 14 | +## Installation |
| 15 | + |
| 16 | + |
| 17 | +1. Install required dependencies: |
| 18 | + |
| 19 | +```bash |
| 20 | +pip install requests pydantic |
| 21 | +``` |
| 22 | + |
| 23 | +2. Make the script executable: |
| 24 | + |
| 25 | +```bash |
| 26 | +chmod +x fact_checker.py |
| 27 | +``` |
| 28 | + |
| 29 | +## API Key Setup |
| 30 | + |
| 31 | +The tool requires a Perplexity API key to function. You can provide it in one of these ways: |
| 32 | + |
| 33 | +1. As a command-line argument: `--api-key YOUR_API_KEY` |
| 34 | +2. As an environment variable: `export PPLX_API_KEY=YOUR_API_KEY` |
| 35 | +3. In a file named `pplx_api_key` or `.pplx_api_key` in the same directory as the script: |
| 36 | + |
| 37 | +```bash |
| 38 | +# Create a file to store your API key |
| 39 | +echo "YOUR_API_KEY" > .pplx_api_key |
| 40 | +# Make sure to protect your API key |
| 41 | +chmod 600 .pplx_api_key |
| 42 | +``` |
| 43 | + |
| 44 | +**Note:** If you're using the structured outputs feature, you'll need a Perplexity API account with Tier 3 or higher access level. |
| 45 | + |
| 46 | +## Quick Start |
| 47 | + |
| 48 | +Here's a command you can copy and run immediately after setup: |
| 49 | + |
| 50 | +```bash |
| 51 | +# Make sure your API key is set up as described above, then run: |
| 52 | +./fact_checker.py -t "The Earth is flat and NASA is hiding the truth." |
| 53 | +``` |
| 54 | + |
| 55 | +This will analyze the claim, research it using Perplexity's Sonar API, and return a detailed fact check with ratings, explanations, and sources. |
| 56 | + |
| 57 | +## Usage |
| 58 | + |
| 59 | +### Basic Usage |
| 60 | + |
| 61 | +Check a claim: |
| 62 | + |
| 63 | +```bash |
| 64 | +./fact_checker.py --text "The Earth is flat and NASA is hiding the truth." |
| 65 | +``` |
| 66 | + |
| 67 | +### Check an article from a file: |
| 68 | + |
| 69 | +```bash |
| 70 | +./fact_checker.py --file article.txt |
| 71 | +``` |
| 72 | + |
| 73 | +### Specify a different model: |
| 74 | + |
| 75 | +```bash |
| 76 | +./fact_checker.py --text "Global temperatures have decreased over the past century." --model "sonar-pro" |
| 77 | +``` |
| 78 | + |
| 79 | +### Output results as JSON: |
| 80 | + |
| 81 | +```bash |
| 82 | +./fact_checker.py --text "Mars has a breathable atmosphere." --json |
| 83 | +``` |
| 84 | + |
| 85 | +### Use a custom prompt file: |
| 86 | + |
| 87 | +```bash |
| 88 | +./fact_checker.py --text "The first human heart transplant was performed in the United States." --prompt-file custom_prompt.md |
| 89 | +``` |
| 90 | + |
| 91 | +### Disable structured outputs (for lower tier accounts): |
| 92 | + |
| 93 | +```bash |
| 94 | +./fact_checker.py --text "Vaccines cause autism." --no-structured-output |
| 95 | +``` |
| 96 | + |
| 97 | +### Get help: |
| 98 | + |
| 99 | +```bash |
| 100 | +./fact_checker.py --help |
| 101 | +``` |
| 102 | + |
| 103 | +## Output Format |
| 104 | + |
| 105 | +The tool provides a structured output with: |
| 106 | + |
| 107 | +- Overall rating of the content (MOSTLY_TRUE, MIXED, or MOSTLY_FALSE) |
| 108 | +- Summary of findings |
| 109 | +- List of specific claims with individual ratings: |
| 110 | + - TRUE: Factually accurate and supported by evidence |
| 111 | + - FALSE: Contradicted by evidence |
| 112 | + - MISLEADING: Contains some truth but presented in a way that could lead to incorrect conclusions |
| 113 | + - UNVERIFIABLE: Cannot be conclusively verified with available information |
| 114 | +- Explanations for each claim |
| 115 | +- Sources used for verification |
| 116 | + |
| 117 | +## Example |
| 118 | + |
| 119 | +``` |
| 120 | +$ ./fact_checker.py -t "The Great Wall of China is visible from the moon." |
| 121 | +
|
| 122 | +Fact checking in progress... |
| 123 | +
|
| 124 | +🔴 OVERALL RATING: MOSTLY_FALSE |
| 125 | +
|
| 126 | +📝 SUMMARY: |
| 127 | +The claim that the Great Wall of China is visible from the moon is false. This is a common misconception that has been debunked by NASA astronauts and scientific evidence. |
| 128 | +
|
| 129 | +🔍 CLAIMS ANALYSIS: |
| 130 | +
|
| 131 | +Claim 1: ❌ FALSE |
| 132 | + Statement: "The Great Wall of China is visible from the moon." |
| 133 | + Explanation: The Great Wall of China is not visible from the moon with the naked eye. NASA astronauts have confirmed this, including Neil Armstrong who stated he could not see the Wall from lunar orbit. The Wall is too narrow and is similar in color to its surroundings when viewed from such a distance. |
| 134 | + Sources: |
| 135 | + - NASA.gov |
| 136 | + - Scientific American |
| 137 | + - National Geographic |
| 138 | +``` |
| 139 | + |
| 140 | +## Limitations |
| 141 | + |
| 142 | +- The accuracy of fact-checking depends on the quality of information available through the Perplexity Sonar API |
| 143 | +- Like all language models, the underlying AI may have limitations in certain specialized domains |
| 144 | +- The structured outputs feature requires a Tier 3 or higher Perplexity API account |
| 145 | +- The tool does not replace professional fact-checking services for highly sensitive or complex content |
0 commit comments