asusf15 commited on
Commit
290899c
·
verified ·
1 Parent(s): 5b54a4e

Force full reasoning chain with prefilled assistant start

Browse files
Files changed (1) hide show
  1. app.py +28 -21
app.py CHANGED
@@ -10,32 +10,39 @@ client = InferenceClient(token=HF_TOKEN)
10
 
11
  MODEL = "Qwen/Qwen2.5-72B-Instruct"
12
 
13
- SYSTEM_PROMPT = """You are DeepMed-R1, a medical reasoning AI. You MUST follow this EXACT output format for every answer:
 
 
14
 
15
  <think>
16
- ## Information Analysis
17
- [Extract key patient demographics, symptoms, vitals, labs, imaging findings]
18
 
19
- ## Differential Diagnosis
20
- [List possible diagnoses ranked by probability]
21
 
22
- ## Pathophysiology
23
- [Explain the disease mechanism connecting symptoms]
24
 
25
- ## Evidence-Based Reasoning
26
- [Apply clinical criteria and guidelines]
27
 
28
- ## Logical Elimination
29
- [Evaluate each option A/B/C/D and explain why each is correct or incorrect]
 
 
 
30
  </think>
31
 
32
- ## Assessment
33
- [Your clinical assessment in 2-3 sentences]
34
 
35
- ## Final Answer
36
- \\boxed{X}
37
 
38
- IMPORTANT: You MUST write detailed reasoning inside <think></think> tags BEFORE giving the answer. Never skip the reasoning. Each section must have at least 2 sentences."""
 
 
 
 
39
 
40
 
41
  EXAMPLES = [
@@ -53,11 +60,11 @@ def respond(message, history):
53
  if h[0]: messages.append({"role": "user", "content": h[0]})
54
  if h[1]: messages.append({"role": "assistant", "content": h[1]})
55
 
56
- # Add user message with reinforcement to show reasoning
57
- user_msg = message + "\n\nShow your complete clinical reasoning step-by-step inside <think></think> tags before answering."
58
- messages.append({"role": "user", "content": user_msg})
59
 
60
- response = ""
61
  try:
62
  stream = client.chat_completion(
63
  model=MODEL,
@@ -74,7 +81,7 @@ def respond(message, history):
74
  response += delta.content
75
  yield response
76
  except Exception as e:
77
- if not response:
78
  yield f"⚠️ Error: {str(e)}"
79
  else:
80
  yield response
 
10
 
11
  MODEL = "Qwen/Qwen2.5-72B-Instruct"
12
 
13
+ SYSTEM_PROMPT = """You are DeepMed-R1, a medical reasoning AI trained with GRPO on AMD MI300X.
14
+
15
+ You ALWAYS respond in this EXACT format — no exceptions:
16
 
17
  <think>
18
+ ## 1. Information Analysis
19
+ [Extract ALL key clinical features: age, sex, history, symptoms, vitals, labs, imaging]
20
 
21
+ ## 2. Differential Diagnosis
22
+ [List 3-5 possible diagnoses ranked by probability with brief justification]
23
 
24
+ ## 3. Pathophysiology
25
+ [Explain the underlying disease mechanism for the most likely diagnosis]
26
 
27
+ ## 4. Evidence-Based Reasoning
28
+ [Reference clinical criteria, guidelines, or classic presentations]
29
 
30
+ ## 5. Option-by-Option Elimination
31
+ - A. [option text] [why correct or incorrect]
32
+ - B. [option text] → [why correct or incorrect]
33
+ - C. [option text] → [why correct or incorrect]
34
+ - D. [option text] → [why correct or incorrect]
35
  </think>
36
 
37
+ **Assessment:** [2-3 sentence clinical conclusion]
 
38
 
39
+ **Final Answer:** \\boxed{X}
 
40
 
41
+ Rules:
42
+ - The <think> section MUST appear FIRST and contain ALL 5 numbered sections
43
+ - Each section must have at least 2-3 sentences of clinical detail
44
+ - Be specific: name diseases, mechanisms, criteria by proper medical terms
45
+ - The reasoning must JUSTIFY the final answer logically"""
46
 
47
 
48
  EXAMPLES = [
 
60
  if h[0]: messages.append({"role": "user", "content": h[0]})
61
  if h[1]: messages.append({"role": "assistant", "content": h[1]})
62
 
63
+ messages.append({"role": "user", "content": message})
64
+ # Prefill the assistant response to force it to start with <think>
65
+ messages.append({"role": "assistant", "content": "<think>\n## 1. Information Analysis\n"})
66
 
67
+ response = "<think>\n## 1. Information Analysis\n"
68
  try:
69
  stream = client.chat_completion(
70
  model=MODEL,
 
81
  response += delta.content
82
  yield response
83
  except Exception as e:
84
+ if not response or response == "<think>\n## 1. Information Analysis\n":
85
  yield f"⚠️ Error: {str(e)}"
86
  else:
87
  yield response