Spaces:
Running
Running
ai: Do not clear history if user ON/OFF deep search.
Browse files
jarvis.py
CHANGED
@@ -508,14 +508,22 @@ async def respond_async(multi, history, model_display, sess, custom_prompt, deep
|
|
508 |
await asyncio.gather(*pending_tasks, return_exceptions=True)
|
509 |
yield history, gr.update(value="", interactive=True, submit_btn=True, stop_btn=False), sess
|
510 |
|
|
|
|
|
|
|
|
|
|
|
|
|
511 |
def change_model(new):
|
512 |
"""
|
513 |
Handler to change selected AI model.
|
514 |
Resets chat history and session.
|
515 |
Updates system instructions and deep search checkbox visibility accordingly.
|
|
|
516 |
"""
|
517 |
visible = new == MODEL_CHOICES[0]
|
518 |
default_prompt = SYSTEM_PROMPT_MAPPING.get(get_model_key(new), SYSTEM_PROMPT_DEFAULT)
|
|
|
519 |
return [], create_session(), new, default_prompt, False, gr.update(visible=visible)
|
520 |
|
521 |
def stop_response(history, sess):
|
@@ -543,6 +551,7 @@ with gr.Blocks(fill_height=True, fill_width=True, title=AI_TYPES["AI_TYPE_4"], h
|
|
543 |
chatbot = gr.Chatbot(label=AI_TYPES["AI_TYPE_1"], show_copy_button=True, scale=1, elem_id=AI_TYPES["AI_TYPE_2"], examples=JARVIS_INIT)
|
544 |
# Deep search
|
545 |
deep_search = gr.Checkbox(label=AI_TYPES["AI_TYPE_8"], value=False, info=AI_TYPES["AI_TYPE_9"], visible=True)
|
|
|
546 |
# User's input
|
547 |
msg = gr.MultimodalTextbox(show_label=False, placeholder=RESPONSES["RESPONSE_5"], interactive=True, file_count="single", file_types=ALLOWED_EXTENSIONS)
|
548 |
# Sidebar to select AI models
|
@@ -553,9 +562,8 @@ with gr.Blocks(fill_height=True, fill_width=True, title=AI_TYPES["AI_TYPE_4"], h
|
|
553 |
def on_example_select(evt: gr.SelectData): return evt.value
|
554 |
chatbot.example_select(fn=on_example_select, inputs=[], outputs=[msg]).then(fn=respond_async, inputs=[msg, user_history, selected_model, user_session, J_A_R_V_I_S, deep_search], outputs=[chatbot, msg, user_session])
|
555 |
# Clear chat
|
556 |
-
def clear_chat(history, sess, prompt, model): return [], create_session(), prompt, model
|
557 |
-
|
558 |
-
chatbot.clear(fn=clear_chat, inputs=[user_history, user_session, J_A_R_V_I_S, selected_model], outputs=[chatbot, user_session, J_A_R_V_I_S, selected_model, user_history])
|
559 |
# Submit message
|
560 |
msg.submit(fn=respond_async, inputs=[msg, user_history, selected_model, user_session, J_A_R_V_I_S, deep_search], outputs=[chatbot, msg, user_session], api_name=INTERNAL_AI_GET_SERVER)
|
561 |
# Stop message
|
|
|
508 |
await asyncio.gather(*pending_tasks, return_exceptions=True)
|
509 |
yield history, gr.update(value="", interactive=True, submit_btn=True, stop_btn=False), sess
|
510 |
|
511 |
+
def toggle_deep_search(deep_search_value, history, sess, prompt, model):
|
512 |
+
"""
|
513 |
+
Toggle deep search checkbox. Keeps chat intact for production compatibility.
|
514 |
+
"""
|
515 |
+
return history, sess, prompt, model, gr.update(value=deep_search_value)
|
516 |
+
|
517 |
def change_model(new):
|
518 |
"""
|
519 |
Handler to change selected AI model.
|
520 |
Resets chat history and session.
|
521 |
Updates system instructions and deep search checkbox visibility accordingly.
|
522 |
+
Deep search is only available for default model.
|
523 |
"""
|
524 |
visible = new == MODEL_CHOICES[0]
|
525 |
default_prompt = SYSTEM_PROMPT_MAPPING.get(get_model_key(new), SYSTEM_PROMPT_DEFAULT)
|
526 |
+
# On model change, clear chat, create new session, reset deep search, update visibility
|
527 |
return [], create_session(), new, default_prompt, False, gr.update(visible=visible)
|
528 |
|
529 |
def stop_response(history, sess):
|
|
|
551 |
chatbot = gr.Chatbot(label=AI_TYPES["AI_TYPE_1"], show_copy_button=True, scale=1, elem_id=AI_TYPES["AI_TYPE_2"], examples=JARVIS_INIT)
|
552 |
# Deep search
|
553 |
deep_search = gr.Checkbox(label=AI_TYPES["AI_TYPE_8"], value=False, info=AI_TYPES["AI_TYPE_9"], visible=True)
|
554 |
+
deep_search.change(fn=toggle_deep_search, inputs=[deep_search, user_history, user_session, J_A_R_V_I_S, selected_model], outputs=[chatbot, user_session, J_A_R_V_I_S, selected_model, deep_search])
|
555 |
# User's input
|
556 |
msg = gr.MultimodalTextbox(show_label=False, placeholder=RESPONSES["RESPONSE_5"], interactive=True, file_count="single", file_types=ALLOWED_EXTENSIONS)
|
557 |
# Sidebar to select AI models
|
|
|
562 |
def on_example_select(evt: gr.SelectData): return evt.value
|
563 |
chatbot.example_select(fn=on_example_select, inputs=[], outputs=[msg]).then(fn=respond_async, inputs=[msg, user_history, selected_model, user_session, J_A_R_V_I_S, deep_search], outputs=[chatbot, msg, user_session])
|
564 |
# Clear chat
|
565 |
+
def clear_chat(history, sess, prompt, model): return [], create_session(), prompt, model
|
566 |
+
chatbot.clear(fn=clear_chat, inputs=[user_history, user_session, J_A_R_V_I_S, selected_model], outputs=[chatbot, user_session, J_A_R_V_I_S, selected_model])
|
|
|
567 |
# Submit message
|
568 |
msg.submit(fn=respond_async, inputs=[msg, user_history, selected_model, user_session, J_A_R_V_I_S, deep_search], outputs=[chatbot, msg, user_session], api_name=INTERNAL_AI_GET_SERVER)
|
569 |
# Stop message
|