show thinking for gpt-5 with poe
Browse files733 unmodified lines7347357367377387391826 unmodified lines256625672568256925702571733 unmodified lines# Matches lines like: "Thinking..." or "Thinking... (12s elapsed)"return re.sub(r"(?mi)^[\t ]*Thinking\.\.\.(?:\s*\(\d+s elapsed\))?[\t ]*$\n?", "", text)def parse_transformers_js_output(text):"""Parse transformers.js output and extract the three files (index.html, index.js, style.css)"""files = {1826 unmodified linesif chunk_content:if _current_model["id"] == "gpt-5":# Filter placeholdersincoming = strip_placeholder_thinking(chunk_content)# Process code fences incrementally, only keep content inside fences733 unmodified lines7347357367377387397407417427437447457467477487497507517527531826 unmodified lines258025812582258325842585258625872588258925902591259225932594733 unmodified lines# Matches lines like: "Thinking..." or "Thinking... (12s elapsed)"return re.sub(r"(?mi)^[\t ]*Thinking\.\.\.(?:\s*\(\d+s elapsed\))?[\t ]*$\n?", "", text)def is_placeholder_thinking_only(text: str) -> bool:"""Return True if text contains only 'Thinking...' placeholder lines (with optional elapsed)."""if not text:return Falsestripped = text.strip()if not stripped:return Falsereturn re.fullmatch(r"(?s)(?:\s*Thinking\.\.\.(?:\s*\(\d+s elapsed\))?\s*)+", stripped) is not Nonedef extract_last_thinking_line(text: str) -> str:"""Extract the last 'Thinking...' line to display as status."""matches = list(re.finditer(r"Thinking\.\.\.(?:\s*\(\d+s elapsed\))?", text))return matches[-1].group(0) if matches else "Thinking..."def parse_transformers_js_output(text):"""Parse transformers.js output and extract the three files (index.html, index.js, style.css)"""files = {1826 unmodified linesif chunk_content:if _current_model["id"] == "gpt-5":# If this chunk is only placeholder thinking, surface a status update without polluting contentif is_placeholder_thinking_only(chunk_content):status_line = extract_last_thinking_line(chunk_content)yield {code_output: gr.update(value=(content or "") + "\n<!-- " + status_line + " -->", language="html"),history_output: history_to_chatbot_messages(_history),sandbox: "<div style='padding:1em;color:#888;text-align:center;'>" + status_line + "</div>",}continue# Filter placeholdersincoming = strip_placeholder_thinking(chunk_content)# Process code fences incrementally, only keep content inside fences
app.py+23