ommlds 0.0.0.dev489__py3-none-any.whl → 0.0.0.dev491__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.
- ommlds/.omlish-manifests.json +3 -3
- ommlds/README.md +11 -0
- ommlds/__about__.py +1 -1
- ommlds/backends/ollama/_dataclasses.py +53 -23
- ommlds/backends/ollama/protocol.py +3 -0
- ommlds/cli/_dataclasses.py +835 -356
- ommlds/cli/main.py +80 -41
- ommlds/cli/rendering/types.py +6 -0
- ommlds/cli/sessions/chat/configs.py +4 -12
- ommlds/cli/sessions/chat/{chat → drivers}/ai/configs.py +3 -1
- ommlds/cli/sessions/chat/drivers/ai/events.py +57 -0
- ommlds/cli/sessions/chat/{chat → drivers}/ai/inject.py +10 -3
- ommlds/cli/sessions/chat/{chat → drivers}/ai/rendering.py +1 -1
- ommlds/cli/sessions/chat/{chat → drivers}/ai/services.py +1 -1
- ommlds/cli/sessions/chat/{chat → drivers}/ai/tools.py +1 -1
- ommlds/cli/sessions/chat/{chat → drivers}/ai/types.py +9 -0
- ommlds/cli/sessions/chat/drivers/configs.py +25 -0
- ommlds/cli/sessions/chat/drivers/driver.py +49 -0
- ommlds/cli/sessions/chat/drivers/events/inject.py +27 -0
- ommlds/cli/sessions/chat/drivers/events/injection.py +14 -0
- ommlds/cli/sessions/chat/drivers/events/manager.py +16 -0
- ommlds/cli/sessions/chat/drivers/events/types.py +38 -0
- ommlds/cli/sessions/chat/drivers/inject.py +69 -0
- ommlds/cli/sessions/chat/{chat → drivers}/state/inject.py +3 -3
- ommlds/cli/sessions/chat/{chat → drivers}/state/types.py +1 -1
- ommlds/cli/sessions/chat/{tools → drivers/tools}/configs.py +2 -2
- ommlds/cli/sessions/chat/drivers/tools/confirmation.py +44 -0
- ommlds/cli/sessions/chat/{tools → drivers/tools}/execution.py +3 -4
- ommlds/cli/sessions/chat/{tools → drivers/tools}/fs/inject.py +3 -3
- ommlds/cli/sessions/chat/{tools → drivers/tools}/inject.py +4 -12
- ommlds/cli/sessions/chat/{tools → drivers/tools}/injection.py +1 -1
- ommlds/cli/sessions/chat/{tools → drivers/tools}/rendering.py +3 -3
- ommlds/cli/sessions/chat/{tools → drivers/tools}/todo/inject.py +3 -3
- ommlds/cli/sessions/chat/{tools → drivers/tools}/weather/tools.py +1 -1
- ommlds/cli/sessions/chat/drivers/types.py +10 -0
- ommlds/cli/sessions/chat/{chat → drivers}/user/configs.py +0 -2
- ommlds/cli/sessions/chat/drivers/user/inject.py +40 -0
- ommlds/cli/sessions/chat/inject.py +4 -32
- ommlds/cli/sessions/chat/interfaces/bare/inject.py +61 -0
- ommlds/cli/sessions/chat/interfaces/bare/interactive.py +41 -0
- ommlds/cli/sessions/chat/{interface/bare/interface.py → interfaces/bare/oneshot.py} +5 -3
- ommlds/cli/sessions/chat/{tools/confirmation.py → interfaces/bare/tools.py} +3 -22
- ommlds/cli/sessions/chat/{interface → interfaces}/bare/user.py +1 -1
- ommlds/cli/sessions/chat/{interface → interfaces}/configs.py +8 -0
- ommlds/cli/sessions/chat/interfaces/textual/__init__.py +0 -0
- ommlds/cli/sessions/chat/interfaces/textual/app.py +217 -0
- ommlds/cli/sessions/chat/interfaces/textual/inject.py +67 -0
- ommlds/cli/sessions/chat/{interface → interfaces}/textual/interface.py +0 -3
- ommlds/cli/sessions/chat/interfaces/textual/styles/__init__.py +29 -0
- ommlds/cli/sessions/chat/interfaces/textual/styles/input.tcss +51 -0
- ommlds/cli/sessions/chat/interfaces/textual/styles/markdown.tcss +7 -0
- ommlds/cli/sessions/chat/interfaces/textual/styles/messages.tcss +104 -0
- ommlds/cli/sessions/chat/interfaces/textual/widgets/__init__.py +0 -0
- ommlds/cli/sessions/chat/interfaces/textual/widgets/input.py +36 -0
- ommlds/cli/sessions/chat/interfaces/textual/widgets/messages.py +114 -0
- ommlds/cli/sessions/chat/session.py +1 -1
- ommlds/minichain/backends/impls/ollama/chat.py +24 -56
- ommlds/minichain/backends/impls/ollama/protocol.py +144 -0
- ommlds/nanochat/rustbpe/README.md +9 -0
- {ommlds-0.0.0.dev489.dist-info → ommlds-0.0.0.dev491.dist-info}/METADATA +6 -6
- {ommlds-0.0.0.dev489.dist-info → ommlds-0.0.0.dev491.dist-info}/RECORD +91 -73
- ommlds/cli/sessions/chat/chat/user/inject.py +0 -52
- ommlds/cli/sessions/chat/chat/user/oneshot.py +0 -25
- ommlds/cli/sessions/chat/chat/user/types.py +0 -15
- ommlds/cli/sessions/chat/driver.py +0 -43
- ommlds/cli/sessions/chat/interface/bare/inject.py +0 -32
- ommlds/cli/sessions/chat/interface/textual/app.py +0 -191
- ommlds/cli/sessions/chat/interface/textual/inject.py +0 -27
- ommlds/cli/sessions/chat/interface/textual/user.py +0 -20
- /ommlds/cli/sessions/chat/{chat → drivers}/__init__.py +0 -0
- /ommlds/cli/sessions/chat/{chat → drivers}/ai/__init__.py +0 -0
- /ommlds/cli/sessions/chat/{chat → drivers}/ai/injection.py +0 -0
- /ommlds/cli/sessions/chat/{chat/state → drivers/events}/__init__.py +0 -0
- /ommlds/cli/sessions/chat/{chat/user → drivers/phases}/__init__.py +0 -0
- /ommlds/cli/sessions/chat/{phases → drivers/phases}/inject.py +0 -0
- /ommlds/cli/sessions/chat/{phases → drivers/phases}/injection.py +0 -0
- /ommlds/cli/sessions/chat/{phases → drivers/phases}/manager.py +0 -0
- /ommlds/cli/sessions/chat/{phases → drivers/phases}/types.py +0 -0
- /ommlds/cli/sessions/chat/{interface → drivers/state}/__init__.py +0 -0
- /ommlds/cli/sessions/chat/{chat → drivers}/state/configs.py +0 -0
- /ommlds/cli/sessions/chat/{chat → drivers}/state/inmemory.py +0 -0
- /ommlds/cli/sessions/chat/{chat → drivers}/state/storage.py +0 -0
- /ommlds/cli/sessions/chat/{interface/bare → drivers/tools}/__init__.py +0 -0
- /ommlds/cli/sessions/chat/{interface/textual → drivers/tools/fs}/__init__.py +0 -0
- /ommlds/cli/sessions/chat/{tools → drivers/tools}/fs/configs.py +0 -0
- /ommlds/cli/sessions/chat/{phases → drivers/tools/todo}/__init__.py +0 -0
- /ommlds/cli/sessions/chat/{tools → drivers/tools}/todo/configs.py +0 -0
- /ommlds/cli/sessions/chat/{tools → drivers/tools/weather}/__init__.py +0 -0
- /ommlds/cli/sessions/chat/{tools → drivers/tools}/weather/configs.py +0 -0
- /ommlds/cli/sessions/chat/{tools → drivers/tools}/weather/inject.py +0 -0
- /ommlds/cli/sessions/chat/{tools/fs → drivers/user}/__init__.py +0 -0
- /ommlds/cli/sessions/chat/{tools/todo → interfaces}/__init__.py +0 -0
- /ommlds/cli/sessions/chat/{tools/weather → interfaces/bare}/__init__.py +0 -0
- /ommlds/cli/sessions/chat/{interface → interfaces}/base.py +0 -0
- /ommlds/cli/sessions/chat/{interface → interfaces}/inject.py +0 -0
- {ommlds-0.0.0.dev489.dist-info → ommlds-0.0.0.dev491.dist-info}/WHEEL +0 -0
- {ommlds-0.0.0.dev489.dist-info → ommlds-0.0.0.dev491.dist-info}/entry_points.txt +0 -0
- {ommlds-0.0.0.dev489.dist-info → ommlds-0.0.0.dev491.dist-info}/licenses/LICENSE +0 -0
- {ommlds-0.0.0.dev489.dist-info → ommlds-0.0.0.dev491.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import abc
|
|
2
|
+
import typing as ta
|
|
3
|
+
|
|
4
|
+
from omlish import lang
|
|
5
|
+
|
|
6
|
+
from ...... import minichain as mc
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
##
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ToolExecutionRequestDeniedError(Exception):
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ToolExecutionConfirmation(lang.Abstract):
|
|
17
|
+
@abc.abstractmethod
|
|
18
|
+
def confirm_tool_execution_or_raise(
|
|
19
|
+
self,
|
|
20
|
+
use: 'mc.ToolUse',
|
|
21
|
+
entry: 'mc.ToolCatalogEntry',
|
|
22
|
+
) -> ta.Awaitable[None]:
|
|
23
|
+
raise NotImplementedError
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
##
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class AlwaysDenyToolExecutionConfirmation(ToolExecutionConfirmation):
|
|
30
|
+
async def confirm_tool_execution_or_raise(
|
|
31
|
+
self,
|
|
32
|
+
use: 'mc.ToolUse',
|
|
33
|
+
entry: 'mc.ToolCatalogEntry',
|
|
34
|
+
) -> None:
|
|
35
|
+
raise ToolExecutionRequestDeniedError
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class UnsafeAlwaysAllowToolExecutionConfirmation(ToolExecutionConfirmation):
|
|
39
|
+
async def confirm_tool_execution_or_raise(
|
|
40
|
+
self,
|
|
41
|
+
use: 'mc.ToolUse',
|
|
42
|
+
entry: 'mc.ToolCatalogEntry',
|
|
43
|
+
) -> None:
|
|
44
|
+
pass
|
|
@@ -4,7 +4,7 @@ import typing as ta
|
|
|
4
4
|
from omlish import check
|
|
5
5
|
from omlish import lang
|
|
6
6
|
|
|
7
|
-
from
|
|
7
|
+
from ...... import minichain as mc
|
|
8
8
|
from .confirmation import ToolExecutionConfirmation
|
|
9
9
|
|
|
10
10
|
|
|
@@ -37,7 +37,7 @@ class ToolUseExecutorImpl(ToolUseExecutor):
|
|
|
37
37
|
*,
|
|
38
38
|
catalog: 'mc.ToolCatalog',
|
|
39
39
|
ctx_provider: ToolContextProvider,
|
|
40
|
-
confirmation: ToolExecutionConfirmation
|
|
40
|
+
confirmation: ToolExecutionConfirmation,
|
|
41
41
|
) -> None:
|
|
42
42
|
super().__init__()
|
|
43
43
|
|
|
@@ -52,8 +52,7 @@ class ToolUseExecutorImpl(ToolUseExecutor):
|
|
|
52
52
|
) -> 'mc.ToolUseResultMessage':
|
|
53
53
|
tce = self._catalog.by_name[check.non_empty_str(use.name)]
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
await self._confirmation.confirm_tool_execution_or_raise(use, tce)
|
|
55
|
+
await self._confirmation.confirm_tool_execution_or_raise(use, tce)
|
|
57
56
|
|
|
58
57
|
return await mc.execute_tool_use(
|
|
59
58
|
mc.ToolContext(
|
|
@@ -12,9 +12,9 @@ from .configs import FsToolSetConfig
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
def bind_fs_tools(cfg: FsToolSetConfig) -> inj.Elements:
|
|
15
|
-
from
|
|
16
|
-
from
|
|
17
|
-
from
|
|
15
|
+
from .......minichain.lib.fs.context import FsContext
|
|
16
|
+
from .......minichain.lib.fs.tools.ls import ls_tool
|
|
17
|
+
from .......minichain.lib.fs.tools.read import read_tool
|
|
18
18
|
|
|
19
19
|
return inj.as_elements(
|
|
20
20
|
tool_catalog_entries().bind_item_consts(
|
|
@@ -2,15 +2,14 @@ from omlish import check
|
|
|
2
2
|
from omlish import inject as inj
|
|
3
3
|
from omlish import lang
|
|
4
4
|
|
|
5
|
-
from
|
|
6
|
-
from
|
|
5
|
+
from ...... import minichain as mc
|
|
6
|
+
from ..configs import ToolsConfig
|
|
7
7
|
from .injection import ToolSetBinder
|
|
8
8
|
from .injection import tool_catalog_entries
|
|
9
9
|
from .injection import tool_context_providers
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
with lang.auto_proxy_import(globals()):
|
|
13
|
-
from . import confirmation as _confirmation
|
|
14
13
|
from . import execution as _execution
|
|
15
14
|
from . import rendering as _rendering
|
|
16
15
|
|
|
@@ -58,23 +57,16 @@ def bind_tools(cfg: ToolsConfig = ToolsConfig()) -> inj.Elements:
|
|
|
58
57
|
|
|
59
58
|
els.append(exec_stack.push_bind(to_ctor=_execution.ToolUseExecutorImpl, singleton=True))
|
|
60
59
|
|
|
61
|
-
if
|
|
60
|
+
if cfg.verbose:
|
|
61
|
+
els.append(exec_stack.push_bind(to_ctor=_rendering.ArgsRenderingToolUseExecutor, singleton=True))
|
|
62
62
|
els.append(exec_stack.push_bind(to_ctor=_rendering.ResultRenderingToolUseExecutor, singleton=True))
|
|
63
63
|
|
|
64
|
-
if cfg.dangerous_no_confirmation:
|
|
65
|
-
els.append(exec_stack.push_bind(to_ctor=_rendering.ArgsRenderingToolUseExecutor, singleton=True))
|
|
66
|
-
|
|
67
64
|
els.extend([
|
|
68
65
|
inj.bind(_execution.ToolUseExecutor, to_key=exec_stack.top),
|
|
69
66
|
])
|
|
70
67
|
|
|
71
68
|
#
|
|
72
69
|
|
|
73
|
-
if not cfg.dangerous_no_confirmation:
|
|
74
|
-
els.append(inj.bind(_confirmation.ToolExecutionConfirmation, to_ctor=_confirmation.InteractiveToolExecutionConfirmation, singleton=True)) # noqa
|
|
75
|
-
|
|
76
|
-
#
|
|
77
|
-
|
|
78
70
|
els.extend([
|
|
79
71
|
tool_context_providers().bind_items_provider(singleton=True),
|
|
80
72
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import typing as ta
|
|
2
2
|
|
|
3
|
-
from
|
|
4
|
-
from
|
|
5
|
-
from .execution import ToolUseExecutor
|
|
3
|
+
from ...... import minichain as mc
|
|
4
|
+
from .....rendering.types import ContentRendering
|
|
5
|
+
from ...drivers.tools.execution import ToolUseExecutor
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
##
|
|
@@ -10,9 +10,9 @@ from .configs import TodoToolSetConfig
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
def bind_todo_tools(cfg: TodoToolSetConfig) -> inj.Elements:
|
|
13
|
-
from
|
|
14
|
-
from
|
|
15
|
-
from
|
|
13
|
+
from .......minichain.lib.todo.context import TodoContext
|
|
14
|
+
from .......minichain.lib.todo.tools.read import todo_read_tool
|
|
15
|
+
from .......minichain.lib.todo.tools.write import todo_write_tool
|
|
16
16
|
|
|
17
17
|
return inj.as_elements(
|
|
18
18
|
tool_catalog_entries().bind_item_consts(
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from omlish import inject as inj
|
|
2
|
+
from omlish import lang
|
|
3
|
+
|
|
4
|
+
from ...... import minichain as mc
|
|
5
|
+
from ..phases.injection import phase_callbacks
|
|
6
|
+
from ..phases.types import ChatPhase
|
|
7
|
+
from ..phases.types import ChatPhaseCallback
|
|
8
|
+
from .configs import UserConfig
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
with lang.auto_proxy_import(globals()):
|
|
12
|
+
from .. import driver as _driver
|
|
13
|
+
from ..state import types as _state
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
##
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def bind_user(cfg: UserConfig = UserConfig()) -> inj.Elements:
|
|
20
|
+
els: list[inj.Elemental] = []
|
|
21
|
+
|
|
22
|
+
if cfg.initial_system_content is not None:
|
|
23
|
+
async def add_initial_system_content(cm: '_state.ChatStateManager') -> None:
|
|
24
|
+
await cm.extend_chat([mc.SystemMessage(cfg.initial_system_content)])
|
|
25
|
+
|
|
26
|
+
els.append(phase_callbacks().bind_item(to_fn=inj.KwargsTarget.of(
|
|
27
|
+
lambda cm: ChatPhaseCallback(ChatPhase.STARTED, lambda: add_initial_system_content(cm)),
|
|
28
|
+
cm=_state.ChatStateManager,
|
|
29
|
+
)))
|
|
30
|
+
|
|
31
|
+
if cfg.initial_user_content is not None:
|
|
32
|
+
async def add_initial_user_content(ca: '_driver.ChatDriver') -> None:
|
|
33
|
+
await ca.send_user_messages([mc.UserMessage(cfg.initial_user_content)])
|
|
34
|
+
|
|
35
|
+
els.append(phase_callbacks().bind_item(to_fn=inj.KwargsTarget.of(
|
|
36
|
+
lambda ca: ChatPhaseCallback(ChatPhase.STARTED, lambda: add_initial_user_content(ca())),
|
|
37
|
+
ca=inj.Late[_driver.ChatDriver],
|
|
38
|
+
)))
|
|
39
|
+
|
|
40
|
+
return inj.as_elements(*els)
|
|
@@ -2,23 +2,15 @@ from omlish import dataclasses as dc
|
|
|
2
2
|
from omlish import inject as inj
|
|
3
3
|
from omlish import lang
|
|
4
4
|
|
|
5
|
-
from ...backends.types import DefaultBackendName
|
|
6
5
|
from ..base import Session
|
|
7
|
-
from .configs import DEFAULT_BACKEND
|
|
8
6
|
from .configs import ChatConfig
|
|
9
7
|
|
|
10
8
|
|
|
11
9
|
with lang.auto_proxy_import(globals()):
|
|
12
|
-
from ...backends import inject as _backends
|
|
13
10
|
from ...rendering import inject as _rendering
|
|
14
|
-
from . import driver as _driver
|
|
15
11
|
from . import session as _session
|
|
16
|
-
from .
|
|
17
|
-
from .
|
|
18
|
-
from .chat.user import inject as _chat_user
|
|
19
|
-
from .interface import inject as _interface
|
|
20
|
-
from .phases import inject as _phases
|
|
21
|
-
from .tools import inject as _tools
|
|
12
|
+
from .drivers import inject as _drivers
|
|
13
|
+
from .interfaces import inject as _interfaces
|
|
22
14
|
|
|
23
15
|
|
|
24
16
|
##
|
|
@@ -30,27 +22,11 @@ def bind_chat(cfg: ChatConfig) -> inj.Elements:
|
|
|
30
22
|
#
|
|
31
23
|
|
|
32
24
|
els.extend([
|
|
33
|
-
|
|
25
|
+
_drivers.bind_driver(cfg.driver),
|
|
34
26
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
_chat_user.bind_user(cfg.user),
|
|
38
|
-
|
|
39
|
-
_chat_state.bind_state(cfg.state),
|
|
40
|
-
|
|
41
|
-
_interface.bind_interface(cfg.interface),
|
|
42
|
-
|
|
43
|
-
_phases.bind_phases(),
|
|
27
|
+
_interfaces.bind_interface(cfg.interface),
|
|
44
28
|
|
|
45
29
|
_rendering.bind_rendering(cfg.rendering),
|
|
46
|
-
|
|
47
|
-
_tools.bind_tools(cfg.tools),
|
|
48
|
-
])
|
|
49
|
-
|
|
50
|
-
#
|
|
51
|
-
|
|
52
|
-
els.extend([
|
|
53
|
-
inj.bind(_driver.ChatDriver, singleton=True),
|
|
54
30
|
])
|
|
55
31
|
|
|
56
32
|
#
|
|
@@ -62,8 +38,4 @@ def bind_chat(cfg: ChatConfig) -> inj.Elements:
|
|
|
62
38
|
|
|
63
39
|
#
|
|
64
40
|
|
|
65
|
-
els.append(inj.bind(DefaultBackendName, to_const=DEFAULT_BACKEND))
|
|
66
|
-
|
|
67
|
-
#
|
|
68
|
-
|
|
69
41
|
return inj.as_elements(*els)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
from omlish import inject as inj
|
|
2
|
+
from omlish import lang
|
|
3
|
+
|
|
4
|
+
from ..base import ChatInterface
|
|
5
|
+
from ..configs import InterfaceConfig
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
with lang.auto_proxy_import(globals()):
|
|
9
|
+
from .....inputs import asyncs as _inputs_asyncs
|
|
10
|
+
from .....inputs import sync as _inputs_sync
|
|
11
|
+
from ...drivers.tools import confirmation as _tools_confirmation
|
|
12
|
+
from . import interactive as _interactive
|
|
13
|
+
from . import oneshot as _oneshot
|
|
14
|
+
from . import tools as _tools
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
##
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def bind_bare(cfg: InterfaceConfig = InterfaceConfig()) -> inj.Elements:
|
|
21
|
+
els: list[inj.Elemental] = []
|
|
22
|
+
|
|
23
|
+
#
|
|
24
|
+
|
|
25
|
+
if cfg.interactive:
|
|
26
|
+
els.extend([
|
|
27
|
+
inj.bind(_interactive.InteractiveBareChatInterface, singleton=True),
|
|
28
|
+
inj.bind(ChatInterface, to_key=_interactive.InteractiveBareChatInterface),
|
|
29
|
+
])
|
|
30
|
+
|
|
31
|
+
els.extend([
|
|
32
|
+
inj.bind(_inputs_sync.SyncStringInput, to_const=_inputs_sync.InputSyncStringInput(use_readline=cfg.use_readline)), # noqa
|
|
33
|
+
inj.bind(_inputs_asyncs.AsyncStringInput, to_ctor=_inputs_asyncs.ThreadAsyncStringInput, singleton=True),
|
|
34
|
+
])
|
|
35
|
+
|
|
36
|
+
else:
|
|
37
|
+
els.extend([
|
|
38
|
+
inj.bind(_oneshot.OneshotBareChatInterface, singleton=True),
|
|
39
|
+
inj.bind(ChatInterface, to_key=_oneshot.OneshotBareChatInterface),
|
|
40
|
+
])
|
|
41
|
+
|
|
42
|
+
#
|
|
43
|
+
|
|
44
|
+
if cfg.enable_tools:
|
|
45
|
+
if cfg.dangerous_no_tool_confirmation:
|
|
46
|
+
els.append(inj.bind(
|
|
47
|
+
_tools_confirmation.ToolExecutionConfirmation,
|
|
48
|
+
to_ctor=_tools_confirmation.UnsafeAlwaysAllowToolExecutionConfirmation,
|
|
49
|
+
singleton=True,
|
|
50
|
+
))
|
|
51
|
+
|
|
52
|
+
else:
|
|
53
|
+
els.append(inj.bind(
|
|
54
|
+
_tools_confirmation.ToolExecutionConfirmation,
|
|
55
|
+
to_ctor=_tools.InteractiveToolExecutionConfirmation,
|
|
56
|
+
singleton=True,
|
|
57
|
+
))
|
|
58
|
+
|
|
59
|
+
#
|
|
60
|
+
|
|
61
|
+
return inj.as_elements(*els)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import typing as ta
|
|
2
|
+
|
|
3
|
+
from ...... import minichain as mc
|
|
4
|
+
from .....inputs.asyncs import AsyncStringInput
|
|
5
|
+
from .....inputs.asyncs import SyncAsyncStringInput
|
|
6
|
+
from .....inputs.sync import InputSyncStringInput
|
|
7
|
+
from ...drivers.driver import ChatDriver
|
|
8
|
+
from ..base import ChatInterface
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
##
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class InteractiveBareChatInterface(ChatInterface):
|
|
15
|
+
DEFAULT_STRING_INPUT: ta.ClassVar[AsyncStringInput] = SyncAsyncStringInput(InputSyncStringInput())
|
|
16
|
+
|
|
17
|
+
def __init__(
|
|
18
|
+
self,
|
|
19
|
+
*,
|
|
20
|
+
driver: ChatDriver,
|
|
21
|
+
string_input: AsyncStringInput | None = None,
|
|
22
|
+
) -> None:
|
|
23
|
+
super().__init__()
|
|
24
|
+
|
|
25
|
+
self._driver = driver
|
|
26
|
+
if string_input is None:
|
|
27
|
+
string_input = self.DEFAULT_STRING_INPUT
|
|
28
|
+
self._string_input = string_input
|
|
29
|
+
|
|
30
|
+
async def run(self) -> None:
|
|
31
|
+
await self._driver.start()
|
|
32
|
+
|
|
33
|
+
while True:
|
|
34
|
+
try:
|
|
35
|
+
s = await self._string_input()
|
|
36
|
+
except EOFError:
|
|
37
|
+
break
|
|
38
|
+
|
|
39
|
+
await self._driver.send_user_messages([mc.UserMessage(s)])
|
|
40
|
+
|
|
41
|
+
await self._driver.stop()
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
from ...driver import ChatDriver
|
|
1
|
+
from ...drivers.driver import ChatDriver
|
|
2
2
|
from ..base import ChatInterface
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
##
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
class
|
|
8
|
+
class OneshotBareChatInterface(ChatInterface):
|
|
9
9
|
def __init__(
|
|
10
10
|
self,
|
|
11
11
|
*,
|
|
@@ -16,4 +16,6 @@ class BareChatInterface(ChatInterface):
|
|
|
16
16
|
self._driver = driver
|
|
17
17
|
|
|
18
18
|
async def run(self) -> None:
|
|
19
|
-
await self._driver.
|
|
19
|
+
await self._driver.start()
|
|
20
|
+
|
|
21
|
+
await self._driver.stop()
|
|
@@ -1,28 +1,9 @@
|
|
|
1
|
-
import abc
|
|
2
|
-
import typing as ta
|
|
3
|
-
|
|
4
|
-
from omlish import lang
|
|
5
1
|
from omlish.formats import json
|
|
6
2
|
from omlish.term.confirm import confirm_action
|
|
7
3
|
|
|
8
|
-
from
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
##
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class ToolExecutionRequestDeniedError(Exception):
|
|
15
|
-
pass
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class ToolExecutionConfirmation(lang.Abstract):
|
|
19
|
-
@abc.abstractmethod
|
|
20
|
-
def confirm_tool_execution_or_raise(
|
|
21
|
-
self,
|
|
22
|
-
use: 'mc.ToolUse',
|
|
23
|
-
entry: 'mc.ToolCatalogEntry',
|
|
24
|
-
) -> ta.Awaitable[None]:
|
|
25
|
-
raise NotImplementedError
|
|
4
|
+
from ...... import minichain as mc
|
|
5
|
+
from ...drivers.tools.confirmation import ToolExecutionConfirmation
|
|
6
|
+
from ...drivers.tools.confirmation import ToolExecutionRequestDeniedError
|
|
26
7
|
|
|
27
8
|
|
|
28
9
|
##
|
|
@@ -4,7 +4,7 @@ from ...... import minichain as mc
|
|
|
4
4
|
from .....inputs.asyncs import AsyncStringInput
|
|
5
5
|
from .....inputs.asyncs import SyncAsyncStringInput
|
|
6
6
|
from .....inputs.sync import InputSyncStringInput
|
|
7
|
-
from ...
|
|
7
|
+
from ...drivers.user.types import UserChatInput
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
##
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
"""
|
|
2
|
+
TODO:
|
|
3
|
+
- obviously, subclasses of InterfaceConfig
|
|
4
|
+
- this is really just another instance of the whole `argparse -> config -> inject` flow
|
|
5
|
+
"""
|
|
1
6
|
import typing as ta
|
|
2
7
|
|
|
3
8
|
from omlish import dataclasses as dc
|
|
@@ -13,3 +18,6 @@ class InterfaceConfig:
|
|
|
13
18
|
use_textual: bool = False
|
|
14
19
|
|
|
15
20
|
use_readline: bool | ta.Literal['auto'] = 'auto'
|
|
21
|
+
|
|
22
|
+
enable_tools: bool = False
|
|
23
|
+
dangerous_no_tool_confirmation: bool = False
|
|
File without changes
|