Installation
Import the PAS2 class from the library:Initialization
Initialize the PAS2 detector with your API keys:API key priority
The library checks for API keys in the following order:Progress callbacks
Optionally provide a callback function to track progress:Core methods
Detect hallucination
The main method for hallucination detection:query(str): The question or prompt to analyzen_paraphrases(int): Number of paraphrases to generate (default: 3)
Generate paraphrases
Generate semantic paraphrases of a query:Get responses
Get AI responses for multiple queries in parallel:Judge hallucination
Use the judge model to analyze responses for inconsistencies:HallucinationJudgment object with:
Model configuration
The library uses specific models for different tasks:Complete example
Here’s a full example demonstrating the library workflow:Error handling
The library includes comprehensive error handling:Logging
Enable detailed logging to debug issues:- Paraphrase generation timing and results
- Response retrieval progress
- Judgment execution details
- Error stack traces