Spaces:
Build error
Build error
Update researchsimulation/InteractiveInterviewChatbot.py
Browse files
researchsimulation/InteractiveInterviewChatbot.py
CHANGED
|
@@ -240,6 +240,7 @@ def generate_generic_answer(agent_name, agent_question, respondent_agent, respon
|
|
| 240 |
- Do **not** speak as an individual or use "I", "my", or "me".
|
| 241 |
- Avoid personal anecdotes—focus on shared behaviours, preferences, or perceptions.
|
| 242 |
- If there is diversity of opinion, include it naturally (e.g., "some of us...", "others felt...").
|
|
|
|
| 243 |
"""
|
| 244 |
else:
|
| 245 |
persona_description = f"You are {agent_name}. You represent an individual user with a unique point of view."
|
|
@@ -440,24 +441,26 @@ def validate_generic_answer(agent_name, agent_question, generic_answer, user_pro
|
|
| 440 |
logging.exception("[validate_generic_answer] Exception during validation")
|
| 441 |
return False, "Exception during validation"
|
| 442 |
|
| 443 |
-
def validate_styled_answer(agent_name, agent_question, styled_answer, user_profile, processor_llm):
|
| 444 |
"""
|
| 445 |
-
Validates whether the styled answer matches the user's
|
| 446 |
-
Returns (True, explanation) if
|
| 447 |
"""
|
| 448 |
logging.info("[validate_styled_answer] Entry")
|
|
|
|
| 449 |
try:
|
| 450 |
is_valid, explanation = matches_user_speaking_style(
|
| 451 |
answer=styled_answer,
|
| 452 |
processor_llm=processor_llm,
|
| 453 |
user_profile=user_profile,
|
| 454 |
agent_question=agent_question,
|
|
|
|
| 455 |
return_explanation=True
|
| 456 |
)
|
| 457 |
-
logging.info(f"[validate_styled_answer]
|
| 458 |
return is_valid, explanation
|
| 459 |
except Exception as e:
|
| 460 |
-
logging.exception("[validate_styled_answer] Exception during
|
| 461 |
return False, "Exception during style validation"
|
| 462 |
|
| 463 |
|
|
@@ -537,7 +540,7 @@ def ask_interview_question(respondent_agents_dict, last_active_agent, question,
|
|
| 537 |
continue
|
| 538 |
|
| 539 |
is_valid, style_feedback = validate_styled_answer(
|
| 540 |
-
agent_name, agent_question, styled, user_profile, processor_llm
|
| 541 |
)
|
| 542 |
if is_valid:
|
| 543 |
tailored_answer = styled
|
|
|
|
| 240 |
- Do **not** speak as an individual or use "I", "my", or "me".
|
| 241 |
- Avoid personal anecdotes—focus on shared behaviours, preferences, or perceptions.
|
| 242 |
- If there is diversity of opinion, include it naturally (e.g., "some of us...", "others felt...").
|
| 243 |
+
- If the group does not have **direct experience** with the topic, acknowledge that honestly. Do not fabricate experiences. It's okay to say "none of us have ..., but we’ve heard..." or "we can’t comment from experience."
|
| 244 |
"""
|
| 245 |
else:
|
| 246 |
persona_description = f"You are {agent_name}. You represent an individual user with a unique point of view."
|
|
|
|
| 441 |
logging.exception("[validate_generic_answer] Exception during validation")
|
| 442 |
return False, "Exception during validation"
|
| 443 |
|
| 444 |
+
def validate_styled_answer(agent_name, agent_question, styled_answer, user_profile, processor_llm, respondent_type):
|
| 445 |
"""
|
| 446 |
+
Validates whether the styled answer matches the user's speaking style (individual or focus group).
|
| 447 |
+
Returns (True, explanation) if aligned, (False, explanation) otherwise.
|
| 448 |
"""
|
| 449 |
logging.info("[validate_styled_answer] Entry")
|
| 450 |
+
|
| 451 |
try:
|
| 452 |
is_valid, explanation = matches_user_speaking_style(
|
| 453 |
answer=styled_answer,
|
| 454 |
processor_llm=processor_llm,
|
| 455 |
user_profile=user_profile,
|
| 456 |
agent_question=agent_question,
|
| 457 |
+
respondent_type=respondent_type,
|
| 458 |
return_explanation=True
|
| 459 |
)
|
| 460 |
+
logging.info(f"[validate_styled_answer] Validation result: {is_valid}, explanation: {explanation}")
|
| 461 |
return is_valid, explanation
|
| 462 |
except Exception as e:
|
| 463 |
+
logging.exception("[validate_styled_answer] Exception during validation")
|
| 464 |
return False, "Exception during style validation"
|
| 465 |
|
| 466 |
|
|
|
|
| 540 |
continue
|
| 541 |
|
| 542 |
is_valid, style_feedback = validate_styled_answer(
|
| 543 |
+
agent_name, agent_question, styled, user_profile, processor_llm, respondent_type
|
| 544 |
)
|
| 545 |
if is_valid:
|
| 546 |
tailored_answer = styled
|