Luigi commited on
Commit
b27d02e
·
1 Parent(s): 6122a55

Add missing parse_thinking_blocks function

Browse files

Function was referenced in summarize_streaming but never defined in app.py.
Copied from summarize_transcript.py.

Files changed (1) hide show
  1. app.py +20 -9
app.py CHANGED
@@ -56,15 +56,26 @@ def load_model():
56
  raise
57
 
58
 
59
- def clean_thinking_tags(content: str) -> str:
60
- """Remove thinking tags and return clean summary text."""
61
- # Remove thinking blocks
62
- content = re.sub(r'<thinking>.*?</thinking>', '', content, flags=re.DOTALL)
63
- # Remove reasoning blocks if present
64
- content = re.sub(r'<reasoning>.*?</reasoning>', '', content, flags=re.DOTALL)
65
- # Clean up extra whitespace
66
- content = re.sub(r'\n{3,}', '\n\n', content)
67
- return content.strip()
 
 
 
 
 
 
 
 
 
 
 
68
 
69
 
70
  def summarize_streaming(file_obj, max_tokens: int = 512, temperature: float = 0.6) -> Generator[str, None, None]:
 
56
  raise
57
 
58
 
59
+ def parse_thinking_blocks(content: str) -> Tuple[str, str]:
60
+ """
61
+ Parse thinking blocks from model output.
62
+
63
+ Args:
64
+ content: Full model response
65
+
66
+ Returns:
67
+ Tuple of (thinking_content, summary_content)
68
+ """
69
+ pattern = r'<thinking>(.*?)</thinking>'
70
+ matches = re.findall(pattern, content, re.DOTALL)
71
+
72
+ if not matches:
73
+ return ("", content)
74
+
75
+ thinking = '\n\n'.join(match.strip() for match in matches)
76
+ summary = re.sub(pattern, '', content, flags=re.DOTALL).strip()
77
+
78
+ return (thinking, summary)
79
 
80
 
81
  def summarize_streaming(file_obj, max_tokens: int = 512, temperature: float = 0.6) -> Generator[str, None, None]: