mirror of
https://gitcode.com/JianFeeeee/TrulyMEM-TrueHumanMEM.git
synced 2026-09-21 09:28:19 +00:00
feat: Add embedded SQLite database and web interface
- Implement EmbeddedGraphDB with full Neo4j compatibility - Add web interface for browser access - Fix input box display issue - Add comprehensive database tests (15/15 passed) - Simplify startup script (3 steps, no Docker needed) - Add multi-language support - Add .gitignore for clean repository - Update documentation All tests passed. Ready for production.
This commit is contained in:
1
graph_memory_tui/models/__init__.py
Normal file
1
graph_memory_tui/models/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
"""Data Models for Graph Memory TUI"""
|
||||
46
graph_memory_tui/models/config.py
Normal file
46
graph_memory_tui/models/config.py
Normal file
@ -0,0 +1,46 @@
|
||||
"""配置数据模型"""
|
||||
|
||||
import json
|
||||
import os
|
||||
from dataclasses import dataclass, asdict
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
|
||||
@dataclass
|
||||
class AppConfig:
|
||||
"""应用配置"""
|
||||
api_key: str = ""
|
||||
model: str = "deepseek-chat"
|
||||
base_url: str = "https://api.deepseek.com"
|
||||
|
||||
@classmethod
|
||||
def from_env(cls) -> "AppConfig":
|
||||
"""从环境变量加载配置"""
|
||||
return cls(
|
||||
api_key=os.getenv("DEEPSEEK_API_KEY", ""),
|
||||
model=os.getenv("MODEL_NAME", "deepseek-chat"),
|
||||
base_url=os.getenv("DEEPSEEK_BASE_URL", "https://api.deepseek.com"),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_file(cls, path: Path) -> "AppConfig":
|
||||
"""从文件加载配置"""
|
||||
if not path.exists():
|
||||
return cls()
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
|
||||
return cls(
|
||||
api_key=data.get("api_key", ""),
|
||||
model=data.get("model", "deepseek-chat"),
|
||||
base_url=data.get("base_url", "https://api.deepseek.com"),
|
||||
)
|
||||
|
||||
def save(self, path: Path) -> None:
|
||||
"""保存配置到文件"""
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
json.dump(asdict(self), f, indent=2, ensure_ascii=False)
|
||||
30
graph_memory_tui/models/log_entry.py
Normal file
30
graph_memory_tui/models/log_entry.py
Normal file
@ -0,0 +1,30 @@
|
||||
"""日志条目数据模型"""
|
||||
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict
|
||||
|
||||
|
||||
@dataclass
|
||||
class LogEntry:
|
||||
"""日志条目"""
|
||||
timestamp: datetime
|
||||
tool_name: str
|
||||
arguments: Dict[str, Any]
|
||||
result: str
|
||||
duration: float
|
||||
|
||||
@property
|
||||
def args_summary(self) -> str:
|
||||
"""参数摘要(截断到50字符)"""
|
||||
args_str = str(self.arguments)
|
||||
if len(args_str) > 50:
|
||||
return args_str[:50] + "..."
|
||||
return args_str
|
||||
|
||||
@property
|
||||
def result_summary(self) -> str:
|
||||
"""结果摘要(截断到100字符)"""
|
||||
if len(self.result) > 100:
|
||||
return self.result[:100] + "..."
|
||||
return self.result
|
||||
33
graph_memory_tui/models/message.py
Normal file
33
graph_memory_tui/models/message.py
Normal file
@ -0,0 +1,33 @@
|
||||
"""消息数据模型"""
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
from typing import Dict, List, Literal, Optional, Any
|
||||
|
||||
|
||||
@dataclass
|
||||
class ToolCall:
|
||||
"""工具调用"""
|
||||
id: str
|
||||
name: str
|
||||
arguments: Dict[str, Any]
|
||||
|
||||
|
||||
@dataclass
|
||||
class ToolResult:
|
||||
"""工具执行结果"""
|
||||
tool_call_id: str
|
||||
name: str
|
||||
arguments: Dict[str, Any]
|
||||
result: str
|
||||
success: bool
|
||||
|
||||
|
||||
@dataclass
|
||||
class Message:
|
||||
"""消息"""
|
||||
role: Literal["user", "assistant", "system"]
|
||||
content: str
|
||||
timestamp: datetime = field(default_factory=datetime.now)
|
||||
tool_calls: Optional[List[ToolCall]] = None
|
||||
tool_results: Optional[List[ToolResult]] = None
|
||||
Reference in New Issue
Block a user