Show thinking as single self-overwriting line with timer

parent 7e0e358b
...@@ -453,7 +453,6 @@ class CoderClient: ...@@ -453,7 +453,6 @@ class CoderClient:
in_thinking = False in_thinking = False
thinking_content = "" thinking_content = ""
thinking_start_time = 0 thinking_start_time = 0
last_timer_update = 0
# Use iter_content with smaller chunk size for better real-time handling # Use iter_content with smaller chunk size for better real-time handling
buffer = "" buffer = ""
...@@ -486,39 +485,38 @@ class CoderClient: ...@@ -486,39 +485,38 @@ class CoderClient:
if '<think>' in content: if '<think>' in content:
in_thinking = True in_thinking = True
thinking_start_time = time.time() thinking_start_time = time.time()
last_timer_update = thinking_start_time
print("<think> ", end='', flush=True)
continue continue
if in_thinking: if in_thinking:
current_time = time.time() current_time = time.time()
# Update timer display every second
if current_time - last_timer_update >= 1.0:
elapsed = int(current_time - thinking_start_time)
print(f"[{elapsed}s]", end=' ', flush=True)
last_timer_update = current_time
if '</think>' in content: if '</think>' in content:
# End of thinking # End of thinking
in_thinking = False in_thinking = False
# Show final timer # Show final thinking line
elapsed = int(current_time - thinking_start_time) elapsed = int(current_time - thinking_start_time)
print(f"[{elapsed}s]", end=' ', flush=True)
# Show remaining thinking content and close tag
think_part = content.split('</think>')[0] think_part = content.split('</think>')[0]
if think_part: if think_part:
print(think_part, end='', flush=True)
thinking_content += think_part thinking_content += think_part
print("</think>\n", flush=True) # Clear line and show final thinking
display_text = thinking_content[-80:] # Last 80 chars
if len(thinking_content) > 80:
display_text = "..." + display_text
print(f"\r{Colors.DIM}[{elapsed}s] Thinking: [{display_text}]{Colors.RESET}", end='', flush=True)
print() # Newline after thinking
# Get content after </think> # Get content after </think>
actual_content = content.split('</think>', 1)[-1] actual_content = content.split('</think>', 1)[-1]
if actual_content: if actual_content:
print(actual_content, end='', flush=True) print(actual_content, end='', flush=True)
full_content += actual_content full_content += actual_content
else: else:
# Still thinking - show content as it arrives # Still thinking - accumulate and display
print(content, end='', flush=True)
thinking_content += content thinking_content += content
elapsed = int(current_time - thinking_start_time)
display_text = thinking_content[-80:] # Last 80 chars
if len(thinking_content) > 80:
display_text = "..." + display_text
print(f"\r{Colors.DIM}[{elapsed}s] Thinking: [{display_text}]{Colors.RESET}", end='', flush=True)
else: else:
# Normal content # Normal content
print(content, end='', flush=True) print(content, end='', flush=True)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment