Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1613,31 +1613,33 @@ def _chat_fragment():
|
|
| 1613 |
|
| 1614 |
|
| 1615 |
# =========================
|
| 1616 |
-
# 11. 搜索框下方的工具按钮
|
| 1617 |
# =========================
|
| 1618 |
-
|
| 1619 |
-
|
| 1620 |
-
|
| 1621 |
-
|
| 1622 |
-
|
| 1623 |
-
|
| 1624 |
-
_btn_cols = st.columns(2)
|
| 1625 |
-
with _btn_cols[0]:
|
| 1626 |
-
|
| 1627 |
-
|
| 1628 |
-
|
| 1629 |
-
|
| 1630 |
-
|
| 1631 |
-
|
| 1632 |
-
|
| 1633 |
-
|
| 1634 |
-
|
| 1635 |
-
|
| 1636 |
-
|
| 1637 |
-
|
| 1638 |
-
|
| 1639 |
-
|
| 1640 |
-
|
| 1641 |
-
|
|
|
|
|
|
|
| 1642 |
|
| 1643 |
_chat_fragment()
|
|
|
|
| 1613 |
|
| 1614 |
|
| 1615 |
# =========================
|
| 1616 |
+
# 11. 搜索框下方的工具按钮(使用 fragment 局部刷新)
|
| 1617 |
# =========================
|
| 1618 |
+
@st.fragment
|
| 1619 |
+
def _toolbar_fragment():
|
| 1620 |
+
_current_model = st.session_state.get("sel_model", list(model_mapping.keys())[0])
|
| 1621 |
+
_web_status = st.session_state.get("sel_web", True)
|
| 1622 |
+
_model_short = _current_model.split("(")[0].strip()
|
| 1623 |
+
|
| 1624 |
+
_btn_cols = st.columns(2)
|
| 1625 |
+
with _btn_cols[0]:
|
| 1626 |
+
with st.popover(_model_short, use_container_width=True):
|
| 1627 |
+
st.caption("选择模型")
|
| 1628 |
+
_model_list = list(_active_models.keys())
|
| 1629 |
+
for m in _model_list:
|
| 1630 |
+
_btn_type = "primary" if m == _current_model else "secondary"
|
| 1631 |
+
if st.button(m, key=f"mdl_{m}", use_container_width=True, type=_btn_type):
|
| 1632 |
+
if m != _current_model:
|
| 1633 |
+
st.session_state["sel_model"] = m
|
| 1634 |
+
|
| 1635 |
+
with _btn_cols[1]:
|
| 1636 |
+
if IS_GUEST:
|
| 1637 |
+
_web_label = "🌐 联网模式" if _web_status else "💬 直接回答"
|
| 1638 |
+
else:
|
| 1639 |
+
_web_label = "🌐 联网模式" if _web_status else "📚 知识库"
|
| 1640 |
+
if st.button(_web_label, key="toggle_web", use_container_width=True):
|
| 1641 |
+
st.session_state["sel_web"] = not _web_status
|
| 1642 |
+
|
| 1643 |
+
_toolbar_fragment()
|
| 1644 |
|
| 1645 |
_chat_fragment()
|