Collapsible thinking box with details/summary, thinking on by default
- Thinking box uses <details>/<summary> — collapsed by default, expands on click - Simple __status header shown before content arrives (no expand needed) - show_thinking checkbox default changed to True Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -118,8 +118,9 @@ async def respond(message, history, show_thinking, user_id, use_tts, run_ids):
|
||||
|
||||
# 즉시 상태 표시 — thinking_acc에 누적하지 않음 (임시 메시지)
|
||||
if isinstance(token, dict) and "__status" in token:
|
||||
status_text = (thinking_acc + "\n\n" + token["__status"]) if thinking_acc else token["__status"]
|
||||
yield history, "", None, run_ids, _thinking_html(status_text)
|
||||
if not thinking_acc:
|
||||
yield history, "", None, run_ids, _status_html(token["__status"])
|
||||
# thinking_acc에 내용 있으면 기존 표시 유지
|
||||
continue
|
||||
|
||||
# 사고 과정(LLM thinking) — 박스에 추가
|
||||
@@ -228,21 +229,35 @@ def delete_doc(source):
|
||||
|
||||
# ── UI 구성 ──────────────────────────────────────────────────────
|
||||
|
||||
_THINKING_STYLE = (
|
||||
_BOX_STYLE = (
|
||||
"background:#f9f9f9;border-left:3px solid #bbb;border-radius:6px;"
|
||||
"padding:10px 14px;max-height:220px;overflow-y:auto;"
|
||||
"font-size:0.85em;color:#555;white-space:pre-wrap;margin-bottom:6px;"
|
||||
"padding:8px 14px;margin-bottom:6px;"
|
||||
)
|
||||
_CONTENT_STYLE = (
|
||||
"margin-top:8px;white-space:pre-wrap;font-size:0.85em;"
|
||||
"color:#555;max-height:200px;overflow-y:auto;"
|
||||
)
|
||||
|
||||
|
||||
def _thinking_html(text: str, done: bool = False) -> str:
|
||||
"""접기/펼치기 가능한 사고 과정 박스."""
|
||||
icon = "💭" if done else "🤔"
|
||||
label = "분석 완료" if done else "분석 중..."
|
||||
cursor = "" if done else " ▌"
|
||||
return (
|
||||
f'<div style="{_THINKING_STYLE}">'
|
||||
f"<strong>{icon} {label}</strong><br><br>"
|
||||
f"{_html.escape(text)}{cursor}</div>"
|
||||
f'<details style="{_BOX_STYLE}">'
|
||||
f'<summary style="cursor:pointer;font-weight:bold;">{icon} {label}</summary>'
|
||||
f'<div style="{_CONTENT_STYLE}">{_html.escape(text)}{cursor}</div>'
|
||||
f'</details>'
|
||||
)
|
||||
|
||||
|
||||
def _status_html(status: str) -> str:
|
||||
"""내용 없이 상태만 표시하는 단순 헤더."""
|
||||
return (
|
||||
f'<div style="{_BOX_STYLE}">'
|
||||
f'<strong>🤔 {_html.escape(status)}</strong>'
|
||||
f'</div>'
|
||||
)
|
||||
|
||||
|
||||
@@ -282,7 +297,7 @@ with gr.Blocks(title="율봇") as demo:
|
||||
transcribe_btn = gr.Button("음성 → 텍스트 변환", scale=1)
|
||||
|
||||
with gr.Row():
|
||||
show_thinking = gr.Checkbox(label="사고 과정 표시", value=False)
|
||||
show_thinking = gr.Checkbox(label="사고 과정 표시", value=True)
|
||||
use_tts = gr.Checkbox(label="음성으로 답변 읽기 (TTS)", value=False)
|
||||
reset_btn = gr.Button("대화 초기화", size="sm")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user