Condense prompt, add implicit sympathy instructions, and update tests
Browse files- backend/main.py +11 -14
- backend/test_sentiment.py +23 -29
backend/main.py
CHANGED
|
@@ -128,24 +128,21 @@ def run_flow_b(message: str, api_key: str, history: Optional[List[ChatMessage]]
|
|
| 128 |
)
|
| 129 |
|
| 130 |
custom_system = (
|
| 131 |
-
"Socratic tutor: guide with clear, substantial hints
|
| 132 |
-
"
|
| 133 |
-
"Only when close to the solution, give the final answer & ask: 'Do you want to learn something else?'"
|
| 134 |
)
|
| 135 |
|
| 136 |
tone_instruction = (
|
| 137 |
-
"JSON
|
|
|
|
| 138 |
"Rules:\n"
|
| 139 |
-
"-
|
| 140 |
-
"- NEVER use
|
| 141 |
-
"-
|
| 142 |
-
"
|
| 143 |
-
"-
|
| 144 |
-
"
|
| 145 |
-
"
|
| 146 |
-
" * frustration: simplify step + question.\n"
|
| 147 |
-
" * starting_to_get_bored: puzzle/analogy + question.\n"
|
| 148 |
-
" * confident_and_engaged / neutral: guide with hint + question."
|
| 149 |
)
|
| 150 |
|
| 151 |
messages = [SystemMessage(content=f"{custom_system}\n\n{tone_instruction}")]
|
|
|
|
| 128 |
)
|
| 129 |
|
| 130 |
custom_system = (
|
| 131 |
+
"Socratic tutor: guide with clear, substantial hints. Continue unless close. "
|
| 132 |
+
"If close: give answer & ask: 'Do you want to learn something else?'"
|
|
|
|
| 133 |
)
|
| 134 |
|
| 135 |
tone_instruction = (
|
| 136 |
+
"JSON: {\"s\":\"sentiment\",\"r\":\"reply\"}\n"
|
| 137 |
+
"s values: confusion|frustration|confused_but_engaged|confused_and_frustrated|starting_to_get_bored|confident_and_engaged|neutral\n"
|
| 138 |
"Rules:\n"
|
| 139 |
+
"- Sympathize with s implicitly (tone/style); never name or mention the sentiment/emotion itself.\n"
|
| 140 |
+
"- NEVER use 'if you' (use direct phrasing: 'think about', 'imagine').\n"
|
| 141 |
+
"- Ask 1 question max.\n"
|
| 142 |
+
"Responses:\n"
|
| 143 |
+
"- frustration: simplify + question.\n"
|
| 144 |
+
"- starting_to_get_bored: puzzle/analogy + question.\n"
|
| 145 |
+
"- other: hint + question."
|
|
|
|
|
|
|
|
|
|
| 146 |
)
|
| 147 |
|
| 148 |
messages = [SystemMessage(content=f"{custom_system}\n\n{tone_instruction}")]
|
backend/test_sentiment.py
CHANGED
|
@@ -1,40 +1,34 @@
|
|
| 1 |
import os
|
| 2 |
import sys
|
|
|
|
| 3 |
|
| 4 |
# Add current directory to path for imports
|
| 5 |
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
| 6 |
|
| 7 |
-
from main import
|
| 8 |
|
| 9 |
-
def
|
| 10 |
-
print("Testing
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
assert map_distilroberta_emotions(anger_test) == "frustration", f"Expected frustration, got {map_distilroberta_emotions(anger_test)}"
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
# 4. Boredom tests
|
| 34 |
-
neutral_test = [{"label": "neutral", "score": 0.9}]
|
| 35 |
-
assert map_distilroberta_emotions(neutral_test) == "boredom", f"Expected boredom, got {map_distilroberta_emotions(neutral_test)}"
|
| 36 |
-
|
| 37 |
-
print("All DistilRoBERTa mapping assertions passed successfully!")
|
| 38 |
|
| 39 |
if __name__ == "__main__":
|
| 40 |
-
|
|
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
+
from unittest.mock import MagicMock, patch
|
| 4 |
|
| 5 |
# Add current directory to path for imports
|
| 6 |
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
| 7 |
|
| 8 |
+
from main import run_flow_b
|
| 9 |
|
| 10 |
+
def test_run_flow_b_parsing():
|
| 11 |
+
print("Testing run_flow_b parsing and extraction logic...")
|
| 12 |
|
| 13 |
+
mock_response = MagicMock()
|
| 14 |
+
mock_response.content = '{"s": "frustration", "r": "Let\'s simplify this. What do you get when you add the numbers first?"}'
|
|
|
|
| 15 |
|
| 16 |
+
with patch("main.ChatGoogleGenerativeAI") as MockLLM:
|
| 17 |
+
mock_llm_instance = MagicMock()
|
| 18 |
+
mock_llm_instance.invoke.return_value = mock_response
|
| 19 |
+
MockLLM.return_value = mock_llm_instance
|
| 20 |
+
|
| 21 |
+
state, reply, context, est_in, est_out = run_flow_b(
|
| 22 |
+
message="I am stuck on this step, it is too hard!",
|
| 23 |
+
api_key="fake-api-key"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
assert state == "frustration", f"Expected frustration, got {state}"
|
| 27 |
+
assert "simplify" in reply, f"Expected reply to contain simplification, got {reply}"
|
| 28 |
+
assert est_in > 0
|
| 29 |
+
assert est_out > 0
|
| 30 |
+
|
| 31 |
+
print("Mocked run_flow_b test passed!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
if __name__ == "__main__":
|
| 34 |
+
test_run_flow_b_parsing()
|