Spaces:
Running
Running
feat(chat): always display model reasoning
Browse files- [remove] Remove `show_reasoning` parameter from `handle_chat_submit` and `handle_chat_retry` (chat_handler.py:168,275)
- [feat] Hardcode `render_with_reasoning_toggle` to `True` in `handle_chat_submit` and `handle_chat_retry` (chat_handler.py:203,275)
- [remove] Remove `show_reasoning` checkbox and its usage in chat event handlers (ui_components.py:52-57,87-88,102-103,124-125)
- chat_handler.py +4 -4
- ui_components.py +3 -8
chat_handler.py
CHANGED
|
@@ -168,7 +168,7 @@ def chat_respond(
|
|
| 168 |
yield format_error_message("Unexpected Error", f"An unexpected error occurred: {error_msg}")
|
| 169 |
|
| 170 |
|
| 171 |
-
def handle_chat_submit(message, history, system_msg, model_name, max_tokens, temperature, top_p,
|
| 172 |
"""
|
| 173 |
Handle chat submission and manage conversation history with streaming.
|
| 174 |
"""
|
|
@@ -203,13 +203,13 @@ def handle_chat_submit(message, history, system_msg, model_name, max_tokens, tem
|
|
| 203 |
# Stream the assistant response token by token
|
| 204 |
assistant_response = ""
|
| 205 |
for partial_response in response_generator:
|
| 206 |
-
assistant_response = render_with_reasoning_toggle(partial_response,
|
| 207 |
# Update history with the current partial response and yield it
|
| 208 |
current_history = history + [{"role": "assistant", "content": assistant_response}]
|
| 209 |
yield current_history, ""
|
| 210 |
|
| 211 |
|
| 212 |
-
def handle_chat_retry(history, system_msg, model_name, max_tokens, temperature, top_p,
|
| 213 |
"""
|
| 214 |
Retry the assistant response for the selected message.
|
| 215 |
Works with gr.Chatbot.retry() which provides retry_data.index for the message.
|
|
@@ -275,6 +275,6 @@ def handle_chat_retry(history, system_msg, model_name, max_tokens, temperature,
|
|
| 275 |
|
| 276 |
assistant_response = ""
|
| 277 |
for partial_response in response_generator:
|
| 278 |
-
assistant_response = render_with_reasoning_toggle(partial_response,
|
| 279 |
current_history = trimmed_history + [{"role": "assistant", "content": assistant_response}]
|
| 280 |
yield current_history
|
|
|
|
| 168 |
yield format_error_message("Unexpected Error", f"An unexpected error occurred: {error_msg}")
|
| 169 |
|
| 170 |
|
| 171 |
+
def handle_chat_submit(message, history, system_msg, model_name, max_tokens, temperature, top_p, hf_token: gr.OAuthToken = None):
|
| 172 |
"""
|
| 173 |
Handle chat submission and manage conversation history with streaming.
|
| 174 |
"""
|
|
|
|
| 203 |
# Stream the assistant response token by token
|
| 204 |
assistant_response = ""
|
| 205 |
for partial_response in response_generator:
|
| 206 |
+
assistant_response = render_with_reasoning_toggle(partial_response, True)
|
| 207 |
# Update history with the current partial response and yield it
|
| 208 |
current_history = history + [{"role": "assistant", "content": assistant_response}]
|
| 209 |
yield current_history, ""
|
| 210 |
|
| 211 |
|
| 212 |
+
def handle_chat_retry(history, system_msg, model_name, max_tokens, temperature, top_p, hf_token: gr.OAuthToken = None, retry_data=None):
|
| 213 |
"""
|
| 214 |
Retry the assistant response for the selected message.
|
| 215 |
Works with gr.Chatbot.retry() which provides retry_data.index for the message.
|
|
|
|
| 275 |
|
| 276 |
assistant_response = ""
|
| 277 |
for partial_response in response_generator:
|
| 278 |
+
assistant_response = render_with_reasoning_toggle(partial_response, True)
|
| 279 |
current_history = trimmed_history + [{"role": "assistant", "content": assistant_response}]
|
| 280 |
yield current_history
|
ui_components.py
CHANGED
|
@@ -52,11 +52,6 @@ def create_chat_tab(handle_chat_submit_fn, handle_chat_retry_fn=None):
|
|
| 52 |
lines=2,
|
| 53 |
placeholder="Define the assistant's personality and behavior..."
|
| 54 |
)
|
| 55 |
-
show_reasoning = gr.Checkbox(
|
| 56 |
-
value=False,
|
| 57 |
-
label="Show reasoning (<think>…</think>)",
|
| 58 |
-
info="Reveal model's reasoning, if present",
|
| 59 |
-
)
|
| 60 |
|
| 61 |
with gr.Column(scale=1):
|
| 62 |
chat_max_tokens = gr.Slider(
|
|
@@ -87,7 +82,7 @@ def create_chat_tab(handle_chat_submit_fn, handle_chat_retry_fn=None):
|
|
| 87 |
chat_send_event = chat_submit.click(
|
| 88 |
fn=handle_chat_submit_fn,
|
| 89 |
inputs=[chat_input, chatbot_display, chat_system_message, chat_model_name,
|
| 90 |
-
chat_max_tokens, chat_temperature, chat_top_p
|
| 91 |
outputs=[chatbot_display, chat_input]
|
| 92 |
)
|
| 93 |
|
|
@@ -102,7 +97,7 @@ def create_chat_tab(handle_chat_submit_fn, handle_chat_retry_fn=None):
|
|
| 102 |
chat_enter_event = chat_input.submit(
|
| 103 |
fn=handle_chat_submit_fn,
|
| 104 |
inputs=[chat_input, chatbot_display, chat_system_message, chat_model_name,
|
| 105 |
-
chat_max_tokens, chat_temperature, chat_top_p
|
| 106 |
outputs=[chatbot_display, chat_input]
|
| 107 |
)
|
| 108 |
|
|
@@ -124,7 +119,7 @@ def create_chat_tab(handle_chat_submit_fn, handle_chat_retry_fn=None):
|
|
| 124 |
chatbot_display.retry(
|
| 125 |
fn=handle_chat_retry_fn,
|
| 126 |
inputs=[chatbot_display, chat_system_message, chat_model_name,
|
| 127 |
-
chat_max_tokens, chat_temperature, chat_top_p
|
| 128 |
outputs=chatbot_display
|
| 129 |
)
|
| 130 |
|
|
|
|
| 52 |
lines=2,
|
| 53 |
placeholder="Define the assistant's personality and behavior..."
|
| 54 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
with gr.Column(scale=1):
|
| 57 |
chat_max_tokens = gr.Slider(
|
|
|
|
| 82 |
chat_send_event = chat_submit.click(
|
| 83 |
fn=handle_chat_submit_fn,
|
| 84 |
inputs=[chat_input, chatbot_display, chat_system_message, chat_model_name,
|
| 85 |
+
chat_max_tokens, chat_temperature, chat_top_p],
|
| 86 |
outputs=[chatbot_display, chat_input]
|
| 87 |
)
|
| 88 |
|
|
|
|
| 97 |
chat_enter_event = chat_input.submit(
|
| 98 |
fn=handle_chat_submit_fn,
|
| 99 |
inputs=[chat_input, chatbot_display, chat_system_message, chat_model_name,
|
| 100 |
+
chat_max_tokens, chat_temperature, chat_top_p],
|
| 101 |
outputs=[chatbot_display, chat_input]
|
| 102 |
)
|
| 103 |
|
|
|
|
| 119 |
chatbot_display.retry(
|
| 120 |
fn=handle_chat_retry_fn,
|
| 121 |
inputs=[chatbot_display, chat_system_message, chat_model_name,
|
| 122 |
+
chat_max_tokens, chat_temperature, chat_top_p],
|
| 123 |
outputs=chatbot_display
|
| 124 |
)
|
| 125 |
|