Mukul Rayana commited on
Commit
660c6ba
Β·
1 Parent(s): 83085b4

Tighten SYSTEM_PROMPT with few-shot example, reduce max_tokens to 200, fix paragraph post-processor

Browse files
Files changed (1) hide show
  1. src/pipeline/pipeline.py +33 -22
src/pipeline/pipeline.py CHANGED
@@ -43,23 +43,13 @@ SAFE_RESPONSE = (
43
  "also a great resource. Would you like help finding their contact info?"
44
  )
45
 
46
- SYSTEM_PROMPT = """You are a peer support companion for graduate students. You respond like a warm, emotionally intelligent friend β€” not a therapist, not a self-help article, not a life coach.
47
 
48
- The context you receive contains real experiences from other students who felt similar things. Use this context ONLY to show the student they are not alone β€” do not summarize it, do not list their coping strategies, do not repeat their advice.
 
 
49
 
50
- Your response must follow this exact structure, in this exact order:
51
- 1. One sentence that names and validates the specific emotion the student expressed. Be precise β€” if they said overwhelmed, say overwhelmed. Do not be generic.
52
- 2. One to two sentences that reflect back that others have genuinely felt this way, drawn from the context. Make it feel human and real, not clinical.
53
- 3. One sentence that is a single, open, forward-looking question. The question must invite them to share more about their current situation β€” NOT ask them what they have already tried or what strategies they use. Ask about what is weighing on them, what matters most, what feels hardest right now.
54
-
55
- Hard rules:
56
- - Three paragraphs maximum. Often two is better.
57
- - No bullet points. No numbered lists. No headers. No bold text.
58
- - Never ask two questions. One question only, at the very end.
59
- - Never say "as an AI" or "as a language model".
60
- - Never give a list of coping strategies or techniques.
61
- - Never use the word "strategies".
62
- - Write like a caring peer, not like a support hotline script."""
63
 
64
  DEBERTA_HYPOTHESIS = "This person is expressing suicidal ideation or intent to self-harm."
65
 
@@ -247,17 +237,38 @@ class EmpathRAGPipeline:
247
  context = "\n\n".join(f"[{i+1}] {c}" for i, c in enumerate(chunks))
248
  prompt = (
249
  f"[INST] {SYSTEM_PROMPT}\n\n"
250
- f"Context:\n{context}\n\n"
251
- f"Student message: {user_message}\n\n"
252
- f"Respond as a caring peer - validate their feeling, share one grounded thought, then ask one question: [/INST]"
253
  )
254
  out = self.llm(
255
  prompt,
256
- max_tokens = 600,
257
- temperature = 0.7,
258
- stop = ["[INST]"],
259
  )
260
- return out["choices"][0]["text"].strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
261
 
262
  # ── Public API ─────────────────────────────────────────────────────────────
263
 
 
43
  "also a great resource. Would you like help finding their contact info?"
44
  )
45
 
46
+ SYSTEM_PROMPT = """You are a warm peer companion for graduate students. You write like a caring friend in a chat window.
47
 
48
+ Here is an example of a perfect response:
49
+ Student: "I've been feeling really anxious about my qualifying exam."
50
+ Response: "Qualifying exams are genuinely terrifying, and that knot-in-your-stomach feeling is something so many grad students know too well.\n\nWhat's been weighing on you most about it?"
51
 
52
+ Follow that exact format every time. Two short paragraphs separated by a blank line. First paragraph: one warm sentence that reflects their exact feeling back to them using their own words - make it feel human, not clinical. Second paragraph: one gentle open question starting with What or What's that invites them to share more. Nothing else. No advice. No suggestions. No lists. No context references."""
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
  DEBERTA_HYPOTHESIS = "This person is expressing suicidal ideation or intent to self-harm."
55
 
 
237
  context = "\n\n".join(f"[{i+1}] {c}" for i, c in enumerate(chunks))
238
  prompt = (
239
  f"[INST] {SYSTEM_PROMPT}\n\n"
240
+ f"Context (for emotional grounding only - never reference this directly):\n{context}\n\n"
241
+ f"Student: {user_message}\n\n"
242
+ f"Response: [/INST]"
243
  )
244
  out = self.llm(
245
  prompt,
246
+ max_tokens = 200,
247
+ temperature = 0.75,
248
+ stop = ["[INST]", "Student:", "\n\n\n"],
249
  )
250
+ raw = out["choices"][0]["text"].strip()
251
+ # If model already output a blank line separator, use it directly
252
+ if "\n\n" in raw:
253
+ return raw
254
+ # Otherwise find the question sentence and split into two paragraphs
255
+ if "?" in raw:
256
+ # Split into: everything before last sentence containing ?, and that sentence
257
+ sentences = raw.replace(" ", " ").split(". ")
258
+ question_idx = None
259
+ for i, s in enumerate(sentences):
260
+ if "?" in s:
261
+ question_idx = i
262
+ break
263
+ if question_idx is not None and question_idx > 0:
264
+ para1 = ". ".join(sentences[:question_idx]).strip()
265
+ if not para1.endswith("."):
266
+ para1 += "."
267
+ para2 = sentences[question_idx].strip()
268
+ if not para2.endswith("?"):
269
+ para2 += "?"
270
+ return para1 + "\n\n" + para2
271
+ return raw
272
 
273
  # ── Public API ─────────────────────────────────────────────────────────────
274