aetherforge-platform 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aetherforge_platform-1.0.0.dist-info/METADATA +86 -0
- aetherforge_platform-1.0.0.dist-info/RECORD +55 -0
- aetherforge_platform-1.0.0.dist-info/WHEEL +5 -0
- aetherforge_platform-1.0.0.dist-info/top_level.txt +4 -0
- ai-life-assistant-copy/ai_agent.py +145 -0
- ai-life-assistant-copy/avatar_manager.py +231 -0
- ai-life-assistant-copy/avatar_packer.py +261 -0
- ai-life-assistant-copy/backup_all.py +262 -0
- ai-life-assistant-copy/backups/backup_20260404_193836/ai_agent.py +145 -0
- ai-life-assistant-copy/backups/backup_20260404_193836/avatar_manager.py +231 -0
- ai-life-assistant-copy/backups/backup_20260404_193836/avatar_packer.py +261 -0
- ai-life-assistant-copy/backups/backup_20260404_193836/backup_all.py +262 -0
- ai-life-assistant-copy/backups/backup_20260404_193836/commands.py +210 -0
- ai-life-assistant-copy/backups/backup_20260404_193836/config.py +30 -0
- ai-life-assistant-copy/backups/backup_20260404_193836/daemon/__init__.py +3 -0
- ai-life-assistant-copy/backups/backup_20260404_193836/daemon/daemon.py +174 -0
- ai-life-assistant-copy/backups/backup_20260404_193836/database.py +292 -0
- ai-life-assistant-copy/backups/backup_20260404_193836/graph.py +531 -0
- ai-life-assistant-copy/backups/backup_20260404_193836/main.py +830 -0
- ai-life-assistant-copy/backups/backup_20260404_193836/mcp_tools.py +449 -0
- ai-life-assistant-copy/backups/backup_20260404_193836/memory.py +92 -0
- ai-life-assistant-copy/backups/backup_20260404_193836/memory_v2.py +333 -0
- ai-life-assistant-copy/backups/backup_20260404_193836/mock_shopping_data.py +172 -0
- ai-life-assistant-copy/backups/backup_20260404_193836/personality.py +159 -0
- ai-life-assistant-copy/backups/backup_20260404_193836/speech.py +41 -0
- ai-life-assistant-copy/backups/backup_20260404_193836/test_simple.py +127 -0
- ai-life-assistant-copy/backups/backup_20260404_193836/tools/__init__.py +15 -0
- ai-life-assistant-copy/backups/backup_20260404_193836/tools/amazon_tool.py +103 -0
- ai-life-assistant-copy/backups/backup_20260404_193836/tools/calendar_tool.py +92 -0
- ai-life-assistant-copy/backups/backup_20260404_193836/tools/reminder_tool.py +92 -0
- ai-life-assistant-copy/backups/backup_20260404_193836/tools/weather_tool.py +45 -0
- ai-life-assistant-copy/backups/backup_20260404_193836/tree_memory.py +340 -0
- ai-life-assistant-copy/commands.py +210 -0
- ai-life-assistant-copy/config.py +30 -0
- ai-life-assistant-copy/daemon/__init__.py +3 -0
- ai-life-assistant-copy/daemon/daemon.py +174 -0
- ai-life-assistant-copy/database.py +292 -0
- ai-life-assistant-copy/graph.py +531 -0
- ai-life-assistant-copy/main.py +830 -0
- ai-life-assistant-copy/mcp_tools.py +449 -0
- ai-life-assistant-copy/memory.py +92 -0
- ai-life-assistant-copy/memory_v2.py +333 -0
- ai-life-assistant-copy/mock_shopping_data.py +172 -0
- ai-life-assistant-copy/personality.py +159 -0
- ai-life-assistant-copy/speech.py +41 -0
- ai-life-assistant-copy/test_simple.py +127 -0
- ai-life-assistant-copy/tools/__init__.py +15 -0
- ai-life-assistant-copy/tools/amazon_tool.py +103 -0
- ai-life-assistant-copy/tools/calendar_tool.py +92 -0
- ai-life-assistant-copy/tools/reminder_tool.py +92 -0
- ai-life-assistant-copy/tools/weather_tool.py +45 -0
- ai-life-assistant-copy/tree_memory.py +340 -0
- ai_agent_runtime.py +447 -0
- main.py +6752 -0
- mcp_server.py +427 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"""生活助手守护进程"""
|
|
2
|
+
|
|
3
|
+
import threading
|
|
4
|
+
import time
|
|
5
|
+
import schedule
|
|
6
|
+
from typing import Dict, Any, List
|
|
7
|
+
import json
|
|
8
|
+
import os
|
|
9
|
+
from datetime import datetime
|
|
10
|
+
|
|
11
|
+
class LifeAssistantDaemon:
|
|
12
|
+
"""生活助手守护进程"""
|
|
13
|
+
|
|
14
|
+
def __init__(self, user_id: str = "default"):
|
|
15
|
+
self.user_id = user_id
|
|
16
|
+
self.running = False
|
|
17
|
+
self.thread = None
|
|
18
|
+
self.memory = self._load_memory()
|
|
19
|
+
self.triggers = {
|
|
20
|
+
"stock_check": self._check_stock,
|
|
21
|
+
"weather_alert": self._check_weather,
|
|
22
|
+
"reminder_check": self._check_reminders,
|
|
23
|
+
"habit_analysis": self._analyze_habits
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
def start(self):
|
|
27
|
+
"""启动守护进程"""
|
|
28
|
+
if self.running:
|
|
29
|
+
return
|
|
30
|
+
|
|
31
|
+
self.running = True
|
|
32
|
+
self.thread = threading.Thread(target=self._run, daemon=True)
|
|
33
|
+
self.thread.start()
|
|
34
|
+
print(f"[Daemon] 生活助手守护进程已启动")
|
|
35
|
+
|
|
36
|
+
def stop(self):
|
|
37
|
+
"""停止守护进程"""
|
|
38
|
+
self.running = False
|
|
39
|
+
if self.thread:
|
|
40
|
+
self.thread.join()
|
|
41
|
+
print(f"[Daemon] 生活助手守护进程已停止")
|
|
42
|
+
|
|
43
|
+
def _run(self):
|
|
44
|
+
"""运行守护进程"""
|
|
45
|
+
# 初始化定时任务
|
|
46
|
+
self._schedule_tasks()
|
|
47
|
+
|
|
48
|
+
while self.running:
|
|
49
|
+
schedule.run_pending()
|
|
50
|
+
time.sleep(1)
|
|
51
|
+
|
|
52
|
+
def _schedule_tasks(self):
|
|
53
|
+
"""调度任务"""
|
|
54
|
+
# 每天检查库存
|
|
55
|
+
schedule.every().day.at("08:00").do(self._check_stock)
|
|
56
|
+
# 每天检查天气
|
|
57
|
+
schedule.every().day.at("07:00").do(self._check_weather)
|
|
58
|
+
# 每分钟检查提醒
|
|
59
|
+
schedule.every().minute.do(self._check_reminders)
|
|
60
|
+
# 每周分析习惯
|
|
61
|
+
schedule.every().sunday.at("22:00").do(self._analyze_habits)
|
|
62
|
+
|
|
63
|
+
def _check_stock(self):
|
|
64
|
+
"""检查库存"""
|
|
65
|
+
print(f"[Daemon] 检查库存 - {datetime.now()}")
|
|
66
|
+
# 示例:检查常用商品库存
|
|
67
|
+
stocks = self.memory.get("stocks", {})
|
|
68
|
+
low_stock_items = []
|
|
69
|
+
|
|
70
|
+
for item, info in stocks.items():
|
|
71
|
+
if info.get("stock", 0) < info.get("threshold", 5):
|
|
72
|
+
low_stock_items.append(item)
|
|
73
|
+
|
|
74
|
+
if low_stock_items:
|
|
75
|
+
alert = f"您的以下商品库存不足:{', '.join(low_stock_items)}"
|
|
76
|
+
self._send_alert("stock", alert)
|
|
77
|
+
|
|
78
|
+
def _check_weather(self):
|
|
79
|
+
"""检查天气"""
|
|
80
|
+
print(f"[Daemon] 检查天气 - {datetime.now()}")
|
|
81
|
+
# 示例:检查天气并发送提醒
|
|
82
|
+
from tools.weather_tool import get_weather
|
|
83
|
+
weather = get_weather()
|
|
84
|
+
|
|
85
|
+
if weather.get("success"):
|
|
86
|
+
data = weather.get("data", {})
|
|
87
|
+
temp = data.get("temperature", "")
|
|
88
|
+
desc = data.get("description", "")
|
|
89
|
+
|
|
90
|
+
alert = f"今日天气:{temp},{desc}"
|
|
91
|
+
self._send_alert("weather", alert)
|
|
92
|
+
|
|
93
|
+
def _check_reminders(self):
|
|
94
|
+
"""检查提醒"""
|
|
95
|
+
now = datetime.now()
|
|
96
|
+
current_time = now.strftime("%H:%M")
|
|
97
|
+
current_date = now.strftime("%Y-%m-%d")
|
|
98
|
+
|
|
99
|
+
# 示例:检查提醒
|
|
100
|
+
from tools.reminder_tool import get_reminders
|
|
101
|
+
reminders = get_reminders(current_date)
|
|
102
|
+
|
|
103
|
+
if reminders.get("success"):
|
|
104
|
+
for reminder in reminders.get("reminders", []):
|
|
105
|
+
if reminder.get("time") == current_time:
|
|
106
|
+
alert = f"提醒:{reminder.get('title')}"
|
|
107
|
+
self._send_alert("reminder", alert)
|
|
108
|
+
|
|
109
|
+
def _analyze_habits(self):
|
|
110
|
+
"""分析习惯"""
|
|
111
|
+
print(f"[Daemon] 分析习惯 - {datetime.now()}")
|
|
112
|
+
# 示例:分析用户习惯
|
|
113
|
+
habits = self.memory.get("habits", {})
|
|
114
|
+
|
|
115
|
+
# 简单的习惯分析
|
|
116
|
+
if habits:
|
|
117
|
+
analysis = "习惯分析:\n"
|
|
118
|
+
for habit, data in habits.items():
|
|
119
|
+
frequency = data.get("frequency", 0)
|
|
120
|
+
analysis += f"- {habit}: 频率 {frequency}次/周\n"
|
|
121
|
+
|
|
122
|
+
self._send_alert("habit", analysis)
|
|
123
|
+
|
|
124
|
+
def _send_alert(self, type: str, message: str):
|
|
125
|
+
"""发送提醒"""
|
|
126
|
+
print(f"[Alert] {type}: {message}")
|
|
127
|
+
# 这里可以集成到前端通知系统
|
|
128
|
+
|
|
129
|
+
def _load_memory(self) -> Dict[str, Any]:
|
|
130
|
+
"""加载记忆"""
|
|
131
|
+
memory_file = f"memory_{self.user_id}.json"
|
|
132
|
+
if os.path.exists(memory_file):
|
|
133
|
+
try:
|
|
134
|
+
with open(memory_file, "r", encoding="utf-8") as f:
|
|
135
|
+
return json.load(f)
|
|
136
|
+
except:
|
|
137
|
+
pass
|
|
138
|
+
return {
|
|
139
|
+
"stocks": {
|
|
140
|
+
"纸巾": {"stock": 3, "threshold": 5},
|
|
141
|
+
"牙膏": {"stock": 2, "threshold": 3},
|
|
142
|
+
"洗发水": {"stock": 1, "threshold": 2}
|
|
143
|
+
},
|
|
144
|
+
"habits": {
|
|
145
|
+
"购物": {"frequency": 3},
|
|
146
|
+
"外卖": {"frequency": 2},
|
|
147
|
+
"打车": {"frequency": 1}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
def save_memory(self):
|
|
152
|
+
"""保存记忆"""
|
|
153
|
+
memory_file = f"memory_{self.user_id}.json"
|
|
154
|
+
with open(memory_file, "w", encoding="utf-8") as f:
|
|
155
|
+
json.dump(self.memory, f, ensure_ascii=False, indent=2)
|
|
156
|
+
|
|
157
|
+
def add_habit(self, habit: str):
|
|
158
|
+
"""添加习惯"""
|
|
159
|
+
if "habits" not in self.memory:
|
|
160
|
+
self.memory["habits"] = {}
|
|
161
|
+
|
|
162
|
+
if habit not in self.memory["habits"]:
|
|
163
|
+
self.memory["habits"][habit] = {"frequency": 0}
|
|
164
|
+
|
|
165
|
+
self.memory["habits"][habit]["frequency"] += 1
|
|
166
|
+
self.save_memory()
|
|
167
|
+
|
|
168
|
+
def update_stock(self, item: str, stock: int):
|
|
169
|
+
"""更新库存"""
|
|
170
|
+
if "stocks" not in self.memory:
|
|
171
|
+
self.memory["stocks"] = {}
|
|
172
|
+
|
|
173
|
+
self.memory["stocks"][item] = {"stock": stock, "threshold": 5}
|
|
174
|
+
self.save_memory()
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import sqlite3
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
from typing import Dict, Any, List, Optional
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class AvatarDatabase:
|
|
9
|
+
def __init__(self, db_path: str = "avatar_system.db"):
|
|
10
|
+
self.db_path = db_path
|
|
11
|
+
self._init_database()
|
|
12
|
+
|
|
13
|
+
def _get_connection(self):
|
|
14
|
+
conn = sqlite3.connect(self.db_path)
|
|
15
|
+
conn.row_factory = sqlite3.Row
|
|
16
|
+
return conn
|
|
17
|
+
|
|
18
|
+
def _init_database(self):
|
|
19
|
+
conn = self._get_connection()
|
|
20
|
+
cursor = conn.cursor()
|
|
21
|
+
|
|
22
|
+
cursor.execute("""
|
|
23
|
+
CREATE TABLE IF NOT EXISTS avatars (
|
|
24
|
+
avatar_id TEXT PRIMARY KEY,
|
|
25
|
+
name TEXT NOT NULL,
|
|
26
|
+
description TEXT,
|
|
27
|
+
personality_traits TEXT,
|
|
28
|
+
current_age INTEGER DEFAULT 25,
|
|
29
|
+
birth_year INTEGER,
|
|
30
|
+
avatar_image TEXT,
|
|
31
|
+
is_public INTEGER DEFAULT 0,
|
|
32
|
+
price REAL,
|
|
33
|
+
creator_id TEXT,
|
|
34
|
+
created_at TEXT,
|
|
35
|
+
updated_at TEXT,
|
|
36
|
+
settings TEXT
|
|
37
|
+
)
|
|
38
|
+
""")
|
|
39
|
+
|
|
40
|
+
cursor.execute("""
|
|
41
|
+
CREATE TABLE IF NOT EXISTS memories (
|
|
42
|
+
memory_id TEXT PRIMARY KEY,
|
|
43
|
+
avatar_id TEXT NOT NULL,
|
|
44
|
+
content TEXT NOT NULL,
|
|
45
|
+
min_age INTEGER DEFAULT 0,
|
|
46
|
+
max_age INTEGER DEFAULT 150,
|
|
47
|
+
clarity INTEGER DEFAULT 80,
|
|
48
|
+
emotional_tone TEXT DEFAULT 'neutral',
|
|
49
|
+
topic TEXT,
|
|
50
|
+
parent_id TEXT,
|
|
51
|
+
created_at TEXT,
|
|
52
|
+
FOREIGN KEY (avatar_id) REFERENCES avatars(avatar_id)
|
|
53
|
+
)
|
|
54
|
+
""")
|
|
55
|
+
|
|
56
|
+
cursor.execute("""
|
|
57
|
+
CREATE INDEX IF NOT EXISTS idx_memories_avatar ON memories(avatar_id)
|
|
58
|
+
""")
|
|
59
|
+
|
|
60
|
+
cursor.execute("""
|
|
61
|
+
CREATE INDEX IF NOT EXISTS idx_memories_age ON memories(avatar_id, min_age, max_age)
|
|
62
|
+
""")
|
|
63
|
+
|
|
64
|
+
conn.commit()
|
|
65
|
+
conn.close()
|
|
66
|
+
|
|
67
|
+
def save_avatar(self, avatar_data: Dict[str, Any]):
|
|
68
|
+
conn = self._get_connection()
|
|
69
|
+
cursor = conn.cursor()
|
|
70
|
+
|
|
71
|
+
cursor.execute("""
|
|
72
|
+
INSERT OR REPLACE INTO avatars
|
|
73
|
+
(avatar_id, name, description, personality_traits, current_age, birth_year,
|
|
74
|
+
avatar_image, is_public, price, creator_id, created_at, updated_at, settings)
|
|
75
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
76
|
+
""", (
|
|
77
|
+
avatar_data["avatar_id"],
|
|
78
|
+
avatar_data["name"],
|
|
79
|
+
avatar_data.get("description", ""),
|
|
80
|
+
json.dumps(avatar_data.get("personality_traits", []), ensure_ascii=False),
|
|
81
|
+
avatar_data.get("current_age", 25),
|
|
82
|
+
avatar_data.get("birth_year"),
|
|
83
|
+
avatar_data.get("avatar_image"),
|
|
84
|
+
1 if avatar_data.get("is_public") else 0,
|
|
85
|
+
avatar_data.get("price"),
|
|
86
|
+
avatar_data.get("creator_id"),
|
|
87
|
+
avatar_data.get("created_at"),
|
|
88
|
+
avatar_data.get("updated_at"),
|
|
89
|
+
json.dumps(avatar_data.get("settings", {}), ensure_ascii=False)
|
|
90
|
+
))
|
|
91
|
+
|
|
92
|
+
conn.commit()
|
|
93
|
+
conn.close()
|
|
94
|
+
|
|
95
|
+
def get_avatar(self, avatar_id: str) -> Optional[Dict[str, Any]]:
|
|
96
|
+
conn = self._get_connection()
|
|
97
|
+
cursor = conn.cursor()
|
|
98
|
+
|
|
99
|
+
cursor.execute("SELECT * FROM avatars WHERE avatar_id = ?", (avatar_id,))
|
|
100
|
+
row = cursor.fetchone()
|
|
101
|
+
|
|
102
|
+
if row:
|
|
103
|
+
data = dict(row)
|
|
104
|
+
data["personality_traits"] = json.loads(data["personality_traits"])
|
|
105
|
+
data["settings"] = json.loads(data["settings"])
|
|
106
|
+
data["is_public"] = bool(data["is_public"])
|
|
107
|
+
conn.close()
|
|
108
|
+
return data
|
|
109
|
+
|
|
110
|
+
conn.close()
|
|
111
|
+
return None
|
|
112
|
+
|
|
113
|
+
def list_avatars(self, creator_id: Optional[str] = None) -> List[Dict[str, Any]]:
|
|
114
|
+
conn = self._get_connection()
|
|
115
|
+
cursor = conn.cursor()
|
|
116
|
+
|
|
117
|
+
if creator_id:
|
|
118
|
+
cursor.execute("SELECT * FROM avatars WHERE creator_id = ?", (creator_id,))
|
|
119
|
+
else:
|
|
120
|
+
cursor.execute("SELECT * FROM avatars")
|
|
121
|
+
|
|
122
|
+
avatars = []
|
|
123
|
+
for row in cursor.fetchall():
|
|
124
|
+
data = dict(row)
|
|
125
|
+
data["personality_traits"] = json.loads(data["personality_traits"])
|
|
126
|
+
data["settings"] = json.loads(data["settings"])
|
|
127
|
+
data["is_public"] = bool(data["is_public"])
|
|
128
|
+
avatars.append(data)
|
|
129
|
+
|
|
130
|
+
conn.close()
|
|
131
|
+
return avatars
|
|
132
|
+
|
|
133
|
+
def delete_avatar(self, avatar_id: str) -> bool:
|
|
134
|
+
conn = self._get_connection()
|
|
135
|
+
cursor = conn.cursor()
|
|
136
|
+
|
|
137
|
+
cursor.execute("DELETE FROM memories WHERE avatar_id = ?", (avatar_id,))
|
|
138
|
+
cursor.execute("DELETE FROM avatars WHERE avatar_id = ?", (avatar_id,))
|
|
139
|
+
|
|
140
|
+
deleted = cursor.rowcount > 0
|
|
141
|
+
conn.commit()
|
|
142
|
+
conn.close()
|
|
143
|
+
return deleted
|
|
144
|
+
|
|
145
|
+
def save_memory(self, memory_data: Dict[str, Any]):
|
|
146
|
+
conn = self._get_connection()
|
|
147
|
+
cursor = conn.cursor()
|
|
148
|
+
|
|
149
|
+
cursor.execute("""
|
|
150
|
+
INSERT OR REPLACE INTO memories
|
|
151
|
+
(memory_id, avatar_id, content, min_age, max_age, clarity,
|
|
152
|
+
emotional_tone, topic, parent_id, created_at)
|
|
153
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
154
|
+
""", (
|
|
155
|
+
memory_data["memory_id"],
|
|
156
|
+
memory_data["avatar_id"],
|
|
157
|
+
memory_data["content"],
|
|
158
|
+
memory_data.get("min_age", 0),
|
|
159
|
+
memory_data.get("max_age", 150),
|
|
160
|
+
memory_data.get("clarity", 80),
|
|
161
|
+
memory_data.get("emotional_tone", "neutral"),
|
|
162
|
+
memory_data.get("topic"),
|
|
163
|
+
memory_data.get("parent_id"),
|
|
164
|
+
memory_data.get("created_at")
|
|
165
|
+
))
|
|
166
|
+
|
|
167
|
+
conn.commit()
|
|
168
|
+
conn.close()
|
|
169
|
+
|
|
170
|
+
def get_memories_by_age(self, avatar_id: str, target_age: int) -> List[Dict[str, Any]]:
|
|
171
|
+
conn = self._get_connection()
|
|
172
|
+
cursor = conn.cursor()
|
|
173
|
+
|
|
174
|
+
cursor.execute("""
|
|
175
|
+
SELECT * FROM memories
|
|
176
|
+
WHERE avatar_id = ? AND min_age <= ? AND max_age >= ?
|
|
177
|
+
ORDER BY created_at DESC
|
|
178
|
+
""", (avatar_id, target_age, target_age))
|
|
179
|
+
|
|
180
|
+
memories = [dict(row) for row in cursor.fetchall()]
|
|
181
|
+
conn.close()
|
|
182
|
+
return memories
|
|
183
|
+
|
|
184
|
+
def get_all_memories(self, avatar_id: str) -> List[Dict[str, Any]]:
|
|
185
|
+
conn = self._get_connection()
|
|
186
|
+
cursor = conn.cursor()
|
|
187
|
+
|
|
188
|
+
cursor.execute("""
|
|
189
|
+
SELECT * FROM memories WHERE avatar_id = ?
|
|
190
|
+
ORDER BY created_at DESC
|
|
191
|
+
""", (avatar_id,))
|
|
192
|
+
|
|
193
|
+
memories = [dict(row) for row in cursor.fetchall()]
|
|
194
|
+
conn.close()
|
|
195
|
+
return memories
|
|
196
|
+
|
|
197
|
+
def delete_memory(self, memory_id: str) -> bool:
|
|
198
|
+
conn = self._get_connection()
|
|
199
|
+
cursor = conn.cursor()
|
|
200
|
+
|
|
201
|
+
cursor.execute("DELETE FROM memories WHERE memory_id = ?", (memory_id,))
|
|
202
|
+
|
|
203
|
+
deleted = cursor.rowcount > 0
|
|
204
|
+
conn.commit()
|
|
205
|
+
conn.close()
|
|
206
|
+
return deleted
|
|
207
|
+
|
|
208
|
+
def list_market_avatars(self) -> List[Dict[str, Any]]:
|
|
209
|
+
conn = self._get_connection()
|
|
210
|
+
cursor = conn.cursor()
|
|
211
|
+
|
|
212
|
+
cursor.execute("""
|
|
213
|
+
SELECT * FROM avatars
|
|
214
|
+
WHERE is_public = 1 AND price IS NOT NULL
|
|
215
|
+
""")
|
|
216
|
+
|
|
217
|
+
avatars = []
|
|
218
|
+
for row in cursor.fetchall():
|
|
219
|
+
data = dict(row)
|
|
220
|
+
data["personality_traits"] = json.loads(data["personality_traits"])
|
|
221
|
+
data["settings"] = json.loads(data["settings"])
|
|
222
|
+
data["is_public"] = bool(data["is_public"])
|
|
223
|
+
avatars.append(data)
|
|
224
|
+
|
|
225
|
+
conn.close()
|
|
226
|
+
return avatars
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
avatar_database = AvatarDatabase()
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def init_sample_data():
|
|
233
|
+
sample_avatar = {
|
|
234
|
+
"avatar_id": "sample_001",
|
|
235
|
+
"name": "Alex",
|
|
236
|
+
"description": "一个友好、好奇的虚拟形象",
|
|
237
|
+
"personality_traits": ["友好", "好奇", "创造力"],
|
|
238
|
+
"current_age": 25,
|
|
239
|
+
"birth_year": 2000,
|
|
240
|
+
"is_public": False,
|
|
241
|
+
"creator_id": "demo_user",
|
|
242
|
+
"created_at": datetime.now().isoformat(),
|
|
243
|
+
"updated_at": datetime.now().isoformat(),
|
|
244
|
+
"settings": {"developer_mode": False, "auto_organize": True}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
avatar_database.save_avatar(sample_avatar)
|
|
248
|
+
|
|
249
|
+
sample_memories = [
|
|
250
|
+
{
|
|
251
|
+
"memory_id": "mem_001",
|
|
252
|
+
"avatar_id": "sample_001",
|
|
253
|
+
"content": "我第一次学会骑自行车,那天很开心",
|
|
254
|
+
"min_age": 5,
|
|
255
|
+
"max_age": 10,
|
|
256
|
+
"clarity": 90,
|
|
257
|
+
"emotional_tone": "happy",
|
|
258
|
+
"topic": "童年",
|
|
259
|
+
"created_at": datetime.now().isoformat()
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
"memory_id": "mem_002",
|
|
263
|
+
"avatar_id": "sample_001",
|
|
264
|
+
"content": "高中时参加了数学竞赛,获得了二等奖",
|
|
265
|
+
"min_age": 15,
|
|
266
|
+
"max_age": 18,
|
|
267
|
+
"clarity": 85,
|
|
268
|
+
"emotional_tone": "proud",
|
|
269
|
+
"topic": "学业",
|
|
270
|
+
"created_at": datetime.now().isoformat()
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
"memory_id": "mem_003",
|
|
274
|
+
"avatar_id": "sample_001",
|
|
275
|
+
"content": "大学毕业后的第一份工作是软件开发工程师",
|
|
276
|
+
"min_age": 22,
|
|
277
|
+
"max_age": 30,
|
|
278
|
+
"clarity": 95,
|
|
279
|
+
"emotional_tone": "excited",
|
|
280
|
+
"topic": "职业",
|
|
281
|
+
"created_at": datetime.now().isoformat()
|
|
282
|
+
}
|
|
283
|
+
]
|
|
284
|
+
|
|
285
|
+
for memory in sample_memories:
|
|
286
|
+
avatar_database.save_memory(memory)
|
|
287
|
+
|
|
288
|
+
print("Sample data initialized!")
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
if __name__ == "__main__":
|
|
292
|
+
init_sample_data()
|