lionagi 0.17.7__py3-none-any.whl → 0.17.8__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.
- lionagi/service/hooks/_utils.py +4 -4
- lionagi/service/hooks/hook_event.py +17 -4
- lionagi/service/hooks/hook_registry.py +34 -15
- lionagi/version.py +1 -1
- {lionagi-0.17.7.dist-info → lionagi-0.17.8.dist-info}/METADATA +1 -1
- {lionagi-0.17.7.dist-info → lionagi-0.17.8.dist-info}/RECORD +8 -8
- {lionagi-0.17.7.dist-info → lionagi-0.17.8.dist-info}/WHEEL +0 -0
- {lionagi-0.17.7.dist-info → lionagi-0.17.8.dist-info}/licenses/LICENSE +0 -0
lionagi/service/hooks/_utils.py
CHANGED
@@ -25,16 +25,16 @@ def get_handler(d_: dict, k: str | type, get: bool = False, /):
|
|
25
25
|
if handler is not None:
|
26
26
|
if not is_coro_func(handler):
|
27
27
|
|
28
|
-
async def _func(
|
28
|
+
async def _func(*args, **kwargs):
|
29
29
|
await sleep(0)
|
30
|
-
return handler(
|
30
|
+
return handler(*args, **kwargs)
|
31
31
|
|
32
32
|
return _func
|
33
33
|
return handler
|
34
34
|
|
35
|
-
async def _func(
|
35
|
+
async def _func(*args, **_kwargs):
|
36
36
|
await sleep(0)
|
37
|
-
return
|
37
|
+
return args[0] if args else None
|
38
38
|
|
39
39
|
return _func
|
40
40
|
|
@@ -3,16 +3,21 @@
|
|
3
3
|
|
4
4
|
from __future__ import annotations
|
5
5
|
|
6
|
-
from typing import Any
|
6
|
+
from typing import TYPE_CHECKING, Any
|
7
7
|
|
8
8
|
import anyio
|
9
|
-
from pydantic import Field, PrivateAttr
|
9
|
+
from pydantic import Field, PrivateAttr, field_validator
|
10
10
|
|
11
11
|
from lionagi.ln.concurrency import fail_after, get_cancelled_exc_class
|
12
12
|
from lionagi.protocols.types import Event, EventStatus
|
13
13
|
|
14
14
|
from ._types import AssosiatedEventInfo, HookEventTypes
|
15
|
-
|
15
|
+
|
16
|
+
if TYPE_CHECKING:
|
17
|
+
from .hook_registry import HookRegistry
|
18
|
+
else:
|
19
|
+
# Import at runtime for Pydantic
|
20
|
+
from .hook_registry import HookRegistry
|
16
21
|
|
17
22
|
|
18
23
|
class HookEvent(Event):
|
@@ -27,6 +32,12 @@ class HookEvent(Event):
|
|
27
32
|
|
28
33
|
assosiated_event_info: AssosiatedEventInfo | None = None
|
29
34
|
|
35
|
+
@field_validator("exit", mode="before")
|
36
|
+
def _validate_exit(cls, v: Any) -> bool:
|
37
|
+
if v is None:
|
38
|
+
return False
|
39
|
+
return v
|
40
|
+
|
30
41
|
async def invoke(self):
|
31
42
|
start = anyio.current_time()
|
32
43
|
self.execution.status = EventStatus.PROCESSING
|
@@ -61,7 +72,9 @@ class HookEvent(Event):
|
|
61
72
|
self.execution.status = EventStatus.FAILED
|
62
73
|
self.execution.response = None
|
63
74
|
self.execution.error = str(e)
|
64
|
-
|
75
|
+
# Registry/wiring failures should obey the configured policy
|
76
|
+
self._exit_cause = e
|
77
|
+
self._should_exit = bool(self.exit)
|
65
78
|
|
66
79
|
finally:
|
67
80
|
self.execution.duration = anyio.current_time() - start
|
@@ -10,7 +10,7 @@ from lionagi.protocols.types import Event, EventStatus
|
|
10
10
|
from lionagi.utils import UNDEFINED
|
11
11
|
|
12
12
|
from ._types import HookDict, HookEventTypes, StreamHandlers
|
13
|
-
from ._utils import validate_hooks, validate_stream_handlers
|
13
|
+
from ._utils import get_handler, validate_hooks, validate_stream_handlers
|
14
14
|
|
15
15
|
E = TypeVar("E", bound=Event)
|
16
16
|
|
@@ -48,17 +48,17 @@ class HookRegistry:
|
|
48
48
|
raise RuntimeError(
|
49
49
|
"Either hook_type or chunk_type must be provided"
|
50
50
|
)
|
51
|
-
if ht_ and (
|
52
|
-
validate_hooks({ht_:
|
51
|
+
if ht_ and (self._hooks.get(ht_)):
|
52
|
+
validate_hooks({ht_: self._hooks[ht_]})
|
53
|
+
h = get_handler(self._hooks, ht_, True)
|
53
54
|
return await h(ev_, **kw)
|
54
55
|
elif not ct_:
|
55
56
|
raise RuntimeError(
|
56
57
|
"Hook type is required when chunk_type is not provided"
|
57
58
|
)
|
58
59
|
else:
|
59
|
-
validate_stream_handlers(
|
60
|
-
|
61
|
-
)
|
60
|
+
validate_stream_handlers({ct_: self._stream_handlers.get(ct_)})
|
61
|
+
h = get_handler(self._stream_handlers, ct_, True)
|
62
62
|
return await h(ev_, ct_, ch_, **kw)
|
63
63
|
|
64
64
|
async def _call_stream_handler(
|
@@ -69,8 +69,8 @@ class HookRegistry:
|
|
69
69
|
/,
|
70
70
|
**kw,
|
71
71
|
):
|
72
|
-
|
73
|
-
|
72
|
+
validate_stream_handlers({ct_: self._stream_handlers.get(ct_)})
|
73
|
+
handler = get_handler(self._stream_handlers, ct_, True)
|
74
74
|
return await handler(ev_, ct_, ch_, **kw)
|
75
75
|
|
76
76
|
async def pre_event_create(
|
@@ -94,6 +94,7 @@ class HookRegistry:
|
|
94
94
|
None,
|
95
95
|
None,
|
96
96
|
event_type,
|
97
|
+
exit=exit,
|
97
98
|
**kw,
|
98
99
|
)
|
99
100
|
return (res, False, EventStatus.COMPLETED)
|
@@ -119,6 +120,7 @@ class HookRegistry:
|
|
119
120
|
None,
|
120
121
|
None,
|
121
122
|
event,
|
123
|
+
exit=exit,
|
122
124
|
**kw,
|
123
125
|
)
|
124
126
|
return (res, False, EventStatus.COMPLETED)
|
@@ -129,7 +131,7 @@ class HookRegistry:
|
|
129
131
|
|
130
132
|
async def post_invocation(
|
131
133
|
self, event: E, /, exit: bool = False, **kw
|
132
|
-
) -> tuple[None | Exception, bool, EventStatus
|
134
|
+
) -> tuple[None | Exception, bool, EventStatus]:
|
133
135
|
"""Hook to be called right after event finished its execution.
|
134
136
|
It can either raise an exception to abort the event invocation or pass to continue (status: aborted).
|
135
137
|
It cannot modify the event itself, and won't be able to access the event instance.
|
@@ -140,6 +142,7 @@ class HookRegistry:
|
|
140
142
|
None,
|
141
143
|
None,
|
142
144
|
event,
|
145
|
+
exit=exit,
|
143
146
|
**kw,
|
144
147
|
)
|
145
148
|
return (res, False, EventStatus.COMPLETED)
|
@@ -163,6 +166,7 @@ class HookRegistry:
|
|
163
166
|
chunk_type,
|
164
167
|
chunk,
|
165
168
|
None,
|
169
|
+
exit=exit,
|
166
170
|
**kw,
|
167
171
|
)
|
168
172
|
return (res, False, None)
|
@@ -191,20 +195,35 @@ class HookRegistry:
|
|
191
195
|
if hook_type is None and chunk_type is None:
|
192
196
|
raise ValueError("Either method or chunk_type must be provided")
|
193
197
|
if hook_type:
|
194
|
-
|
195
|
-
meta
|
198
|
+
# Align with AssosiatedEventInfo
|
199
|
+
meta = {"lion_class": event_like.class_name(full=True)}
|
196
200
|
match hook_type:
|
197
201
|
case HookEventTypes.PreEventCreate:
|
198
|
-
return
|
202
|
+
return (
|
203
|
+
await self.pre_event_create(
|
204
|
+
event_like, exit=exit, **kw
|
205
|
+
),
|
206
|
+
meta,
|
207
|
+
)
|
199
208
|
case HookEventTypes.PreInvocation:
|
200
209
|
meta["event_id"] = str(event_like.id)
|
201
210
|
meta["event_created_at"] = event_like.created_at
|
202
|
-
return
|
211
|
+
return (
|
212
|
+
await self.pre_invocation(event_like, exit=exit, **kw),
|
213
|
+
meta,
|
214
|
+
)
|
203
215
|
case HookEventTypes.PostInvocation:
|
204
216
|
meta["event_id"] = str(event_like.id)
|
205
217
|
meta["event_created_at"] = event_like.created_at
|
206
|
-
return
|
207
|
-
|
218
|
+
return (
|
219
|
+
await self.post_invocation(
|
220
|
+
event_like, exit=exit, **kw
|
221
|
+
),
|
222
|
+
meta,
|
223
|
+
)
|
224
|
+
return await self.handle_streaming_chunk(
|
225
|
+
chunk_type, chunk, exit=exit, **kw
|
226
|
+
)
|
208
227
|
|
209
228
|
def _can_handle(
|
210
229
|
self,
|
lionagi/version.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "0.17.
|
1
|
+
__version__ = "0.17.8"
|
@@ -5,7 +5,7 @@ lionagi/_types.py,sha256=COWRrmstmABGKKn-h_cKiAREGsMp_Ik49OdR4lSS3P8,1263
|
|
5
5
|
lionagi/config.py,sha256=yGnzj5D14B2TBhqVeyp1uccvAK6mk4hm0QA8dAEJUeQ,4776
|
6
6
|
lionagi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
7
|
lionagi/utils.py,sha256=yRHKN_v9xRnUa-nYg1lTpCCK2wNDg4pCpicUEIyFwKg,7084
|
8
|
-
lionagi/version.py,sha256=
|
8
|
+
lionagi/version.py,sha256=H2Y9686JbmOVItv-s7YNC6eYseSRZPwHCIXOoDgBIEM,23
|
9
9
|
lionagi/adapters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
10
|
lionagi/adapters/_utils.py,sha256=sniMG1LDDkwJNzUF2K32jv7rA6Y1QcohgyNclYsptzI,453
|
11
11
|
lionagi/adapters/async_postgres_adapter.py,sha256=2XlxYNPow78dFHIQs8W1oJ2zkVD5Udn3aynMBF9Nf3k,3498
|
@@ -173,9 +173,9 @@ lionagi/service/connections/providers/perplexity_.py,sha256=1GMmxAXsKGsB-xlqxO6h
|
|
173
173
|
lionagi/service/connections/providers/types.py,sha256=omKWbmJYu_ozK_qJLcxQezVcauXTqhp4ClOWAyENEFU,807
|
174
174
|
lionagi/service/hooks/__init__.py,sha256=WCfzc-Aco5PkKufDMvSYxbrLqlEvmOsaZELlWKAuG2w,464
|
175
175
|
lionagi/service/hooks/_types.py,sha256=e1vmA24arGKweS45jEXK6pw8Ysk2NOvlBc6m1ABsKws,1255
|
176
|
-
lionagi/service/hooks/_utils.py,sha256=
|
177
|
-
lionagi/service/hooks/hook_event.py,sha256=
|
178
|
-
lionagi/service/hooks/hook_registry.py,sha256=
|
176
|
+
lionagi/service/hooks/_utils.py,sha256=VVPWL7HE61xc4UPYF0DIuMeFhVb3gSzPNJTNZK7ssqA,2627
|
177
|
+
lionagi/service/hooks/hook_event.py,sha256=cJCnE3dQnOvjPj9wptBvPGGJx2LQqtXgwPMU8JLQSkM,2831
|
178
|
+
lionagi/service/hooks/hook_registry.py,sha256=V25UwTVoOixL1CKfRAyR0__fggCvF5pBK5fF4PzcZd8,8527
|
179
179
|
lionagi/service/hooks/hooked_event.py,sha256=D_1HtWCH3CriNlmsksi5lerXuF_LV2lbktcEdhZqXw0,4339
|
180
180
|
lionagi/service/third_party/README.md,sha256=qFjWnI8rmLivIyr6Tc-hRZh-rQwntROp76af4MBNJJc,2214
|
181
181
|
lionagi/service/third_party/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -193,7 +193,7 @@ lionagi/tools/base.py,sha256=hEGnE4MD0CM4UqnF0xsDRKB0aM-pyrTFHl8utHhyJLU,1897
|
|
193
193
|
lionagi/tools/types.py,sha256=XtJLY0m-Yi_ZLWhm0KycayvqMCZd--HxfQ0x9vFUYDE,230
|
194
194
|
lionagi/tools/file/__init__.py,sha256=5y5joOZzfFWERl75auAcNcKC3lImVJ5ZZGvvHZUFCJM,112
|
195
195
|
lionagi/tools/file/reader.py,sha256=Q9x1UP7YmBqN53e1kUN68OmIs-D1m9EM9VVbWfM35js,9658
|
196
|
-
lionagi-0.17.
|
197
|
-
lionagi-0.17.
|
198
|
-
lionagi-0.17.
|
199
|
-
lionagi-0.17.
|
196
|
+
lionagi-0.17.8.dist-info/METADATA,sha256=d_5YV53ajCQjD7HDhICy31gl4NjaJlDCt2n6pXHF4wg,23448
|
197
|
+
lionagi-0.17.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
198
|
+
lionagi-0.17.8.dist-info/licenses/LICENSE,sha256=VXFWsdoN5AAknBCgFqQNgPWYx7OPp-PFEP961zGdOjc,11288
|
199
|
+
lionagi-0.17.8.dist-info/RECORD,,
|
File without changes
|
File without changes
|