cafe3310 commited on
Commit
fdbc2bf
·
1 Parent(s): 7fa4e63

refactor: Optimize thinking token display using Markdown

Browse files
Files changed (2) hide show
  1. GEMINI.md +2 -1
  2. app.py +10 -4
GEMINI.md CHANGED
@@ -30,10 +30,11 @@
30
 
31
  # Todolist
32
  ## 未完成
33
- - [ ] (进行中) 为“思考”和“正文” token 实现不同的颜色显示。
34
  - [ ] (已暂停) 搜索 `huggingface_hub` 文档,确认是否存在用于重启 Space 的 API。
35
 
36
  ## 已完成
 
37
  - [x] 实现调试模式以观察“思考”和“正文” token 的区别。
38
  - [x] 修改 `app.py`,移除 `Ling-flash-2.0` 模型,只保留 `Ring-mini-2.0`。
39
  - [x] **(用户决策)** 确认 `Ling-flash-2.0` 模型过大,暂时移除,仅使用 `Ring-mini-2.0`。
 
30
 
31
  # Todolist
32
  ## 未完成
33
+ - [ ] (进行中) 使用 Markdown 优化思考过程的显示效果。
34
  - [ ] (已暂停) 搜索 `huggingface_hub` 文档,确认是否存在用于重启 Space 的 API。
35
 
36
  ## 已完成
37
+ - [x] 为“思考”和“正文” token 实现不同的颜色显示。
38
  - [x] 实现调试模式以观察“思考”和“正文” token 的区别。
39
  - [x] 修改 `app.py`,移除 `Ling-flash-2.0` 模型,只保留 `Ring-mini-2.0`。
40
  - [x] **(用户决策)** 确认 `Ling-flash-2.0` 模型过大,暂时移除,仅使用 `Ring-mini-2.0`。
app.py CHANGED
@@ -3,7 +3,7 @@ from comp import generate_response
3
 
4
  # --- Gradio UI ---
5
 
6
- with gr.Blocks(css=".thinking { color: gray; font-style: italic; }") as demo:
7
  gr.Markdown("# Ling Playground")
8
  chatbot = gr.Chatbot()
9
  msg = gr.Textbox()
@@ -16,9 +16,15 @@ with gr.Blocks(css=".thinking { color: gray; font-style: italic; }") as demo:
16
  user_message = history[-1][0]
17
  history[-1][1] = ""
18
  for response in generate_response(user_message, history[:-1]):
19
- html_response = response.replace("<think>", "<div class='thinking'>")
20
- html_response = html_response.replace("</think>", "</div>")
21
- history[-1][1] = html_response
 
 
 
 
 
 
22
  yield history
23
 
24
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
 
3
 
4
  # --- Gradio UI ---
5
 
6
+ with gr.Blocks() as demo:
7
  gr.Markdown("# Ling Playground")
8
  chatbot = gr.Chatbot()
9
  msg = gr.Textbox()
 
16
  user_message = history[-1][0]
17
  history[-1][1] = ""
18
  for response in generate_response(user_message, history[:-1]):
19
+ if "</think>" in response:
20
+ parts = response.split("</think>", 1)
21
+ thinking_text = parts[0].replace("<think>", "")
22
+ body_text = parts[1]
23
+
24
+ md_output = f"**Thinking...**\n```\n{thinking_text}\n```\n\n{body_text}"
25
+ history[-1][1] = md_output
26
+ else:
27
+ history[-1][1] = response
28
  yield history
29
 
30
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(