moazx commited on
Commit
757414a
·
1 Parent(s): 5021fcb

Fixed assess response

Browse files
Files changed (1) hide show
  1. core/hbv_assessment.py +24 -1
core/hbv_assessment.py CHANGED
@@ -71,6 +71,28 @@ def clean_json_string(json_str: str) -> str:
71
  return ''.join(result)
72
 
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  # SASLT 2021 Guidelines - Hardcoded Page Contents
75
  SASLT_GUIDELINES = """
76
  ===== TREATMENT RECOMMENDATIONS =====
@@ -351,9 +373,10 @@ IMPORTANT:
351
  raise ValueError("No JSON found in response")
352
 
353
  # Validate and return result
 
354
  assessment_result = {
355
  "eligible": result.get("eligible", False),
356
- "recommendations": result.get("recommendations", "")
357
  }
358
 
359
  # Log final assessment
 
71
  return ''.join(result)
72
 
73
 
74
+ def normalize_recommendations(text: str) -> str:
75
+ """
76
+ Normalize the recommendations string for concise, consistent formatting.
77
+ - Remove extra blank lines
78
+ - Trim trailing/leading whitespace on each line
79
+ - Ensure single "\n" between lines
80
+ - Optionally cap length to avoid overly long outputs
81
+ """
82
+ if not text:
83
+ return ""
84
+ # Normalize newlines
85
+ text = text.replace('\r\n', '\n').replace('\r', '\n')
86
+ # Split, strip, and drop empty lines
87
+ lines = [ln.strip() for ln in text.split('\n')]
88
+ lines = [ln for ln in lines if ln]
89
+ normalized = '\n'.join(lines)
90
+ # Soft cap length (keep whole content if already short)
91
+ max_len = 1800
92
+ if len(normalized) > max_len:
93
+ normalized = normalized[:max_len].rstrip()
94
+ return normalized
95
+
96
  # SASLT 2021 Guidelines - Hardcoded Page Contents
97
  SASLT_GUIDELINES = """
98
  ===== TREATMENT RECOMMENDATIONS =====
 
373
  raise ValueError("No JSON found in response")
374
 
375
  # Validate and return result
376
+ normalized_recs = normalize_recommendations(result.get("recommendations", ""))
377
  assessment_result = {
378
  "eligible": result.get("eligible", False),
379
+ "recommendations": normalized_recs
380
  }
381
 
382
  # Log final assessment