Basitha commited on
Commit
08871c2
·
verified ·
1 Parent(s): 5f05736

Update common/ResponseValidation.py

Browse files
Files changed (1) hide show
  1. common/ResponseValidation.py +22 -8
common/ResponseValidation.py CHANGED
@@ -21,10 +21,8 @@ You are an expert in analysing writing style and narrative perspective.
21
  Determine whether the following response is written from a first-person point of view.
22
  A first-person response includes pronouns like "I", "me", "my", "mine", "we", "our", or "us".
23
  Say "First Person: Yes" only if clearly first-person, else say "First Person: No".
24
-
25
  Response:
26
  \"\"\"{answer}\"\"\"
27
-
28
  Output format:
29
  First Person: Yes
30
  or
@@ -56,25 +54,20 @@ First Person: No
56
  # --- Step 4: Style validation prompt ---
57
  style_check_prompt = f"""
58
  You are a communication coach and writing style analyst.
59
-
60
  Evaluate whether the following response aligns with the given communication profile.
61
-
62
  ---
63
  ### Response:
64
  \"\"\"{answer}\"\"\"
65
-
66
  ### Communication Profile:
67
  - Style: {style}
68
  - Tone: {tone}
69
  - Preferred Length: {length}
70
  - Common Topics: {topics}
71
-
72
  ---
73
  ### Instructions:
74
  - Does the writing match the tone, style, and sentence structure described?
75
  - Is the language aligned in formality, expressiveness, and delivery?
76
  - Respond only with one of the following:
77
-
78
  Style Match: Yes
79
  or
80
  Style Match: No
@@ -87,7 +80,27 @@ Style Match: No
87
  logging.info("[Style Match Check] Match confirmed")
88
  return True
89
  elif "style match: no" in style_result:
90
- logging.info("[Style Match Check] Style mismatch detected")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  return False
92
  else:
93
  logging.warning(f"[Style Match Check] Unexpected output format: {style_result}")
@@ -99,6 +112,7 @@ Style Match: No
99
 
100
 
101
 
 
102
  def validate_response(question, answer, user_profile_str, fast_facts_str, interview_transcript_text, respondent_type, ai_evaluator_agent, processor_llm):
103
  llm_mode_prompt = f"""
104
  You are an expert in market research interview analysis. Given the following question, determine if it is:
 
21
  Determine whether the following response is written from a first-person point of view.
22
  A first-person response includes pronouns like "I", "me", "my", "mine", "we", "our", or "us".
23
  Say "First Person: Yes" only if clearly first-person, else say "First Person: No".
 
24
  Response:
25
  \"\"\"{answer}\"\"\"
 
26
  Output format:
27
  First Person: Yes
28
  or
 
54
  # --- Step 4: Style validation prompt ---
55
  style_check_prompt = f"""
56
  You are a communication coach and writing style analyst.
 
57
  Evaluate whether the following response aligns with the given communication profile.
 
58
  ---
59
  ### Response:
60
  \"\"\"{answer}\"\"\"
 
61
  ### Communication Profile:
62
  - Style: {style}
63
  - Tone: {tone}
64
  - Preferred Length: {length}
65
  - Common Topics: {topics}
 
66
  ---
67
  ### Instructions:
68
  - Does the writing match the tone, style, and sentence structure described?
69
  - Is the language aligned in formality, expressiveness, and delivery?
70
  - Respond only with one of the following:
 
71
  Style Match: Yes
72
  or
73
  Style Match: No
 
80
  logging.info("[Style Match Check] Match confirmed")
81
  return True
82
  elif "style match: no" in style_result:
83
+ # --- New: Ask LLM for explanation on mismatch ---
84
+ explanation_prompt = f"""
85
+ You are a communication coach and writing style analyst.
86
+ The following response was evaluated as NOT matching the given communication profile.
87
+ Please provide a concise reason why the style does not match.
88
+
89
+ ---
90
+ ### Response:
91
+ \"\"\"{answer}\"\"\"
92
+ ### Communication Profile:
93
+ - Style: {style}
94
+ - Tone: {tone}
95
+ - Preferred Length: {length}
96
+ - Common Topics: {topics}
97
+
98
+ ---
99
+ ### Please provide a short reason for style mismatch:
100
+ """
101
+ explanation_response = processor_llm.invoke(explanation_prompt)
102
+ explanation = explanation_response.content.strip()
103
+ logging.info(f"[Style Match Check] Style mismatch detected: {explanation}")
104
  return False
105
  else:
106
  logging.warning(f"[Style Match Check] Unexpected output format: {style_result}")
 
112
 
113
 
114
 
115
+
116
  def validate_response(question, answer, user_profile_str, fast_facts_str, interview_transcript_text, respondent_type, ai_evaluator_agent, processor_llm):
117
  llm_mode_prompt = f"""
118
  You are an expert in market research interview analysis. Given the following question, determine if it is: