npcpy 1.2.18__py3-none-any.whl → 1.2.19__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.
- npcpy/ft/memory_trainer.py +3 -3
- npcpy/memory/memory_processor.py +0 -90
- {npcpy-1.2.18.dist-info → npcpy-1.2.19.dist-info}/METADATA +1 -1
- {npcpy-1.2.18.dist-info → npcpy-1.2.19.dist-info}/RECORD +7 -7
- {npcpy-1.2.18.dist-info → npcpy-1.2.19.dist-info}/WHEEL +0 -0
- {npcpy-1.2.18.dist-info → npcpy-1.2.19.dist-info}/licenses/LICENSE +0 -0
- {npcpy-1.2.18.dist-info → npcpy-1.2.19.dist-info}/top_level.txt +0 -0
npcpy/ft/memory_trainer.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import torch
|
|
2
|
-
import torch.nn as nn
|
|
3
1
|
try:
|
|
4
|
-
from transformers import AutoTokenizer, AutoModelForSequenceClassification, Trainer, TrainingArguments
|
|
5
2
|
from torch.utils.data import Dataset
|
|
3
|
+
import torch
|
|
4
|
+
import torch.nn as nn
|
|
5
|
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, Trainer, TrainingArguments
|
|
6
6
|
except:
|
|
7
7
|
pass
|
|
8
8
|
import json
|
npcpy/memory/memory_processor.py
CHANGED
|
@@ -17,96 +17,6 @@ class MemoryItem:
|
|
|
17
17
|
model: str
|
|
18
18
|
provider: str
|
|
19
19
|
|
|
20
|
-
class MemoryApprovalQueue:
|
|
21
|
-
def __init__(self, command_history):
|
|
22
|
-
self.command_history = command_history
|
|
23
|
-
self.pending_queue = queue.Queue()
|
|
24
|
-
self.approval_results = queue.Queue()
|
|
25
|
-
self.processing_thread = None
|
|
26
|
-
self.running = False
|
|
27
|
-
|
|
28
|
-
def add_memory(self, memory_item: MemoryItem):
|
|
29
|
-
"""Add memory to processing queue (non-blocking)"""
|
|
30
|
-
self.pending_queue.put(memory_item)
|
|
31
|
-
|
|
32
|
-
def start_background_processing(self):
|
|
33
|
-
"""Start background thread for memory processing"""
|
|
34
|
-
if self.processing_thread and self.processing_thread.is_alive():
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
self.running = True
|
|
38
|
-
self.processing_thread = threading.Thread(target=self._process_queue)
|
|
39
|
-
self.processing_thread.daemon = True
|
|
40
|
-
self.processing_thread.start()
|
|
41
|
-
|
|
42
|
-
def _process_queue(self):
|
|
43
|
-
"""Background processing of memory queue"""
|
|
44
|
-
while self.running:
|
|
45
|
-
try:
|
|
46
|
-
|
|
47
|
-
batch = []
|
|
48
|
-
try:
|
|
49
|
-
|
|
50
|
-
memory = self.pending_queue.get(timeout=1.0)
|
|
51
|
-
batch.append(memory)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
while len(batch) < 10:
|
|
55
|
-
try:
|
|
56
|
-
memory = self.pending_queue.get_nowait()
|
|
57
|
-
batch.append(memory)
|
|
58
|
-
except queue.Empty:
|
|
59
|
-
break
|
|
60
|
-
|
|
61
|
-
self._process_memory_batch(batch)
|
|
62
|
-
|
|
63
|
-
except queue.Empty:
|
|
64
|
-
continue
|
|
65
|
-
|
|
66
|
-
except Exception as e:
|
|
67
|
-
print(f"Error in memory processing: {e}")
|
|
68
|
-
time.sleep(1)
|
|
69
|
-
|
|
70
|
-
def _process_memory_batch(self, memories: List[MemoryItem]):
|
|
71
|
-
"""Process a batch of memories"""
|
|
72
|
-
for memory in memories:
|
|
73
|
-
|
|
74
|
-
memory_id = self.command_history.add_memory_to_database(
|
|
75
|
-
message_id=memory.message_id,
|
|
76
|
-
conversation_id=memory.conversation_id,
|
|
77
|
-
npc=memory.npc,
|
|
78
|
-
team=memory.team,
|
|
79
|
-
directory_path=memory.directory_path,
|
|
80
|
-
initial_memory=memory.content,
|
|
81
|
-
status="pending_approval",
|
|
82
|
-
model=memory.model,
|
|
83
|
-
provider=memory.provider
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
self.approval_results.put({
|
|
88
|
-
"memory_id": memory_id,
|
|
89
|
-
"content": memory.content,
|
|
90
|
-
"context": memory.context,
|
|
91
|
-
"npc": memory.npc
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
def get_approval_batch(self, max_items: int = 5) -> List[Dict]:
|
|
95
|
-
"""Get batch of memories ready for approval"""
|
|
96
|
-
batch = []
|
|
97
|
-
try:
|
|
98
|
-
while len(batch) < max_items:
|
|
99
|
-
item = self.approval_results.get_nowait()
|
|
100
|
-
batch.append(item)
|
|
101
|
-
except queue.Empty:
|
|
102
|
-
pass
|
|
103
|
-
return batch
|
|
104
|
-
|
|
105
|
-
def stop_processing(self):
|
|
106
|
-
"""Stop background processing"""
|
|
107
|
-
self.running = False
|
|
108
|
-
if self.processing_thread:
|
|
109
|
-
self.processing_thread.join(timeout=2.0)
|
|
110
20
|
|
|
111
21
|
def memory_approval_ui(memories: List[Dict]) -> List[Dict]:
|
|
112
22
|
"""Simple CLI interface for memory approval"""
|
|
@@ -17,7 +17,7 @@ npcpy/data/web.py,sha256=ARGoVKUlQmaiX0zJbSvvFmRCwOv_Z7Pcan9c5GxYObQ,5117
|
|
|
17
17
|
npcpy/ft/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
18
|
npcpy/ft/diff.py,sha256=R3Qo6v0-6M1iI0wiXhUzyuYI2ja0q_0i9bE0z3coxzU,28
|
|
19
19
|
npcpy/ft/ge.py,sha256=my5LtGyVTT40V0i1h9FR-tFFA1FHSga-PeCCgUX1UUI,61
|
|
20
|
-
npcpy/ft/memory_trainer.py,sha256=
|
|
20
|
+
npcpy/ft/memory_trainer.py,sha256=410BtNj308c7V45E809ILbDjCnVRy7n0mdIp2DKOCNY,5904
|
|
21
21
|
npcpy/ft/rl.py,sha256=l3RUkEJe4b2yB6pildveu2LJymtNq0F17COwf_CCq3U,34
|
|
22
22
|
npcpy/ft/sft.py,sha256=i4ENygRPArbLWN4XZZuBnPWaehs8M-J68JB_mewGJHI,62
|
|
23
23
|
npcpy/gen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -30,7 +30,7 @@ npcpy/memory/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
30
30
|
npcpy/memory/command_history.py,sha256=Ww7vZTSjQDuElQXuOjsvu7NTljOLAg07QIFrfKARpVg,45562
|
|
31
31
|
npcpy/memory/kg_vis.py,sha256=TrQQCRh_E7Pyr-GPAHLSsayubAfGyf4HOEFrPB6W86Q,31280
|
|
32
32
|
npcpy/memory/knowledge_graph.py,sha256=2XpIlsyPdAOnzQ6kkwP6MWPGwL3P6V33_3suNJYMMJE,48681
|
|
33
|
-
npcpy/memory/memory_processor.py,sha256=
|
|
33
|
+
npcpy/memory/memory_processor.py,sha256=bLfzT-uDgwNegs1hVBqW3Hl2fYtdmFQbdc5To_f4i5E,2106
|
|
34
34
|
npcpy/memory/search.py,sha256=glN6WYzaixcoDphTEHAXSMX3vKZGjR12Jx9YVL_gYfE,18433
|
|
35
35
|
npcpy/mix/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
36
36
|
npcpy/mix/debate.py,sha256=lQXxC7nl6Rwyf7HIYrsVQILMUmYYx55Tjt2pkTg56qY,9019
|
|
@@ -41,8 +41,8 @@ npcpy/work/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
41
41
|
npcpy/work/desktop.py,sha256=F3I8mUtJp6LAkXodsh8hGZIncoads6c_2Utty-0EdDA,2986
|
|
42
42
|
npcpy/work/plan.py,sha256=QyUwg8vElWiHuoS-xK4jXTxxHvkMD3VkaCEsCmrEPQk,8300
|
|
43
43
|
npcpy/work/trigger.py,sha256=P1Y8u1wQRsS2WACims_2IdkBEar-iBQix-2TDWoW0OM,9948
|
|
44
|
-
npcpy-1.2.
|
|
45
|
-
npcpy-1.2.
|
|
46
|
-
npcpy-1.2.
|
|
47
|
-
npcpy-1.2.
|
|
48
|
-
npcpy-1.2.
|
|
44
|
+
npcpy-1.2.19.dist-info/licenses/LICENSE,sha256=j0YPvce7Ng9e32zYOu0EmXjXeJ0Nwawd0RA3uSGGH4E,1070
|
|
45
|
+
npcpy-1.2.19.dist-info/METADATA,sha256=dnJPjMvml-0yrEJXUt9g-Rf-UT9mIXuQR3HJZzYgm18,26084
|
|
46
|
+
npcpy-1.2.19.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
47
|
+
npcpy-1.2.19.dist-info/top_level.txt,sha256=g1pbSvrOOncB74Bg5-J0Olg4V0A5VzDw-Xz5YObq8BU,6
|
|
48
|
+
npcpy-1.2.19.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|