Spaces:
Running
Running
show thinking for gpt-5 with poe
Browse files
app.py
CHANGED
@@ -734,6 +734,20 @@ def strip_placeholder_thinking(text: str) -> str:
|
|
734 |
# Matches lines like: "Thinking..." or "Thinking... (12s elapsed)"
|
735 |
return re.sub(r"(?mi)^[\t ]*Thinking\.\.\.(?:\s*\(\d+s elapsed\))?[\t ]*$\n?", "", text)
|
736 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
737 |
def parse_transformers_js_output(text):
|
738 |
"""Parse transformers.js output and extract the three files (index.html, index.js, style.css)"""
|
739 |
files = {
|
@@ -2566,6 +2580,15 @@ This will help me create a better design for you."""
|
|
2566 |
|
2567 |
if chunk_content:
|
2568 |
if _current_model["id"] == "gpt-5":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2569 |
# Filter placeholders
|
2570 |
incoming = strip_placeholder_thinking(chunk_content)
|
2571 |
# Process code fences incrementally, only keep content inside fences
|
|
|
734 |
# Matches lines like: "Thinking..." or "Thinking... (12s elapsed)"
|
735 |
return re.sub(r"(?mi)^[\t ]*Thinking\.\.\.(?:\s*\(\d+s elapsed\))?[\t ]*$\n?", "", text)
|
736 |
|
737 |
+
def is_placeholder_thinking_only(text: str) -> bool:
|
738 |
+
"""Return True if text contains only 'Thinking...' placeholder lines (with optional elapsed)."""
|
739 |
+
if not text:
|
740 |
+
return False
|
741 |
+
stripped = text.strip()
|
742 |
+
if not stripped:
|
743 |
+
return False
|
744 |
+
return re.fullmatch(r"(?s)(?:\s*Thinking\.\.\.(?:\s*\(\d+s elapsed\))?\s*)+", stripped) is not None
|
745 |
+
|
746 |
+
def extract_last_thinking_line(text: str) -> str:
|
747 |
+
"""Extract the last 'Thinking...' line to display as status."""
|
748 |
+
matches = list(re.finditer(r"Thinking\.\.\.(?:\s*\(\d+s elapsed\))?", text))
|
749 |
+
return matches[-1].group(0) if matches else "Thinking..."
|
750 |
+
|
751 |
def parse_transformers_js_output(text):
|
752 |
"""Parse transformers.js output and extract the three files (index.html, index.js, style.css)"""
|
753 |
files = {
|
|
|
2580 |
|
2581 |
if chunk_content:
|
2582 |
if _current_model["id"] == "gpt-5":
|
2583 |
+
# If this chunk is only placeholder thinking, surface a status update without polluting content
|
2584 |
+
if is_placeholder_thinking_only(chunk_content):
|
2585 |
+
status_line = extract_last_thinking_line(chunk_content)
|
2586 |
+
yield {
|
2587 |
+
code_output: gr.update(value=(content or "") + "\n<!-- " + status_line + " -->", language="html"),
|
2588 |
+
history_output: history_to_chatbot_messages(_history),
|
2589 |
+
sandbox: "<div style='padding:1em;color:#888;text-align:center;'>" + status_line + "</div>",
|
2590 |
+
}
|
2591 |
+
continue
|
2592 |
# Filter placeholders
|
2593 |
incoming = strip_placeholder_thinking(chunk_content)
|
2594 |
# Process code fences incrementally, only keep content inside fences
|