mirror of
https://gitcode.com/JianFeeeee/TrulyMEM-TrueHumanMEM.git
synced 2026-09-21 09:28:19 +00:00
feat: 添加数据库迁移、清空聊天记录按钮 - 复用SAVE_HISTORY接口
This commit is contained in:
16
ui/app.py
16
ui/app.py
@ -143,7 +143,21 @@ class GraphMemoryApp(App):
|
||||
status_bar.set_processing(True)
|
||||
|
||||
asyncio.create_task(self._process(user_input))
|
||||
|
||||
|
||||
def on_input_box_clear_history(self, event) -> None:
|
||||
"""处理清空聊天记录事件"""
|
||||
if not self._backend_client:
|
||||
self.notify("后端未初始化", title="错误", severity="error")
|
||||
return
|
||||
|
||||
self._backend_client.clear_history()
|
||||
|
||||
from .widgets.message_history import MessageHistory
|
||||
history = self.query_one(MessageHistory)
|
||||
history.clear_messages()
|
||||
|
||||
self.notify("聊天记录已清空,AI记忆保持不变", title="提示", severity="information")
|
||||
|
||||
async def _process(self, user_input: str) -> None:
|
||||
from .widgets.message_history import MessageHistory
|
||||
from .widgets.status_bar import StatusBar
|
||||
|
||||
@ -13,6 +13,11 @@ class InputBox(Container):
|
||||
def __init__(self, content: str) -> None:
|
||||
self.content = content
|
||||
super().__init__()
|
||||
|
||||
class ClearHistory(Message):
|
||||
"""清空聊天记录事件"""
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
@ -26,6 +31,7 @@ class InputBox(Container):
|
||||
id="input-textarea"
|
||||
)
|
||||
with Horizontal(classes="input-buttons"):
|
||||
yield Button("清空", id="clear-button", variant="default")
|
||||
yield Button("发送", id="send-button", variant="primary")
|
||||
|
||||
def on_mount(self) -> None:
|
||||
@ -38,6 +44,8 @@ class InputBox(Container):
|
||||
"""处理按钮点击"""
|
||||
if event.button.id == "send-button":
|
||||
self._send_message()
|
||||
elif event.button.id == "clear-button":
|
||||
self.post_message(self.ClearHistory())
|
||||
|
||||
def on_key(self, event) -> None:
|
||||
"""处理按键事件"""
|
||||
|
||||
Reference in New Issue
Block a user