Spaces:
Build error
Build error
Update common/validation_utils.py
Browse files- common/validation_utils.py +32 -9
common/validation_utils.py
CHANGED
|
@@ -7,17 +7,40 @@ from RespondentAgent import *
|
|
| 7 |
from langchain_groq import ChatGroq
|
| 8 |
|
| 9 |
|
| 10 |
-
def
|
| 11 |
"""
|
| 12 |
-
|
| 13 |
-
Returns True if
|
| 14 |
"""
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
|
| 23 |
def validate_response(question, answer, user_profile_str, fast_facts_str, interview_transcript_text, respondent_type, ai_evaluator_agent, processor_llm):
|
|
|
|
| 7 |
from langchain_groq import ChatGroq
|
| 8 |
|
| 9 |
|
| 10 |
+
def is_first_person_llm(answer, processor_llm):
|
| 11 |
"""
|
| 12 |
+
Uses LLM to determine whether the response is written in first person.
|
| 13 |
+
Returns True if the LLM determines the response is first-person, else False.
|
| 14 |
"""
|
| 15 |
+
prompt = f"""
|
| 16 |
+
You are an expert in analyzing writing style and narrative perspective.
|
| 17 |
+
|
| 18 |
+
Determine whether the following response is written from a first-person point of view.
|
| 19 |
+
A first-person response includes pronouns such as "I", "me", "my", "mine", "we", "our", or "us" and is written from the perspective of the speaker.
|
| 20 |
+
|
| 21 |
+
Do not guess. Only say "Yes" if the writing is clearly in first person. Otherwise, say "No".
|
| 22 |
+
|
| 23 |
+
Response:
|
| 24 |
+
\"\"\"{answer}\"\"\"
|
| 25 |
+
|
| 26 |
+
Output strictly in the following format:
|
| 27 |
+
First Person: Yes
|
| 28 |
+
or
|
| 29 |
+
First Person: No
|
| 30 |
+
"""
|
| 31 |
+
try:
|
| 32 |
+
response = processor_llm.invoke(prompt)
|
| 33 |
+
content = response.content.strip().lower()
|
| 34 |
+
if "first person: yes" in content:
|
| 35 |
+
return True
|
| 36 |
+
elif "first person: no" in content:
|
| 37 |
+
return False
|
| 38 |
+
else:
|
| 39 |
+
logging.warning(f"Unexpected output format from LLM for first person check: {content}")
|
| 40 |
+
return False
|
| 41 |
+
except Exception as e:
|
| 42 |
+
logging.error(f"LLM failed during first person check: {e}")
|
| 43 |
+
return False
|
| 44 |
|
| 45 |
|
| 46 |
def validate_response(question, answer, user_profile_str, fast_facts_str, interview_transcript_text, respondent_type, ai_evaluator_agent, processor_llm):
|