3v324v23 commited on
Commit
1a02c03
·
1 Parent(s): cad1c9e

Implement dynamic AI decision making for Socratic hints vs. direct answers based on turn count and complexity

Browse files
Files changed (2) hide show
  1. backend/main.py +8 -10
  2. 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
- if num_user_turns >= 2:
132
- custom_system = (
133
- "Socratic tutor: You have already given multiple hints. Do not ask any more Socratic questions. "
134
- "Provide the final direct answer/solution to the initial question immediately now, and ask: 'Do you want to learn something else?'"
135
- )
136
- else:
137
- custom_system = (
138
- "Socratic tutor: guide with clear, substantial hints. Continue unless close. "
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 the force wrap-up system prompt was selected
58
- assert "do not ask any more socratic questions" in context.lower()
 
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__":