Spaces:
Build error
Build error
Update common/validation_utils.py
Browse files
common/validation_utils.py
CHANGED
|
@@ -12,6 +12,7 @@ def is_first_person(answer):
|
|
| 12 |
Checks if the answer is written in first person.
|
| 13 |
Returns True if first person pronouns are found and third person references are not dominant.
|
| 14 |
"""
|
|
|
|
| 15 |
# Look for first person pronouns
|
| 16 |
first_person = re.search(r'\b(I|my|me|mine|we|our|us|ours)\b', answer, re.IGNORECASE)
|
| 17 |
# Look for third person references (e.g., "he", "she", "they", or a capitalized name at the start)
|
|
@@ -132,12 +133,14 @@ def validate_response(question, answer, user_profile_str, fast_facts_str, interv
|
|
| 132 |
if line.lower().startswith("plausibility rating:"):
|
| 133 |
try:
|
| 134 |
plausibility = float(line.split(":",1)[1].strip())
|
| 135 |
-
except Exception:
|
|
|
|
| 136 |
plausibility = None
|
| 137 |
if line.lower().startswith("relevance rating:"):
|
| 138 |
try:
|
| 139 |
relevance = float(line.split(":",1)[1].strip())
|
| 140 |
-
except Exception:
|
|
|
|
| 141 |
relevance = None
|
| 142 |
logging.info(f"Exploratory evaluation: plausibility={plausibility}, relevance={relevance}")
|
| 143 |
if plausibility is not None and relevance is not None:
|
|
@@ -148,6 +151,7 @@ def validate_response(question, answer, user_profile_str, fast_facts_str, interv
|
|
| 148 |
return True
|
| 149 |
return False
|
| 150 |
else:
|
|
|
|
| 151 |
# Fact-based: Ask LLM for accuracy rating
|
| 152 |
eval_prompt = f"""
|
| 153 |
You are an expert market research evaluator. Given the following:
|
|
@@ -169,7 +173,8 @@ def validate_response(question, answer, user_profile_str, fast_facts_str, interv
|
|
| 169 |
if line.lower().startswith("accuracy rating:"):
|
| 170 |
try:
|
| 171 |
accuracy = float(line.split(":",1)[1].strip())
|
| 172 |
-
except Exception:
|
|
|
|
| 173 |
accuracy = None
|
| 174 |
logging.info(f"Fact-based evaluation: accuracy={accuracy}")
|
| 175 |
if accuracy is not None:
|
|
|
|
| 12 |
Checks if the answer is written in first person.
|
| 13 |
Returns True if first person pronouns are found and third person references are not dominant.
|
| 14 |
"""
|
| 15 |
+
logging.debug(f"Checking if answer is first person: {answer}")
|
| 16 |
# Look for first person pronouns
|
| 17 |
first_person = re.search(r'\b(I|my|me|mine|we|our|us|ours)\b', answer, re.IGNORECASE)
|
| 18 |
# Look for third person references (e.g., "he", "she", "they", or a capitalized name at the start)
|
|
|
|
| 133 |
if line.lower().startswith("plausibility rating:"):
|
| 134 |
try:
|
| 135 |
plausibility = float(line.split(":",1)[1].strip())
|
| 136 |
+
except Exception as e:
|
| 137 |
+
logging.error(f"Error parsing plausibility rating: {e}")
|
| 138 |
plausibility = None
|
| 139 |
if line.lower().startswith("relevance rating:"):
|
| 140 |
try:
|
| 141 |
relevance = float(line.split(":",1)[1].strip())
|
| 142 |
+
except Exception as e:
|
| 143 |
+
logging.error(f"Error parsing relevance rating: {e}")
|
| 144 |
relevance = None
|
| 145 |
logging.info(f"Exploratory evaluation: plausibility={plausibility}, relevance={relevance}")
|
| 146 |
if plausibility is not None and relevance is not None:
|
|
|
|
| 151 |
return True
|
| 152 |
return False
|
| 153 |
else:
|
| 154 |
+
logging.info("Performing fact-based evaluation (accuracy)...")
|
| 155 |
# Fact-based: Ask LLM for accuracy rating
|
| 156 |
eval_prompt = f"""
|
| 157 |
You are an expert market research evaluator. Given the following:
|
|
|
|
| 173 |
if line.lower().startswith("accuracy rating:"):
|
| 174 |
try:
|
| 175 |
accuracy = float(line.split(":",1)[1].strip())
|
| 176 |
+
except Exception as e:
|
| 177 |
+
logging.error(f"Error parsing accuracy rating: {e}")
|
| 178 |
accuracy = None
|
| 179 |
logging.info(f"Fact-based evaluation: accuracy={accuracy}")
|
| 180 |
if accuracy is not None:
|