|
| 1 | +import json |
1 | 2 | import shutil |
2 | 3 | import sys |
3 | 4 |
|
4 | 5 | from pathlib import Path |
5 | | -from queue import Queue |
6 | | -from typing import TYPE_CHECKING |
7 | 6 |
|
8 | 7 | from memos.configs.mem_cube import GeneralMemCubeConfig |
9 | 8 | from memos.configs.mem_os import MOSConfig |
10 | 9 | from memos.configs.mem_scheduler import AuthConfig |
11 | 10 | from memos.log import get_logger |
12 | 11 | from memos.mem_cube.general import GeneralMemCube |
13 | | -from memos.mem_scheduler.general_scheduler import GeneralScheduler |
14 | 12 | from memos.mem_scheduler.mos_for_test_scheduler import MOSForTestScheduler |
15 | 13 |
|
16 | 14 |
|
17 | | -if TYPE_CHECKING: |
18 | | - from memos.mem_scheduler.modules.schemas import ( |
19 | | - ScheduleLogForWebItem, |
20 | | - ) |
21 | | - |
22 | | - |
23 | 15 | FILE_PATH = Path(__file__).absolute() |
24 | 16 | BASE_DIR = FILE_PATH.parent.parent.parent |
25 | 17 | sys.path.insert(0, str(BASE_DIR)) # Enable execution from any working directory |
@@ -90,41 +82,6 @@ def init_task(): |
90 | 82 | return conversations, questions |
91 | 83 |
|
92 | 84 |
|
93 | | -def show_web_logs(mem_scheduler: GeneralScheduler): |
94 | | - """Display all web log entries from the scheduler's log queue. |
95 | | -
|
96 | | - Args: |
97 | | - mem_scheduler: The scheduler instance containing web logs to display |
98 | | - """ |
99 | | - if mem_scheduler._web_log_message_queue.empty(): |
100 | | - print("Web log queue is currently empty.") |
101 | | - return |
102 | | - |
103 | | - print("\n" + "=" * 50 + " WEB LOGS " + "=" * 50) |
104 | | - |
105 | | - # Create a temporary queue to preserve the original queue contents |
106 | | - temp_queue = Queue() |
107 | | - log_count = 0 |
108 | | - |
109 | | - while not mem_scheduler._web_log_message_queue.empty(): |
110 | | - log_item: ScheduleLogForWebItem = mem_scheduler._web_log_message_queue.get() |
111 | | - temp_queue.put(log_item) |
112 | | - log_count += 1 |
113 | | - |
114 | | - # Print log entry details |
115 | | - print(f"\nLog Entry #{log_count}:") |
116 | | - print(f'- "{log_item.label}" log: {log_item}') |
117 | | - |
118 | | - print("-" * 50) |
119 | | - |
120 | | - # Restore items back to the original queue |
121 | | - while not temp_queue.empty(): |
122 | | - mem_scheduler._web_log_message_queue.put(temp_queue.get()) |
123 | | - |
124 | | - print(f"\nTotal {log_count} web log entries displayed.") |
125 | | - print("=" * 110 + "\n") |
126 | | - |
127 | | - |
128 | 85 | if __name__ == "__main__": |
129 | 86 | # set up data |
130 | 87 | conversations, questions = init_task() |
@@ -168,12 +125,18 @@ def show_web_logs(mem_scheduler: GeneralScheduler): |
168 | 125 |
|
169 | 126 | mos.add(conversations, user_id=user_id, mem_cube_id=mem_cube_id) |
170 | 127 |
|
| 128 | + # Add interfering conversations |
| 129 | + file_path = Path(f"{BASE_DIR}/examples/data/mem_scheduler/scene_data.json") |
| 130 | + scene_data = json.load(file_path.open("r", encoding="utf-8")) |
| 131 | + mos.add(scene_data[0], user_id=user_id, mem_cube_id=mem_cube_id) |
| 132 | + mos.add(scene_data[1], user_id=user_id, mem_cube_id=mem_cube_id) |
| 133 | + |
171 | 134 | for item in questions: |
| 135 | + print("===== Chat Start =====") |
172 | 136 | query = item["question"] |
173 | | - |
| 137 | + print(f"Query:\n {query}\n") |
174 | 138 | response = mos.chat(query=query, user_id=user_id) |
175 | | - print(f"Query:\n {query}\n\nAnswer:\n {response}") |
176 | | - |
177 | | - show_web_logs(mos.mem_scheduler) |
| 139 | + print(f"Answer:\n {response}") |
| 140 | + print("===== Chat End =====") |
178 | 141 |
|
179 | 142 | mos.mem_scheduler.stop() |
0 commit comments