Create validator_agents.py
Browse files- agents/validator_agents.py +68 -0
agents/validator_agents.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Any, Dict
|
2 |
+
from base_agent import ValidatorAgent
|
3 |
+
|
4 |
+
class SummarizeValidatorAgent(ValidatorAgent):
|
5 |
+
async def validate(self, input_data: str, output_data: Dict[str, Any]) -> Dict[str, bool]:
|
6 |
+
prompt = f"""Evaluate if this summary accurately represents the original text:
|
7 |
+
Original: {input_data}
|
8 |
+
Summary: {output_data['summary']}
|
9 |
+
|
10 |
+
Provide:
|
11 |
+
1. A score out of 5 (where 5 is perfect)
|
12 |
+
2. 'valid' or 'invalid'
|
13 |
+
3. Brief explanation
|
14 |
+
|
15 |
+
Format: Score: X/5\nStatus: valid/invalid\nExplanation: ..."""
|
16 |
+
|
17 |
+
result = await self.get_completion(prompt)
|
18 |
+
is_valid = "valid" in result.lower()
|
19 |
+
return {"is_valid": is_valid, "feedback": result}
|
20 |
+
|
21 |
+
class RefinerAgent(ValidatorAgent):
|
22 |
+
async def validate(self, input_data: Dict[str, str], output_data: Dict[str, Any]) -> Dict[str, bool]:
|
23 |
+
prompt = f"""Review this research article for quality and accuracy:
|
24 |
+
Article: {output_data['article']}
|
25 |
+
|
26 |
+
Provide:
|
27 |
+
1. A score out of 5 (where 5 is perfect)
|
28 |
+
2. 'valid' or 'invalid'
|
29 |
+
3. Brief explanation
|
30 |
+
|
31 |
+
Format: Score: X/5\nStatus: valid/invalid\nExplanation: ..."""
|
32 |
+
|
33 |
+
result = await self.get_completion(prompt)
|
34 |
+
is_valid = "valid" in result.lower()
|
35 |
+
return {"is_valid": is_valid, "feedback": result}
|
36 |
+
|
37 |
+
class SanitizeValidatorAgent(ValidatorAgent):
|
38 |
+
async def validate(self, input_data: str, output_data: Dict[str, Any]) -> Dict[str, bool]:
|
39 |
+
prompt = f"""Verify if all Protected Health Information (PHI) has been properly masked in this text:
|
40 |
+
Masked text: {output_data['sanitized_data']}
|
41 |
+
|
42 |
+
Check for any unmasked:
|
43 |
+
- Patient names
|
44 |
+
- Doctor/Provider names
|
45 |
+
- Dates
|
46 |
+
- Locations/Addresses
|
47 |
+
- Phone numbers
|
48 |
+
- Email addresses
|
49 |
+
- Medical record numbers
|
50 |
+
- Social Security numbers
|
51 |
+
- Device identifiers
|
52 |
+
- Other identifying numbers
|
53 |
+
- Physical health conditions
|
54 |
+
- Medications
|
55 |
+
- Lab results
|
56 |
+
- Vital signs
|
57 |
+
- Procedures
|
58 |
+
|
59 |
+
Provide:
|
60 |
+
1. A score out of 5 (where 5 means all PHI properly masked)
|
61 |
+
2. 'valid' or 'invalid'
|
62 |
+
3. List any found unmasked PHI
|
63 |
+
|
64 |
+
Format: Score: X/5\nStatus: valid/invalid\nFindings: ..."""
|
65 |
+
|
66 |
+
result = await self.get_completion(prompt)
|
67 |
+
is_valid = "valid" in result.lower()
|
68 |
+
return {"is_valid": is_valid, "feedback": result}
|