amrita_plugin_memory 0.2.5__tar.gz → 0.2.7__tar.gz
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.
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/PKG-INFO +1 -1
- amrita_plugin_memory-0.2.7/amrita_plugin_memory/rethinking/__init__.py +13 -0
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory/rethinking/_state.py +8 -0
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory/rethinking/runner.py +10 -12
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory/rethinking/tools.py +1 -2
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory.egg-info/PKG-INFO +1 -1
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/pyproject.toml +1 -1
- amrita_plugin_memory-0.2.5/amrita_plugin_memory/rethinking/__init__.py +0 -20
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/LICENSE +0 -0
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/README.md +0 -0
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory/__init__.py +0 -0
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory/config.py +0 -0
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory/embed.py +0 -0
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory/matchers.py +0 -0
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory/rethinking/backend.py +0 -0
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory/rethinking/consts.py +0 -0
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory/rethinking/hooks.py +0 -0
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory/rethinking/nodes.py +0 -0
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory/rethinking/schemas.py +0 -0
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory/rethinking/workflow.py +0 -0
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory/tools.py +0 -0
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory/vector.py +0 -0
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory.egg-info/SOURCES.txt +0 -0
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory.egg-info/dependency_links.txt +0 -0
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory.egg-info/requires.txt +0 -0
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory.egg-info/top_level.txt +0 -0
- {amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/setup.cfg +0 -0
{amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory/rethinking/_state.py
RENAMED
|
@@ -4,6 +4,8 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
from typing import TYPE_CHECKING, Any
|
|
6
6
|
|
|
7
|
+
from amrita.plugins.chat.config import config_manager
|
|
8
|
+
from amrita_core import ModelPreset
|
|
7
9
|
from amrita_core.tools.manager import MultiToolsManager
|
|
8
10
|
|
|
9
11
|
if TYPE_CHECKING:
|
|
@@ -15,6 +17,12 @@ _pending_messages: list[dict[str, Any]] = []
|
|
|
15
17
|
_SUBCONSCIOUS_TOOLS = MultiToolsManager()
|
|
16
18
|
|
|
17
19
|
|
|
20
|
+
async def get_preset() -> ModelPreset:
|
|
21
|
+
return await config_manager.get_preset(
|
|
22
|
+
(await config_manager.safe_get_config()).preset
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
18
26
|
def get_runner() -> SubconsciousRunner | None:
|
|
19
27
|
return _runner
|
|
20
28
|
|
{amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory/rethinking/runner.py
RENAMED
|
@@ -12,15 +12,15 @@ from typing import Any
|
|
|
12
12
|
from amrita.plugins.chat.utils.app import CachedUserDataRepository
|
|
13
13
|
from amrita.plugins.chat.utils.libchat import add_usage
|
|
14
14
|
from amrita.plugins.chat.utils.sql import InsightsModel
|
|
15
|
+
from amrita_core import SuspendObjectStream
|
|
15
16
|
from amrita_core.base.backend import BackendSlots
|
|
16
17
|
from amrita_core.builtins.agent import ReActAgentStrategy
|
|
17
18
|
from amrita_core.chatmanager import ChatObject
|
|
18
19
|
from amrita_core.config import get_config
|
|
19
|
-
from amrita_core.preset import
|
|
20
|
+
from amrita_core.preset import ModelPreset
|
|
20
21
|
from amrita_core.types import Message, UniResponseUsage
|
|
21
22
|
from amrita_core.utils import gather_usage
|
|
22
23
|
from amrita_sense import WorkflowInterpreter
|
|
23
|
-
from amrita_sense.exceptions import InterruptKeepContext
|
|
24
24
|
from amrita_sense.runtime.types import InterpreterContext
|
|
25
25
|
from jinja2 import Template
|
|
26
26
|
from nonebot import logger
|
|
@@ -40,6 +40,9 @@ from .workflow import build_workflow
|
|
|
40
40
|
_REPO_UID = "user_00000000"
|
|
41
41
|
|
|
42
42
|
|
|
43
|
+
async def _ign_cb(*_, **__): ...
|
|
44
|
+
|
|
45
|
+
|
|
43
46
|
class SubconsciousRunner:
|
|
44
47
|
"""常驻推理循环运行器。
|
|
45
48
|
|
|
@@ -123,21 +126,18 @@ class SubconsciousRunner:
|
|
|
123
126
|
self._is_running = True
|
|
124
127
|
self._iter_stop_result = {}
|
|
125
128
|
|
|
126
|
-
preset =
|
|
129
|
+
preset = await _state.get_preset()
|
|
127
130
|
prompt_text = await self._load_prompt()
|
|
128
131
|
user_msg_text = (
|
|
129
132
|
f"现在是第 {self._total_runs + 1} 次潜意识推理循环。"
|
|
130
133
|
f"请检查用户 (ID: {self._config.target_user_id}) 的记忆库,执行必要的整理操作。"
|
|
131
134
|
f"完成后务必调用 subconscious_iter_stop。"
|
|
132
135
|
)
|
|
133
|
-
if self._is_native_thinking():
|
|
134
|
-
user_msg_text += (
|
|
135
|
-
" (注意:你的模型启用了内置思考模式,请务必调用 think_and_reason。)"
|
|
136
|
-
)
|
|
137
|
-
|
|
138
136
|
train = Message(role="system", content=prompt_text)
|
|
139
137
|
user_input = user_msg_text
|
|
140
138
|
|
|
139
|
+
io_stream = SuspendObjectStream(callback=_ign_cb)
|
|
140
|
+
|
|
141
141
|
chat_obj = ChatObject(
|
|
142
142
|
train=train,
|
|
143
143
|
user_input=user_input,
|
|
@@ -146,7 +146,7 @@ class SubconsciousRunner:
|
|
|
146
146
|
backend=BackendSlots(self._backend, self._backend),
|
|
147
147
|
config=get_config(),
|
|
148
148
|
agent_strategy=ReActAgentStrategy,
|
|
149
|
-
|
|
149
|
+
io_stream=io_stream,
|
|
150
150
|
)
|
|
151
151
|
self._chat_obj = chat_obj
|
|
152
152
|
|
|
@@ -157,7 +157,6 @@ class SubconsciousRunner:
|
|
|
157
157
|
chat_obj.io_stream,
|
|
158
158
|
extra_args=chat_obj._interpreter._ava_args[1:],
|
|
159
159
|
extra_kwargs=chat_obj._interpreter._ava_kwargs,
|
|
160
|
-
exception_ignored=chat_obj._interpreter._exc_ignored,
|
|
161
160
|
)
|
|
162
161
|
|
|
163
162
|
if self._saved_dump is not None:
|
|
@@ -181,8 +180,7 @@ class SubconsciousRunner:
|
|
|
181
180
|
await self._post_process(chat_obj)
|
|
182
181
|
|
|
183
182
|
@staticmethod
|
|
184
|
-
def _is_native_thinking() -> bool:
|
|
185
|
-
preset = PresetManager().get_default_preset()
|
|
183
|
+
def _is_native_thinking(preset: ModelPreset) -> bool:
|
|
186
184
|
return (
|
|
187
185
|
preset.thinking_config is not None
|
|
188
186
|
and preset.thinking_config.thinking_type == "enabled"
|
{amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory/rethinking/tools.py
RENAMED
|
@@ -8,7 +8,6 @@ from typing import Any
|
|
|
8
8
|
|
|
9
9
|
from amrita_core import on_tools
|
|
10
10
|
from amrita_core.libchat import call_completion, get_last_response
|
|
11
|
-
from amrita_core.preset import PresetManager
|
|
12
11
|
from amrita_core.types import CONTENT_LIST_TYPE, Message
|
|
13
12
|
from chromadb import GetResult
|
|
14
13
|
from jinja2 import Template
|
|
@@ -308,7 +307,7 @@ async def _generate_send_content(intent: str, memory_context: str) -> str:
|
|
|
308
307
|
current_time=datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC"),
|
|
309
308
|
character_prompt=character_prompt,
|
|
310
309
|
)
|
|
311
|
-
preset =
|
|
310
|
+
preset = await _state.get_preset()
|
|
312
311
|
messages: CONTENT_LIST_TYPE = [
|
|
313
312
|
Message(role="system", content=system_content),
|
|
314
313
|
Message(
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"""潜意识推理循环(rethinking 子包)。
|
|
2
|
-
|
|
3
|
-
导入此包时触发工具注册和 hook 注册。
|
|
4
|
-
注意:避免模块级导入 tools/runner 等会触发循环导入的子模块。
|
|
5
|
-
这些模块的副作用(@on_tools 注册、hook 注册)通过 hooks 和 tools 内部的延迟导入自动生效。
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from . import _state, backend, hooks, nodes, schemas, workflow
|
|
9
|
-
|
|
10
|
-
__all__ = [
|
|
11
|
-
"_state",
|
|
12
|
-
"backend",
|
|
13
|
-
"consts",
|
|
14
|
-
"hooks",
|
|
15
|
-
"nodes",
|
|
16
|
-
"runner",
|
|
17
|
-
"schemas",
|
|
18
|
-
"tools",
|
|
19
|
-
"workflow",
|
|
20
|
-
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory/rethinking/backend.py
RENAMED
|
File without changes
|
{amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory/rethinking/consts.py
RENAMED
|
File without changes
|
{amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory/rethinking/hooks.py
RENAMED
|
File without changes
|
{amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory/rethinking/nodes.py
RENAMED
|
File without changes
|
{amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory/rethinking/schemas.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{amrita_plugin_memory-0.2.5 → amrita_plugin_memory-0.2.7}/amrita_plugin_memory.egg-info/requires.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|