Overview
Thegenerate_paraphrases method creates multiple paraphrased versions of an input query while preserving the original meaning. This is a core component of the PAS2 methodology, enabling the detection of hallucinations through response consistency analysis.
Method signature
Parameters
The original query string to paraphrase.
Number of paraphrases to generate. The method will attempt to generate exactly this many variations.
Return value
List of query strings with the original query as the first element, followed by
n_paraphrases paraphrased versions.Total length: n_paraphrases + 1 (original + paraphrases)Behavior
Successful generation
When the API call succeeds, the method:- Sends a request to Mistral API with JSON formatting
- Parses the response to extract paraphrases
- Handles multiple JSON response structures (
paraphrases,results, or direct array) - Prepends the original query to the list
- Returns all queries for analysis
Fallback mechanism
If paraphrase generation fails (API error, parsing error, etc.), the method returns fallback paraphrases:Example usage
Example output
API integration
The method uses the Mistral API with the following configuration:Error handling
Errors are logged with full stack traces:Performance considerations
- Single API call generates all paraphrases at once
- Typical response time: 1-3 seconds depending on API latency
- Uses JSON mode for structured output parsing
- Handles multiple response formats for robustness
The original query is always included as the first element in the returned list. This ensures consistent comparison between the original response and paraphrased responses.