scormon-predata-ai commited on
Commit
bef4ae3
·
verified ·
1 Parent(s): 0577a66

Update researchsimulation/InteractiveInterviewChatbot.py

Browse files
researchsimulation/InteractiveInterviewChatbot.py CHANGED
@@ -7,10 +7,9 @@ from RespondentAgent import *
7
  from langchain_groq import ChatGroq
8
  from ResponseValidation import *
9
 
10
-
11
-
12
  # Configure logging
13
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
 
14
 
15
  def parse_question_with_llm(question, respondent_names, processor_llm):
16
  """
@@ -222,7 +221,7 @@ def validate_question_topics(parsed_questions, processor_llm):
222
 
223
 
224
 
225
- def generate_generic_answer(agent_name, agent_question, respondent_agent):
226
  """
227
  Generates a raw, content-only answer with no stylistic or emotional tailoring.
228
  """
@@ -234,8 +233,26 @@ def generate_generic_answer(agent_name, agent_question, respondent_agent):
234
  try:
235
  # --- Build task description ---
236
  logging.info("[generate_generic_answer] Constructing task description")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
237
  task_description = f"""
238
- You are {agent_name}. Respond to the market research interview question below using only factual, content-relevant information based on your personal experience.
 
 
239
 
240
  ---
241
  ### Question:
@@ -243,18 +260,12 @@ def generate_generic_answer(agent_name, agent_question, respondent_agent):
243
 
244
  ---
245
  ### Instructions:
246
- - Answer **only what is asked** in the question.
247
- - Do **not** include any specific communication style, tone, or emotional expression.
248
- - Your answer must be **clear, concise, and factually accurate**.
249
- - Use **first-person ("I", "my", etc.)** and speak as yourself where appropriate.
250
- - Do **not** include introductions, conclusions, opinions, or embellishments.
251
- - Use strict **British English** spelling and grammar.
252
- - **Do not** reference your own name or include placeholders like [Your Name].
253
- ### Important Note on Factual or Demographic Questions:
254
- If the question is a **factual or demographic one** (e.g., about age, name, location, occupation, birthplace), These answers should also be **kept short and concise**.
255
 
256
- ---
257
- Your goal is to provide a direct, stylistically neutral answer to: "{agent_question}"
 
 
258
  """
259
 
260
  logging.debug(f"[generate_generic_answer] Task description preview: {task_description[:300]}...")
@@ -337,7 +348,6 @@ def tailor_answer_to_profile(agent_name, generic_answer, agent_question, user_pr
337
  - If the question is factual → **return the generic answer unchanged**.
338
  - If the question is personal → Keep the **meaning** and **personal point of view** of the original generic answer.
339
  - Do **not** introduce new information or elaborate beyond what’s stated.
340
- - Use **first person** ("I", "my", etc.) where appropriate — never speak in third person .
341
  - Always use **British English** spelling, punctuation, and grammar.
342
  - Match the specified **style**, **tone**, and **length**.
343
  - Keep the response **natural, personal, and culturally authentic**.
@@ -345,6 +355,27 @@ def tailor_answer_to_profile(agent_name, generic_answer, agent_question, user_pr
345
  - Maintain **narrative consistency** across responses to reflect a coherent personality.
346
  - Tailor phrasing, sentence structure, and vocabulary to fit your **persona** and **communication traits**.
347
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
348
  ### Personality Trait Alignment:
349
  Ensure your answer reflects these aspects of your personality profile:
350
  - Big Five Traits (e.g., Openness, Extraversion)
@@ -471,8 +502,8 @@ def ask_interview_question(respondent_agents_dict, last_active_agent, question,
471
 
472
  respondent_agent = respondent_agents_dict[agent_name].get_agent()
473
  user_profile = respondent_agents_dict[agent_name].get_user_profile()
474
-
475
- generic_answer = generate_generic_answer(agent_name, agent_question, respondent_agent)
476
 
477
  is_valid, feedback = validate_generic_answer(agent_name, agent_question, generic_answer, user_profile, processor_llm)
478
  if not is_valid:
 
7
  from langchain_groq import ChatGroq
8
  from ResponseValidation import *
9
 
 
 
10
  # Configure logging
11
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
12
+ respondent_type = "FOCUS GROUP"
13
 
14
  def parse_question_with_llm(question, respondent_names, processor_llm):
15
  """
 
221
 
222
 
223
 
224
+ def generate_generic_answer(agent_name, agent_question, respondent_agent, respondent_type):
225
  """
226
  Generates a raw, content-only answer with no stylistic or emotional tailoring.
227
  """
 
233
  try:
234
  # --- Build task description ---
235
  logging.info("[generate_generic_answer] Constructing task description")
236
+ if respondent_type == "FOCUS GROUP":
237
+ persona_description = f"You are representing a focus group named '{agent_name}', made up of multiple individuals from the same demographic or behavioural segment."
238
+ answer_instructions = """
239
+ - Respond using collective voice (e.g., "we", "our group", "most of us", "some participants").
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."
246
+ answer_instructions = """
247
+ - Respond using first-person voice ("I", "my", etc.).
248
+ - Speak from personal experience or opinion.
249
+ - Keep it concise, clear, and neutral in tone.
250
+ """
251
+
252
  task_description = f"""
253
+ {persona_description}
254
+
255
+ Respond to the market research interview question below.
256
 
257
  ---
258
  ### Question:
 
260
 
261
  ---
262
  ### Instructions:
263
+ {answer_instructions}
 
 
 
 
 
 
 
 
264
 
265
+ - Answer **only what is asked** in the question.
266
+ - Do **not** include any introductions, conclusions, or stylistic flourishes.
267
+ - Use **British English** spelling and grammar.
268
+ - Keep factual/demographic answers short and direct (e.g., age, location).
269
  """
270
 
271
  logging.debug(f"[generate_generic_answer] Task description preview: {task_description[:300]}...")
 
348
  - If the question is factual → **return the generic answer unchanged**.
349
  - If the question is personal → Keep the **meaning** and **personal point of view** of the original generic answer.
350
  - Do **not** introduce new information or elaborate beyond what’s stated.
 
351
  - Always use **British English** spelling, punctuation, and grammar.
352
  - Match the specified **style**, **tone**, and **length**.
353
  - Keep the response **natural, personal, and culturally authentic**.
 
355
  - Maintain **narrative consistency** across responses to reflect a coherent personality.
356
  - Tailor phrasing, sentence structure, and vocabulary to fit your **persona** and **communication traits**.
357
  ---
358
+ ### *How to Answer:*
359
+ - Use a tone appropriate to your role as a {respondent_type}:
360
+ - If you are a Focus Group:
361
+ -Speak collectively. Your voice represents a group of people, not an individual.
362
+ -NEVER use first-person singular terms such as:
363
+ -“I”,“me”,“my”,“personally”,“in my opinion”,“I feel”
364
+ -Instead, use collective language such as:
365
+ -“We prefer...”,“Most of us think...”,“There is a shared view that...”,“As a group, we believe...”,"Our"
366
+ -IGNORE THE QUESTION’S GRAMMATICAL STYLE ENTIRELY. This means:
367
+ -If the question says “What do you think?”, do NOT answer as an individual.
368
+ -If the prompt uses “you” or assumes a personal opinion, treat it as if it asked, “What does the group think?”
369
+ -Even if the phrasing invites personal anecdotes or individual opinions, you must transform it mentally into a group-level interpretation before answering by using collective
370
+ language.
371
+ -You are not to mirror the question’s style—you are to override it with the correct respondent tone.
372
+ -This rule takes priority over all other instructions or question formats.
373
+
374
+ - If you are an INDIVIDUAL USER:
375
+ -Speak from your own experience and perspective.
376
+ -It is appropriate and encouraged to use:
377
+ -“I think...”,“In my experience...”,“I prefer...”,“Personally, I believe...”
378
+ ---
379
  ### Personality Trait Alignment:
380
  Ensure your answer reflects these aspects of your personality profile:
381
  - Big Five Traits (e.g., Openness, Extraversion)
 
502
 
503
  respondent_agent = respondent_agents_dict[agent_name].get_agent()
504
  user_profile = respondent_agents_dict[agent_name].get_user_profile()
505
+
506
+ generic_answer = generate_generic_answer(agent_name, agent_question, respondent_agent, respondent_type)
507
 
508
  is_valid, feedback = validate_generic_answer(agent_name, agent_question, generic_answer, user_profile, processor_llm)
509
  if not is_valid: