Spaces:
Running
Running
File size: 752 Bytes
7d9087b e50c54a 7d9087b e50c54a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import os
import re
import time
def get_file_size(file):
file.seek(0, os.SEEK_END)
size = file.tell()
file.seek(0)
return size
def extract_thoughts(response_text):
"""Extracts <think>...</think> content and the main answer."""
match = re.search(r"<think>(.*?)</think>", response_text, re.DOTALL)
if match:
thinking_part = match.group(1).strip()
main_answer = re.sub(r"<think>.*?</think>", "", response_text, flags=re.DOTALL).strip()
else:
thinking_part = None
main_answer = response_text.strip()
return thinking_part, main_answer
# Streamed response emulator
def response_generator(response):
for word in response.split():
yield word + " "
time.sleep(0.05) |