Implement dynamic AI decision making for Socratic hints vs. direct answers based on turn count and complexity
Browse files- backend/main.py +8 -10
- backend/test_sentiment.py +3 -2
backend/main.py
CHANGED
|
@@ -128,16 +128,14 @@ def run_flow_b(message: str, api_key: str, history: Optional[List[ChatMessage]]
|
|
| 128 |
)
|
| 129 |
|
| 130 |
num_user_turns = sum(1 for m in history if m.role == "user") if history else 0
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
"If close: give solution to the initial question & ask: 'Do you want to learn something else?'"
|
| 140 |
-
)
|
| 141 |
|
| 142 |
tone_instruction = (
|
| 143 |
"JSON: {\"s\":\"sentiment\",\"r\":\"reply\"}\n"
|
|
|
|
| 128 |
)
|
| 129 |
|
| 130 |
num_user_turns = sum(1 for m in history if m.role == "user") if history else 0
|
| 131 |
+
custom_system = (
|
| 132 |
+
f"Socratic tutor: guide with clear, substantial hints. "
|
| 133 |
+
f"Current conversation: {num_user_turns} user turns so far. "
|
| 134 |
+
"Dynamically decide whether to nudge or give the final direct solution. "
|
| 135 |
+
"Provide the final direct answer/solution immediately if: the user is close, highly frustrated, "
|
| 136 |
+
"asks directly for the answer, or if hints exceed topic complexity (e.g., 2 hints for simple topics, 4 for complex topics). "
|
| 137 |
+
"Otherwise, continue guiding with a hint and ask exactly 1 Socratic question."
|
| 138 |
+
)
|
|
|
|
|
|
|
| 139 |
|
| 140 |
tone_instruction = (
|
| 141 |
"JSON: {\"s\":\"sentiment\",\"r\":\"reply\"}\n"
|
backend/test_sentiment.py
CHANGED
|
@@ -54,8 +54,9 @@ def test_run_flow_b_force_wrap_up():
|
|
| 54 |
history=history
|
| 55 |
)
|
| 56 |
|
| 57 |
-
# Verify that
|
| 58 |
-
assert "
|
|
|
|
| 59 |
print("Mocked force wrap-up test passed!")
|
| 60 |
|
| 61 |
if __name__ == "__main__":
|
|
|
|
| 54 |
history=history
|
| 55 |
)
|
| 56 |
|
| 57 |
+
# Verify that turn counting and dynamic decision instructions are injected correctly
|
| 58 |
+
assert "current conversation: 2 user turns so far" in context.lower()
|
| 59 |
+
assert "dynamically decide" in context.lower()
|
| 60 |
print("Mocked force wrap-up test passed!")
|
| 61 |
|
| 62 |
if __name__ == "__main__":
|