Async variant that calls the Ollama client asynchronously.
(self, query: str, context: str, answer: str)
| 21 | |
| 22 | # --- Async wrapper ------------------------------------------------ |
| 23 | async def verify_async(self, query: str, context: str, answer: str) -> VerificationResult: |
| 24 | """Async variant that calls the Ollama client asynchronously.""" |
| 25 | prompt = f""" |
| 26 | You are an automated fact-checker. Determine whether the ANSWER is fully supported by the CONTEXT and output a single line of JSON. |
| 27 | |
| 28 | # EXAMPLES |
| 29 | |
| 30 | <QUERY> |
| 31 | What color is the sky? |
| 32 | </QUERY> |
| 33 | <CONTEXT> |
| 34 | During the day, the sky appears blue due to Rayleigh scattering. |
| 35 | </CONTEXT> |
| 36 | <ANSWER> |
| 37 | The sky is blue during the day. |
| 38 | </ANSWER> |
| 39 | <OUTPUT> |
| 40 | {{"verdict": "SUPPORTED", "is_grounded": true, "reasoning": "The context explicitly supports that the sky is blue during the day.", "confidence_score": 100}} |
| 41 | </OUTPUT> |
| 42 | |
| 43 | <QUERY> |
| 44 | Where are apples and oranges grown? |
| 45 | </QUERY> |
| 46 | <CONTEXT> |
| 47 | Apples are grown in orchards. |
| 48 | </CONTEXT> |
| 49 | <ANSWER> |
| 50 | Apples are grown in orchards and oranges are grown in groves. |
| 51 | </ANSWER> |
| 52 | <OUTPUT> |
| 53 | {{"verdict": "NOT_SUPPORTED", "is_grounded": false, "reasoning": "The context mentions orchards, but not oranges or groves.", "confidence_score": 80}} |
| 54 | </OUTPUT> |
| 55 | |
| 56 | <QUERY> |
| 57 | How long is the process? |
| 58 | </QUERY> |
| 59 | <CONTEXT> |
| 60 | The first step takes 3 days. The second step takes 5 days. |
| 61 | </CONTEXT> |
| 62 | <ANSWER> |
| 63 | The process takes 3 days. |
| 64 | </ANSWER> |
| 65 | <OUTPUT> |
| 66 | {{"verdict": "NEEDS_CLARIFICATION", "is_grounded": false, "reasoning": "The answer omits the 5 days required for the second step.", "confidence_score": 70}} |
| 67 | </OUTPUT> |
| 68 | |
| 69 | # TASK |
| 70 | |
| 71 | <QUERY> |
| 72 | "{query}" |
| 73 | </QUERY> |
| 74 | <CONTEXT> |
| 75 | """ |
| 76 | prompt += context[:4000] # Clamp to avoid huge prompts |
| 77 | prompt += """ |
| 78 | </CONTEXT> |
| 79 | <ANSWER> |
| 80 | """ |
no test coverage detected