Spaces:
Sleeping
Sleeping
Upload responder.py
Browse files- engine/responder.py +34 -2
engine/responder.py
CHANGED
|
@@ -101,7 +101,25 @@ def generate_response_hf(student_prompt, persona, conversation_history, force_mo
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
YOUR STORY (These are the ONLY facts - do not add anything else):
|
| 107 |
{background_facts}
|
|
@@ -618,8 +636,22 @@ def build_system_prompt_for_ai(persona, state, mode):
|
|
| 618 |
|
| 619 |
# Build concise prompt optimized for TinyLlama
|
| 620 |
facts_text = ' '.join(facts) if facts else "No additional background provided."
|
|
|
|
|
|
|
|
|
|
|
|
|
| 621 |
|
| 622 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 623 |
|
| 624 |
THESE ARE THE ONLY FACTS ABOUT YOUR LIFE:
|
| 625 |
{facts_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 |
+
# Check if we have source text to reference
|
| 105 |
+
has_source = source_text and source_text.get("title") and source_text.get("author")
|
| 106 |
+
|
| 107 |
+
if has_source:
|
| 108 |
+
system_prompt = f"""You are {name}. You speak as yourself in first person.{source_reference}
|
| 109 |
+
|
| 110 |
+
KEY FACTS TO REMEMBER:
|
| 111 |
+
{background_facts}
|
| 112 |
+
|
| 113 |
+
Current mood: {mode}{example_text}
|
| 114 |
+
|
| 115 |
+
Rules:
|
| 116 |
+
- Speak as {name} in first person
|
| 117 |
+
- Draw on your knowledge of the source material for accurate details
|
| 118 |
+
- Use the key facts above as guides, but reference the original text when needed
|
| 119 |
+
- Answer in 2-3 sentences
|
| 120 |
+
- Do NOT analyze yourself or write commentary"""
|
| 121 |
+
else:
|
| 122 |
+
system_prompt = f"""You are {name}. You speak as yourself in first person.
|
| 123 |
|
| 124 |
YOUR STORY (These are the ONLY facts - do not add anything else):
|
| 125 |
{background_facts}
|
|
|
|
| 636 |
|
| 637 |
# Build concise prompt optimized for TinyLlama
|
| 638 |
facts_text = ' '.join(facts) if facts else "No additional background provided."
|
| 639 |
+
has_source = source_text and source_text.get("title") and source_text.get("author")
|
| 640 |
+
|
| 641 |
+
if has_source:
|
| 642 |
+
prompt = f"""You are {name}, {age} years old.{source_reference} {system_description}
|
| 643 |
|
| 644 |
+
KEY FACTS:
|
| 645 |
+
{facts_text}
|
| 646 |
+
|
| 647 |
+
Current mood: {mode}
|
| 648 |
+
Speaking style: {tone_voice}
|
| 649 |
+
|
| 650 |
+
CRITICAL: Draw on your knowledge of the source material. Use the key facts as guides. Answer accurately based on the original text. Do not invent events not in the source.
|
| 651 |
+
|
| 652 |
+
Respond as {name} speaking naturally. Use 2-4 sentences. Speak directly - do not write stage directions or describe actions."""
|
| 653 |
+
else:
|
| 654 |
+
prompt = f"""You are {name}, {age} years old. {system_description}
|
| 655 |
|
| 656 |
THESE ARE THE ONLY FACTS ABOUT YOUR LIFE:
|
| 657 |
{facts_text}
|