Code0ut commited on
Commit
c3efacd
·
verified ·
1 Parent(s): dc862b9

Upload folder using huggingface_hub

Browse files
server/mentalHealthPatientenv_environment.py CHANGED
@@ -135,12 +135,12 @@ class MentalhealthpatientenvEnvironment(Environment):
135
 
136
 
137
  return MentalhealthpatientenvObservation(
138
- response=generate_response(curr_diagnosis, actual_disorders,state=self._state ),
139
  clarity=random.uniform(0.0, 1.0),
140
  emotional_state="neutral",
141
  trust_level=self._state.trust_level,
142
  risk_flag=self._state.disclosed_risk,
143
- done=False,
144
  reward=reward,
145
  metadata={"diagnosis_result": curr_diagnosis, "actual_disorders": actual_disorders, "reward": reward}
146
  )
@@ -155,12 +155,12 @@ class MentalhealthpatientenvEnvironment(Environment):
155
  action_sequence=self._state.action_sequence
156
  )
157
  return MentalhealthpatientenvObservation(
158
- response=generate_response(action.action_type, action.message, state=self._state),
159
  clarity=random.uniform(0.0, 1.0),
160
  emotional_state="neutral",
161
  trust_level=self._state.trust_level,
162
  risk_flag=self._state.disclosed_risk,
163
- done=False,
164
  reward=reward, # small reward for taking an action
165
  metadata={"received_action": action.action_type}
166
  )
 
135
 
136
 
137
  return MentalhealthpatientenvObservation(
138
+ response=generate_response(curr_diagnosis, actual_disorders,state=self._state ) if self._state.step_count < self._state.max_turns else "Maximum turns reached. Ending session.",
139
  clarity=random.uniform(0.0, 1.0),
140
  emotional_state="neutral",
141
  trust_level=self._state.trust_level,
142
  risk_flag=self._state.disclosed_risk,
143
+ done=True if reward >= 0.8 or self._state.step_count >= self._state.max_turns else False,
144
  reward=reward,
145
  metadata={"diagnosis_result": curr_diagnosis, "actual_disorders": actual_disorders, "reward": reward}
146
  )
 
155
  action_sequence=self._state.action_sequence
156
  )
157
  return MentalhealthpatientenvObservation(
158
+ response=generate_response(action.action_type, action.message, state=self._state) if self._state.step_count < self._state.max_turns else "Maximum turns reached. Ending session.",
159
  clarity=random.uniform(0.0, 1.0),
160
  emotional_state="neutral",
161
  trust_level=self._state.trust_level,
162
  risk_flag=self._state.disclosed_risk,
163
+ done=True if self._state.step_count >= self._state.max_turns else False,
164
  reward=reward, # small reward for taking an action
165
  metadata={"received_action": action.action_type}
166
  )
server/response_generator.py CHANGED
@@ -59,35 +59,35 @@ def call_llm(prompt: str) -> str:
59
  }
60
 
61
  payload = {
62
- "model": "nvidia/nemotron-3-nano-30b-a3b:free",
63
  "messages": [
64
- {"role": "system", "content": "You are a mental health patient."},
65
  {"role": "user", "content": prompt}
66
  ],
67
- "temperature": 0.7,
68
- "max_tokens": 120,
69
  "top_p": 0.9
70
  }
71
 
72
  try:
73
- response = requests.post(OPENROUTER_URL, headers=headers, json=payload)
 
 
 
 
 
74
 
75
  if response.status_code != 200:
76
- print("OpenRouter Error:", response.text)
77
- return "I'm not sure how to respond right now..."
78
 
79
  result = response.json()
80
 
81
  content = result.get("choices", [{}])[0].get("message", {}).get("content")
82
 
83
- if not content:
84
- return "I don't really know how to explain it..."
85
 
86
- return content.strip()
87
-
88
- except Exception as e:
89
- print("LLM Error:", e)
90
- return "I don't know how to explain it..."
91
 
92
 
93
  # =========================
 
59
  }
60
 
61
  payload = {
62
+ "model": "liquid/lfm-2.5-1.2b-instruct:free",
63
  "messages": [
64
+ {"role": "system", "content": "You are a mental health patient. Keep answers short and natural."},
65
  {"role": "user", "content": prompt}
66
  ],
67
+ "temperature": 0.6,
68
+ "max_tokens": 50, # 🔥 IMPORTANT (reduce latency)
69
  "top_p": 0.9
70
  }
71
 
72
  try:
73
+ response = requests.post(
74
+ OPENROUTER_URL,
75
+ headers=headers,
76
+ json=payload,
77
+ timeout=5 # 🔥 prevents long waiting
78
+ )
79
 
80
  if response.status_code != 200:
81
+ return "I'm not really sure… just feeling a bit off."
 
82
 
83
  result = response.json()
84
 
85
  content = result.get("choices", [{}])[0].get("message", {}).get("content")
86
 
87
+ return content.strip() if content else "I don't know… just tired."
 
88
 
89
+ except Exception:
90
+ return "I don't really feel like talking much right now."
 
 
 
91
 
92
 
93
  # =========================