mirascope 1.23.2__py3-none-any.whl → 1.23.3__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.
- mirascope/core/base/_utils/_fn_is_async.py +10 -1
- mirascope/integrations/_middleware_factory.py +3 -3
- {mirascope-1.23.2.dist-info → mirascope-1.23.3.dist-info}/METADATA +1 -1
- {mirascope-1.23.2.dist-info → mirascope-1.23.3.dist-info}/RECORD +6 -6
- {mirascope-1.23.2.dist-info → mirascope-1.23.3.dist-info}/WHEEL +0 -0
- {mirascope-1.23.2.dist-info → mirascope-1.23.3.dist-info}/licenses/LICENSE +0 -0
|
@@ -12,4 +12,13 @@ _R = TypeVar("_R")
|
|
|
12
12
|
def fn_is_async(
|
|
13
13
|
fn: Callable[..., Awaitable[_R] | Coroutine[Any, Any, _R]] | Callable[..., _R],
|
|
14
14
|
) -> TypeIs[Callable[..., Awaitable[_R]]]:
|
|
15
|
-
|
|
15
|
+
if inspect.iscoroutinefunction(fn):
|
|
16
|
+
return True
|
|
17
|
+
|
|
18
|
+
# Check if it's a wrapper around an `async def` function (using functools.wraps).
|
|
19
|
+
_fn = fn
|
|
20
|
+
while hasattr(_fn, "__wrapped__"):
|
|
21
|
+
_fn = _fn.__wrapped__ # pyright: ignore[reportFunctionMemberAccess]
|
|
22
|
+
if inspect.iscoroutinefunction(_fn):
|
|
23
|
+
return True
|
|
24
|
+
return False
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"""The `middleware_factory` method for handling the call response."""
|
|
2
2
|
|
|
3
|
-
import inspect
|
|
4
3
|
from collections.abc import AsyncGenerator, Awaitable, Callable, Generator
|
|
5
4
|
from contextlib import AbstractContextManager, contextmanager
|
|
6
5
|
from functools import wraps
|
|
@@ -16,6 +15,7 @@ from pydantic import BaseModel
|
|
|
16
15
|
|
|
17
16
|
from mirascope.core.base._utils._base_type import BaseType
|
|
18
17
|
|
|
18
|
+
from ..core.base._utils import fn_is_async
|
|
19
19
|
from ..core.base.call_response import BaseCallResponse
|
|
20
20
|
from ..core.base.stream import BaseStream
|
|
21
21
|
from ..core.base.structured_stream import BaseStructuredStream
|
|
@@ -136,14 +136,14 @@ def middleware_factory(
|
|
|
136
136
|
def decorator(
|
|
137
137
|
fn: Callable[_P, _R | Awaitable[_R]],
|
|
138
138
|
) -> Callable[_P, _R | Awaitable[_R]]:
|
|
139
|
-
if
|
|
139
|
+
if fn_is_async(fn):
|
|
140
140
|
|
|
141
141
|
@wraps(fn)
|
|
142
142
|
async def wrapper_async(*args: _P.args, **kwargs: _P.kwargs) -> _R:
|
|
143
143
|
context_manager = custom_context_manager(fn)
|
|
144
144
|
context = context_manager.__enter__()
|
|
145
145
|
try:
|
|
146
|
-
result = await fn(*args, **kwargs)
|
|
146
|
+
result = await fn(*args, **kwargs) # pyright: ignore [reportGeneralTypeIssues]
|
|
147
147
|
except Exception as e:
|
|
148
148
|
if handle_error_async:
|
|
149
149
|
try:
|
|
@@ -114,7 +114,7 @@ mirascope/core/base/_utils/_convert_messages_to_message_params.py,sha256=symOUsX
|
|
|
114
114
|
mirascope/core/base/_utils/_convert_provider_finish_reason_to_finish_reason.py,sha256=Mki5mYbYX8vUW-oosC4PaRNUHW_T5xAQWti3_1ndtTk,611
|
|
115
115
|
mirascope/core/base/_utils/_default_tool_docstring.py,sha256=JLyryjGDaHMU-P7gUpnjkPyELCQsQgi8AP4Dp_yXPOM,277
|
|
116
116
|
mirascope/core/base/_utils/_extract_tool_return.py,sha256=ZDBZJ4cacFd8nijSWZEhib7B58ZnSFD_rK1FiGNTYU0,1553
|
|
117
|
-
mirascope/core/base/_utils/_fn_is_async.py,sha256=
|
|
117
|
+
mirascope/core/base/_utils/_fn_is_async.py,sha256=dMrvkwqyyNhuaQUHtNMxpMoBoHqZuHPbh4nqfK-KKi0,728
|
|
118
118
|
mirascope/core/base/_utils/_format_template.py,sha256=3l0Iq1LxQhocR588bzUDtfLalfiq_Rw_tHrVdgoZHiA,1061
|
|
119
119
|
mirascope/core/base/_utils/_get_audio_type.py,sha256=PN8MlgKgl5OIDANgSUlI4UarLkfBHfWmWWls9shPM8M,683
|
|
120
120
|
mirascope/core/base/_utils/_get_common_usage.py,sha256=s9Gvq0wl4ZM1V3zmI0LDEIG8wIxWEOXkjuDBjtyFx9s,675
|
|
@@ -321,7 +321,7 @@ mirascope/core/xai/_utils/_setup_call.py,sha256=0pCy8SqEQQEFUrCYTe6EEn_z7GuTY7-G
|
|
|
321
321
|
mirascope/experimental/graphs/__init__.py,sha256=xwvU6T5lqfMXeHZ0IN8cepzkFkSURpeeV7ozokjzaBY,162
|
|
322
322
|
mirascope/experimental/graphs/finite_state_machine.py,sha256=xsiguJCW7nyMuITezYKHevM1R2LIs1rdMeqw5kmJITs,26470
|
|
323
323
|
mirascope/integrations/__init__.py,sha256=ieLWknpbkO_gABIVl9790YTTCCRO9ISQ35-1SeOSU0Q,392
|
|
324
|
-
mirascope/integrations/_middleware_factory.py,sha256=
|
|
324
|
+
mirascope/integrations/_middleware_factory.py,sha256=v-S-hVU5S7P9Lu8PiKyUhmtp_rbQaIJ1droC8BcKBAE,17362
|
|
325
325
|
mirascope/integrations/tenacity.py,sha256=jk64MBncCMbgoQMaXQgjxg9Y9UstRqTt2RCeA86pdCU,326
|
|
326
326
|
mirascope/integrations/langfuse/__init__.py,sha256=wG3eBXwGPbFedB28L1K_q1iCf_dERjVmTDCWK4nHZyM,71
|
|
327
327
|
mirascope/integrations/langfuse/_utils.py,sha256=SsZfQkp-_Ytxzoq03XwEy3a-PuHB6oVs3uy3fAZKMOg,3457
|
|
@@ -371,7 +371,7 @@ mirascope/v0/base/ops_utils.py,sha256=1Qq-VIwgHBaYutiZsS2MUQ4OgPC3APyywI5bTiTAmA
|
|
|
371
371
|
mirascope/v0/base/prompts.py,sha256=FM2Yz98cSnDceYogiwPrp4BALf3_F3d4fIOCGAkd-SE,1298
|
|
372
372
|
mirascope/v0/base/types.py,sha256=ZfatJoX0Yl0e3jhv0D_MhiSVHLYUeJsdN3um3iE10zY,352
|
|
373
373
|
mirascope/v0/base/utils.py,sha256=XREPENRQTu8gpMhHU8RC8qH_am3FfGUvY-dJ6x8i-mw,681
|
|
374
|
-
mirascope-1.23.
|
|
375
|
-
mirascope-1.23.
|
|
376
|
-
mirascope-1.23.
|
|
377
|
-
mirascope-1.23.
|
|
374
|
+
mirascope-1.23.3.dist-info/METADATA,sha256=22W90rT7-eiVW-Iz5P-qoVDvwoQii6qiW2HBxIY8zTE,8783
|
|
375
|
+
mirascope-1.23.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
376
|
+
mirascope-1.23.3.dist-info/licenses/LICENSE,sha256=LAs5Q8mdawTsVdONpDGukwsoc4KEUBmmonDEL39b23Y,1072
|
|
377
|
+
mirascope-1.23.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|