Files changed (1) hide show
  1. handler.py +20 -0
handler.py CHANGED
@@ -96,6 +96,13 @@ image_processor = None
96
  context_len = None
97
  args = None
98
 
 
 
 
 
 
 
 
99
  def get_conv_log_filename():
100
  t = datetime.datetime.now()
101
  name = os.path.join(LOGDIR, f"{t.year}-{t.month:02d}-{t.day:02d}-user_conv.json")
@@ -557,6 +564,19 @@ def query(payload):
557
  payload.get("prompt") or
558
  payload.get("istem") or "")
559
 
 
 
 
 
 
 
 
 
 
 
 
 
 
560
  # Extract image with multiple possible keys
561
  image_input = (payload.get("image") or
562
  payload.get("image_url") or
 
96
  context_len = None
97
  args = None
98
 
99
+ # Configuration for consistent responses
100
+ PROMPT_NORMALIZATION = True # Set to False to disable prompt normalization
101
+ DEFAULT_ECG_PROMPT = "What are the main features and diagnosis in this ECG image? Provide a comprehensive clinical analysis"
102
+
103
+ # Note: When PROMPT_NORMALIZATION is True, all ECG diagnosis requests will be
104
+ # standardized to ensure consistent response lengths and content across different clients.
105
+
106
  def get_conv_log_filename():
107
  t = datetime.datetime.now()
108
  name = os.path.join(LOGDIR, f"{t.year}-{t.month:02d}-{t.day:02d}-user_conv.json")
 
564
  payload.get("prompt") or
565
  payload.get("istem") or "")
566
 
567
+ # Normalize prompt to ensure consistent responses
568
+ # This helps maintain consistency across different clients
569
+ if PROMPT_NORMALIZATION and "ecg" in message_text.lower() and "diagnosis" in message_text.lower():
570
+ # Standardize ECG analysis prompts for consistency
571
+ if "comprehensive" in message_text.lower():
572
+ message_text = DEFAULT_ECG_PROMPT
573
+ elif "concise" in message_text.lower():
574
+ message_text = "What are the main features and diagnosis in this ECG image? Provide a concise, clinical answer."
575
+ else:
576
+ # Default to comprehensive analysis for consistency
577
+ message_text = DEFAULT_ECG_PROMPT
578
+ print(f"[DEBUG] Normalized prompt to: {message_text}")
579
+
580
  # Extract image with multiple possible keys
581
  image_input = (payload.get("image") or
582
  payload.get("image_url") or