Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -42,7 +42,7 @@ async def respond_thinking(message, history, selected_model):
|
|
42 |
yield {"role": "assistant", "content": "Error: Selected model not available."}, ""
|
43 |
return
|
44 |
|
45 |
-
yield {"role": "assistant", "content": "Думаю..."}
|
46 |
|
47 |
try:
|
48 |
response = model.generate_content(message)
|
@@ -56,14 +56,14 @@ async def respond_thinking(message, history, selected_model):
|
|
56 |
else:
|
57 |
model_response_text += (part.text or "")
|
58 |
|
59 |
-
|
60 |
except Exception as e:
|
61 |
-
|
62 |
|
63 |
async def process_message(message, history, model_name):
|
64 |
if "thinking" in model_name:
|
65 |
-
response, thinking
|
66 |
-
|
67 |
else:
|
68 |
async for response in respond(message, history, model_name):
|
69 |
yield response, ""
|
@@ -98,7 +98,7 @@ with gr.Blocks() as demo:
|
|
98 |
async def update_thinking_output(history):
|
99 |
if history:
|
100 |
last_turn = history[-1]
|
101 |
-
if last_turn
|
102 |
return last_turn[1]
|
103 |
return ""
|
104 |
|
@@ -108,7 +108,7 @@ with gr.Blocks() as demo:
|
|
108 |
outputs=[chatbot],
|
109 |
)
|
110 |
|
111 |
-
chatbot.
|
112 |
update_thinking_output,
|
113 |
inputs=[chatbot],
|
114 |
outputs=[thinking_output]
|
|
|
42 |
yield {"role": "assistant", "content": "Error: Selected model not available."}, ""
|
43 |
return
|
44 |
|
45 |
+
yield {"role": "assistant", "content": "Думаю..."}
|
46 |
|
47 |
try:
|
48 |
response = model.generate_content(message)
|
|
|
56 |
else:
|
57 |
model_response_text += (part.text or "")
|
58 |
|
59 |
+
yield {"role": "assistant", "content": model_response_text}, thinking_process_text
|
60 |
except Exception as e:
|
61 |
+
yield {"role": "assistant", "content": f"Error during API call: {e}"}, f"Error during API call: {e}"
|
62 |
|
63 |
async def process_message(message, history, model_name):
|
64 |
if "thinking" in model_name:
|
65 |
+
async for response, thinking in respond_thinking(message, history, model_name):
|
66 |
+
yield response, thinking
|
67 |
else:
|
68 |
async for response in respond(message, history, model_name):
|
69 |
yield response, ""
|
|
|
98 |
async def update_thinking_output(history):
|
99 |
if history:
|
100 |
last_turn = history[-1]
|
101 |
+
if len(last_turn) > 1:
|
102 |
return last_turn[1]
|
103 |
return ""
|
104 |
|
|
|
108 |
outputs=[chatbot],
|
109 |
)
|
110 |
|
111 |
+
chatbot.on_change(
|
112 |
update_thinking_output,
|
113 |
inputs=[chatbot],
|
114 |
outputs=[thinking_output]
|