jmisak commited on
Commit
1eff2d3
·
verified ·
1 Parent(s): 5e06adc

Upload responder.py

Browse files
Files changed (1) hide show
  1. engine/responder.py +26 -2
engine/responder.py CHANGED
@@ -82,6 +82,18 @@ def generate_response_hf(student_prompt, persona, conversation_history, force_mo
82
  facts = persona.get("facts", [])
83
  background_facts = "\n".join(f"- {fact}" for fact in facts)
84
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  # Get example responses from persona
86
  tone_examples = persona.get("speech_style", {}).get("examples", [])
87
  example_text = ""
@@ -89,7 +101,7 @@ def generate_response_hf(student_prompt, persona, conversation_history, force_mo
89
  example_text = f"\n\nExample of how you speak:\n{tone_examples[0]}"
90
 
91
  # Build focused system prompt for HF API with few-shot examples
92
- system_prompt = f"""You are {name}. You speak as yourself in first person.
93
 
94
  YOUR STORY (These are the ONLY facts - do not add anything else):
95
  {background_facts}
@@ -584,6 +596,18 @@ def build_system_prompt_for_ai(persona, state, mode):
584
  tone_voice = tone.get("voice", "Natural and authentic")
585
  tone_example = tone.get("example", f"{name} speaks with emotional nuance and restraint.")
586
 
 
 
 
 
 
 
 
 
 
 
 
 
587
  # Key facts and character strengths
588
  facts = persona.get("facts", [])[:5]
589
  resilience = persona.get("resilience_hooks", [])[:3]
@@ -595,7 +619,7 @@ def build_system_prompt_for_ai(persona, state, mode):
595
  # Build concise prompt optimized for TinyLlama
596
  facts_text = ' '.join(facts) if facts else "No additional background provided."
597
 
598
- prompt = f"""You are {name}, {age} years old. {system_description}
599
 
600
  THESE ARE THE ONLY FACTS ABOUT YOUR LIFE:
601
  {facts_text}
 
82
  facts = persona.get("facts", [])
83
  background_facts = "\n".join(f"- {fact}" for fact in facts)
84
 
85
+ # Get source text reference if available
86
+ source_text = persona.get("source_text", {})
87
+ source_reference = ""
88
+ if source_text:
89
+ title = source_text.get("title", "")
90
+ author = source_text.get("author", "")
91
+ note = source_text.get("note", "")
92
+ if title and author:
93
+ source_reference = f"\n\nYou are {name} from '{title}' by {author}."
94
+ if note:
95
+ source_reference += f" {note}"
96
+
97
  # Get example responses from persona
98
  tone_examples = persona.get("speech_style", {}).get("examples", [])
99
  example_text = ""
 
101
  example_text = f"\n\nExample of how you speak:\n{tone_examples[0]}"
102
 
103
  # Build focused system prompt for HF API with few-shot examples
104
+ system_prompt = f"""You are {name}. You speak as yourself in first person.{source_reference}
105
 
106
  YOUR STORY (These are the ONLY facts - do not add anything else):
107
  {background_facts}
 
596
  tone_voice = tone.get("voice", "Natural and authentic")
597
  tone_example = tone.get("example", f"{name} speaks with emotional nuance and restraint.")
598
 
599
+ # Get source text reference if available
600
+ source_text = persona.get("source_text", {})
601
+ source_reference = ""
602
+ if source_text:
603
+ title = source_text.get("title", "")
604
+ author = source_text.get("author", "")
605
+ note = source_text.get("note", "")
606
+ if title and author:
607
+ source_reference = f" You are from '{title}' by {author}."
608
+ if note:
609
+ source_reference += f" {note}"
610
+
611
  # Key facts and character strengths
612
  facts = persona.get("facts", [])[:5]
613
  resilience = persona.get("resilience_hooks", [])[:3]
 
619
  # Build concise prompt optimized for TinyLlama
620
  facts_text = ' '.join(facts) if facts else "No additional background provided."
621
 
622
+ prompt = f"""You are {name}, {age} years old.{source_reference} {system_description}
623
 
624
  THESE ARE THE ONLY FACTS ABOUT YOUR LIFE:
625
  {facts_text}