update
This commit is contained in:
@@ -64,7 +64,7 @@ with st.sidebar:
|
||||
)
|
||||
platform = st.radio("Платформа", ["PV DOT CI", "PV DOT CD", "DPM CI", "DPM CD"])
|
||||
st.divider()
|
||||
st.caption("Портал АС/ФП · конфигурации в разделе «Инструменты»")
|
||||
st.caption("Портал АС/ФП · чат и генератор используют выбранную LLM модель.")
|
||||
|
||||
if "history" not in st.session_state:
|
||||
st.session_state.history = []
|
||||
@@ -77,6 +77,8 @@ if "asfp_info" not in st.session_state:
|
||||
"contacts": "",
|
||||
"description": "",
|
||||
}
|
||||
if "chat_messages" not in st.session_state:
|
||||
st.session_state.chat_messages = []
|
||||
|
||||
|
||||
def _push_history(*, platform: str, model: str, prompt: str, status: str, config: str, error: str | None):
|
||||
@@ -182,8 +184,9 @@ if not st.session_state.token:
|
||||
_title_bar(show_logout=True)
|
||||
st.caption("Портал с данными и инструментами для АС/ФП.")
|
||||
|
||||
tab_info, tab_autonomous, tab_infra, tab_tools, tab_news = st.tabs(
|
||||
tab_chat, tab_info, tab_autonomous, tab_infra, tab_tools, tab_news = st.tabs(
|
||||
[
|
||||
"Чат с ИИ",
|
||||
"Сведения об АС/ФП",
|
||||
"Автономные внедрения",
|
||||
"Инфраструктура АС/ФП",
|
||||
@@ -192,6 +195,56 @@ tab_info, tab_autonomous, tab_infra, tab_tools, tab_news = st.tabs(
|
||||
]
|
||||
)
|
||||
|
||||
with tab_chat:
|
||||
st.subheader("Чат с ИИ")
|
||||
st.caption(
|
||||
f"Запросы идут на backend `{backend_base_url}/chat`, а оттуда — в Ollama (`/api/chat`). "
|
||||
f"Модель: **{model}**."
|
||||
)
|
||||
head_a, head_b = st.columns([4, 1])
|
||||
with head_b:
|
||||
|
||||
def _clear_chat():
|
||||
st.session_state.chat_messages = []
|
||||
|
||||
st.button("Очистить чат", on_click=_clear_chat, use_container_width=True, key="btn_clear_chat")
|
||||
|
||||
with st.container(border=True):
|
||||
for m in st.session_state.chat_messages:
|
||||
with st.chat_message(m["role"]):
|
||||
st.markdown(m["content"].replace("$", r"\$"))
|
||||
|
||||
user_text = st.chat_input("Напишите сообщение…", key="chat_input_portal")
|
||||
if user_text:
|
||||
st.session_state.chat_messages.append({"role": "user", "content": user_text})
|
||||
with st.chat_message("user"):
|
||||
st.markdown(user_text.replace("$", r"\$"))
|
||||
|
||||
reply = ""
|
||||
with st.chat_message("assistant"):
|
||||
with st.spinner("Ollama отвечает…"):
|
||||
try:
|
||||
r = requests.post(
|
||||
f"{backend_base_url}/chat",
|
||||
json={
|
||||
"model": model,
|
||||
"messages": st.session_state.chat_messages,
|
||||
},
|
||||
headers=_auth_headers(),
|
||||
timeout=120,
|
||||
)
|
||||
if r.status_code >= 400:
|
||||
reply = f"**Ошибка:** {_detail_or_text(r)}"
|
||||
st.error(_detail_or_text(r))
|
||||
else:
|
||||
data = r.json()
|
||||
reply = data.get("content") or ""
|
||||
st.markdown(reply.replace("$", r"\$"))
|
||||
except Exception as e:
|
||||
reply = f"**Ошибка сети:** {e}"
|
||||
st.error(str(e))
|
||||
st.session_state.chat_messages.append({"role": "assistant", "content": reply})
|
||||
|
||||
with tab_info:
|
||||
st.subheader("Сведения об АС/ФП")
|
||||
st.caption("Черновик формы. Дальше можно привязать к Postgres.")
|
||||
|
||||
Reference in New Issue
Block a user