lmnr 0.4.42__py3-none-any.whl → 0.4.45__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.
- lmnr/__init__.py +1 -0
- lmnr/openllmetry_sdk/decorators/base.py +28 -2
- lmnr/openllmetry_sdk/tracing/attributes.py +1 -0
- lmnr/openllmetry_sdk/tracing/tracing.py +4 -0
- lmnr/sdk/laminar.py +49 -14
- lmnr/sdk/types.py +8 -2
- {lmnr-0.4.42.dist-info → lmnr-0.4.45.dist-info}/METADATA +8 -11
- {lmnr-0.4.42.dist-info → lmnr-0.4.45.dist-info}/RECORD +11 -11
- {lmnr-0.4.42.dist-info → lmnr-0.4.45.dist-info}/LICENSE +0 -0
- {lmnr-0.4.42.dist-info → lmnr-0.4.45.dist-info}/WHEEL +0 -0
- {lmnr-0.4.42.dist-info → lmnr-0.4.45.dist-info}/entry_points.txt +0 -0
lmnr/__init__.py
CHANGED
@@ -3,11 +3,13 @@ from functools import wraps
|
|
3
3
|
import logging
|
4
4
|
import os
|
5
5
|
import pydantic
|
6
|
+
import traceback
|
6
7
|
import types
|
7
8
|
from typing import Any, Optional
|
8
9
|
|
9
10
|
from opentelemetry import trace
|
10
11
|
from opentelemetry import context as context_api
|
12
|
+
from opentelemetry.trace import Span
|
11
13
|
|
12
14
|
from lmnr.sdk.utils import get_input_from_func_args, is_method
|
13
15
|
from lmnr.openllmetry_sdk.tracing import get_tracer
|
@@ -69,7 +71,12 @@ def entity_method(
|
|
69
71
|
except TypeError:
|
70
72
|
pass
|
71
73
|
|
72
|
-
|
74
|
+
try:
|
75
|
+
res = fn(*args, **kwargs)
|
76
|
+
except Exception as e:
|
77
|
+
_process_exception(span, e)
|
78
|
+
span.end()
|
79
|
+
raise e
|
73
80
|
|
74
81
|
# span will be ended in the generator
|
75
82
|
if isinstance(res, types.GeneratorType):
|
@@ -131,7 +138,12 @@ def aentity_method(
|
|
131
138
|
except TypeError:
|
132
139
|
pass
|
133
140
|
|
134
|
-
|
141
|
+
try:
|
142
|
+
res = await fn(*args, **kwargs)
|
143
|
+
except Exception as e:
|
144
|
+
_process_exception(span, e)
|
145
|
+
span.end()
|
146
|
+
raise e
|
135
147
|
|
136
148
|
# span will be ended in the generator
|
137
149
|
if isinstance(res, types.AsyncGeneratorType):
|
@@ -177,3 +189,17 @@ def _should_send_prompts():
|
|
177
189
|
return (
|
178
190
|
os.getenv("TRACELOOP_TRACE_CONTENT") or "true"
|
179
191
|
).lower() == "true" or context_api.get_value("override_enable_content_tracing")
|
192
|
+
|
193
|
+
|
194
|
+
def _process_exception(span: Span, e: Exception):
|
195
|
+
exception_path = [type(e).__module__] if type(e).__module__ != "builtins" else []
|
196
|
+
exception_path.append(type(e).__qualname__)
|
197
|
+
span.add_event(
|
198
|
+
"exception",
|
199
|
+
{
|
200
|
+
"exception.message": str(e),
|
201
|
+
"exception.type": ".".join(exception_path),
|
202
|
+
"exception.stacktrace": traceback.format_exc(),
|
203
|
+
"exception.escaped": True,
|
204
|
+
},
|
205
|
+
)
|
@@ -10,6 +10,7 @@ from lmnr.openllmetry_sdk.tracing.attributes import (
|
|
10
10
|
ASSOCIATION_PROPERTIES,
|
11
11
|
SPAN_INSTRUMENTATION_SOURCE,
|
12
12
|
SPAN_PATH,
|
13
|
+
TRACING_LEVEL,
|
13
14
|
)
|
14
15
|
from lmnr.openllmetry_sdk.tracing.content_allow_list import ContentAllowList
|
15
16
|
from lmnr.openllmetry_sdk.utils import is_notebook
|
@@ -224,6 +225,9 @@ def remove_association_properties(properties: dict) -> None:
|
|
224
225
|
|
225
226
|
def _set_association_properties_attributes(span, properties: dict) -> None:
|
226
227
|
for key, value in properties.items():
|
228
|
+
if key == TRACING_LEVEL:
|
229
|
+
span.set_attribute(f"lmnr.internal.{TRACING_LEVEL}", value)
|
230
|
+
continue
|
227
231
|
span.set_attribute(f"{ASSOCIATION_PROPERTIES}.{key}", value)
|
228
232
|
|
229
233
|
|
lmnr/sdk/laminar.py
CHANGED
@@ -59,6 +59,7 @@ from .types import (
|
|
59
59
|
SemanticSearchRequest,
|
60
60
|
SemanticSearchResponse,
|
61
61
|
TraceType,
|
62
|
+
TracingLevel,
|
62
63
|
)
|
63
64
|
|
64
65
|
|
@@ -347,6 +348,7 @@ class Laminar:
|
|
347
348
|
|
348
349
|
if not cls.is_initialized():
|
349
350
|
yield
|
351
|
+
return
|
350
352
|
|
351
353
|
with get_tracer() as tracer:
|
352
354
|
span_path = get_span_path(name)
|
@@ -557,6 +559,39 @@ class Laminar:
|
|
557
559
|
if output is not None and span != trace.INVALID_SPAN:
|
558
560
|
span.set_attribute(SPAN_OUTPUT, json_dumps(output))
|
559
561
|
|
562
|
+
@classmethod
|
563
|
+
@contextmanager
|
564
|
+
def set_tracing_level(self, level: TracingLevel):
|
565
|
+
"""Set the tracing level for the current span and the context
|
566
|
+
(i.e. any children spans created from the current span in the current
|
567
|
+
thread).
|
568
|
+
|
569
|
+
Tracing level can be one of:
|
570
|
+
- `TracingLevel.ALL`: Enable tracing for the current span and all
|
571
|
+
children spans.
|
572
|
+
- `TracingLevel.META_ONLY`: Enable tracing for the current span and all
|
573
|
+
children spans, but only record metadata, e.g. tokens, costs.
|
574
|
+
- `TracingLevel.OFF`: Disable recording any spans.
|
575
|
+
|
576
|
+
Example:
|
577
|
+
```python
|
578
|
+
from lmnr import Laminar, TracingLevel
|
579
|
+
|
580
|
+
with Laminar.set_tracing_level(TracingLevel.META_ONLY):
|
581
|
+
openai_client.chat.completions.create()
|
582
|
+
```
|
583
|
+
"""
|
584
|
+
if level == TracingLevel.ALL:
|
585
|
+
yield
|
586
|
+
else:
|
587
|
+
level = "meta_only" if level == TracingLevel.META_ONLY else "off"
|
588
|
+
update_association_properties({"tracing_level": level})
|
589
|
+
yield
|
590
|
+
try:
|
591
|
+
remove_association_properties({"tracing_level": level})
|
592
|
+
except Exception:
|
593
|
+
pass
|
594
|
+
|
560
595
|
@classmethod
|
561
596
|
def set_span_attributes(
|
562
597
|
cls,
|
@@ -642,20 +677,6 @@ class Laminar:
|
|
642
677
|
props.pop(k)
|
643
678
|
set_association_properties(props)
|
644
679
|
|
645
|
-
@classmethod
|
646
|
-
def _set_trace_type(
|
647
|
-
cls,
|
648
|
-
trace_type: TraceType,
|
649
|
-
):
|
650
|
-
"""Set the trace_type for the current span and the context
|
651
|
-
Args:
|
652
|
-
trace_type (TraceType): Type of the trace
|
653
|
-
"""
|
654
|
-
association_properties = {
|
655
|
-
TRACE_TYPE: trace_type.value,
|
656
|
-
}
|
657
|
-
update_association_properties(association_properties)
|
658
|
-
|
659
680
|
@classmethod
|
660
681
|
def clear_session(cls):
|
661
682
|
"""Clear the session and user id from the context"""
|
@@ -731,6 +752,20 @@ class Laminar:
|
|
731
752
|
"Content-Type": "application/json",
|
732
753
|
}
|
733
754
|
|
755
|
+
@classmethod
|
756
|
+
def _set_trace_type(
|
757
|
+
cls,
|
758
|
+
trace_type: TraceType,
|
759
|
+
):
|
760
|
+
"""Set the trace_type for the current span and the context
|
761
|
+
Args:
|
762
|
+
trace_type (TraceType): Type of the trace
|
763
|
+
"""
|
764
|
+
association_properties = {
|
765
|
+
TRACE_TYPE: trace_type.value,
|
766
|
+
}
|
767
|
+
update_association_properties(association_properties)
|
768
|
+
|
734
769
|
@classmethod
|
735
770
|
async def __run(
|
736
771
|
cls,
|
lmnr/sdk/types.py
CHANGED
@@ -124,7 +124,7 @@ ExecutorFunctionReturnType = Any
|
|
124
124
|
EvaluatorFunctionReturnType = Union[Numeric, dict[str, Numeric]]
|
125
125
|
|
126
126
|
ExecutorFunction = Callable[
|
127
|
-
[EvaluationDatapointData, Any
|
127
|
+
[EvaluationDatapointData, Any],
|
128
128
|
Union[ExecutorFunctionReturnType, Awaitable[ExecutorFunctionReturnType]],
|
129
129
|
]
|
130
130
|
|
@@ -133,7 +133,7 @@ ExecutorFunction = Callable[
|
|
133
133
|
# record of string keys and number values. The latter is useful for evaluating
|
134
134
|
# multiple criteria in one go instead of running multiple evaluators.
|
135
135
|
EvaluatorFunction = Callable[
|
136
|
-
[ExecutorFunctionReturnType, Any
|
136
|
+
[ExecutorFunctionReturnType, Any],
|
137
137
|
Union[EvaluatorFunctionReturnType, Awaitable[EvaluatorFunctionReturnType]],
|
138
138
|
]
|
139
139
|
|
@@ -203,3 +203,9 @@ class TraceType(Enum):
|
|
203
203
|
class GetDatapointsResponse(pydantic.BaseModel):
|
204
204
|
items: list[Datapoint]
|
205
205
|
totalCount: int
|
206
|
+
|
207
|
+
|
208
|
+
class TracingLevel(Enum):
|
209
|
+
OFF = 0
|
210
|
+
META_ONLY = 1
|
211
|
+
ALL = 2
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: lmnr
|
3
|
-
Version: 0.4.
|
3
|
+
Version: 0.4.45
|
4
4
|
Summary: Python SDK for Laminar AI
|
5
5
|
License: Apache-2.0
|
6
6
|
Author: lmnr.ai
|
@@ -38,11 +38,9 @@ Provides-Extra: transformers
|
|
38
38
|
Provides-Extra: vertexai
|
39
39
|
Provides-Extra: watsonx
|
40
40
|
Provides-Extra: weaviate
|
41
|
-
Requires-Dist: aiohttp (>=3.0
|
42
|
-
Requires-Dist: argparse (>=1.0
|
43
|
-
Requires-Dist:
|
44
|
-
Requires-Dist: deprecated (>=1.0,<2.0)
|
45
|
-
Requires-Dist: jinja2 (>=3.0,<4.0)
|
41
|
+
Requires-Dist: aiohttp (>=3.0)
|
42
|
+
Requires-Dist: argparse (>=1.0)
|
43
|
+
Requires-Dist: deprecated (>=1.0)
|
46
44
|
Requires-Dist: opentelemetry-api (>=1.28.0)
|
47
45
|
Requires-Dist: opentelemetry-exporter-otlp-proto-grpc (>=1.28.0)
|
48
46
|
Requires-Dist: opentelemetry-exporter-otlp-proto-http (>=1.28.0)
|
@@ -77,11 +75,10 @@ Requires-Dist: opentelemetry-instrumentation-watsonx (>=0.33.12) ; extra == "all
|
|
77
75
|
Requires-Dist: opentelemetry-instrumentation-weaviate (>=0.33.12) ; extra == "all" or extra == "weaviate"
|
78
76
|
Requires-Dist: opentelemetry-sdk (>=1.28.0)
|
79
77
|
Requires-Dist: opentelemetry-semantic-conventions-ai (==0.4.2)
|
80
|
-
Requires-Dist: pydantic (>=2.7
|
81
|
-
Requires-Dist: python-dotenv (>=1.0
|
82
|
-
Requires-Dist: requests (>=2.0
|
83
|
-
Requires-Dist:
|
84
|
-
Requires-Dist: tqdm (>=4.0,<5.0)
|
78
|
+
Requires-Dist: pydantic (>=2.7)
|
79
|
+
Requires-Dist: python-dotenv (>=1.0)
|
80
|
+
Requires-Dist: requests (>=2.0)
|
81
|
+
Requires-Dist: tqdm (>=4.0)
|
85
82
|
Description-Content-Type: text/markdown
|
86
83
|
|
87
84
|
# Laminar Python
|
@@ -1,17 +1,17 @@
|
|
1
|
-
lmnr/__init__.py,sha256=
|
1
|
+
lmnr/__init__.py,sha256=Bqxs-8Mh4h69pOHURgBCgo9EW1GwChebxP6wUX2-bsU,452
|
2
2
|
lmnr/cli.py,sha256=W5zn5DBJiFaVARFy2D-8tJI8ZlGNzjJqk3qiXAG2woo,1456
|
3
3
|
lmnr/openllmetry_sdk/.flake8,sha256=bCxuDlGx3YQ55QHKPiGJkncHanh9qGjQJUujcFa3lAU,150
|
4
4
|
lmnr/openllmetry_sdk/.python-version,sha256=9OLQBQVbD4zE4cJsPePhnAfV_snrPSoqEQw-PXgPMOs,6
|
5
5
|
lmnr/openllmetry_sdk/__init__.py,sha256=vVSGTAwUnJvdulHtslkGAd8QCBuv78WUK3bgfBpH6Do,2390
|
6
6
|
lmnr/openllmetry_sdk/config/__init__.py,sha256=DliMGp2NjYAqRFLKpWQPUKjGMHRO8QsVfazBA1qENQ8,248
|
7
7
|
lmnr/openllmetry_sdk/decorators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
|
-
lmnr/openllmetry_sdk/decorators/base.py,sha256=
|
8
|
+
lmnr/openllmetry_sdk/decorators/base.py,sha256=xwLsUFd5husf3p-ZllVTYEe9gkwl9T3Bf1WpW1-Ua5I,6413
|
9
9
|
lmnr/openllmetry_sdk/instruments.py,sha256=CGGUEELldrXkQwAzAkDeAtDq07_pjhz7i14a92P7C_E,1036
|
10
10
|
lmnr/openllmetry_sdk/tracing/__init__.py,sha256=xT73L1t2si2CM6QmMiTZ7zn-dKKYBLNrpBBWq6WfVBw,68
|
11
|
-
lmnr/openllmetry_sdk/tracing/attributes.py,sha256=
|
11
|
+
lmnr/openllmetry_sdk/tracing/attributes.py,sha256=B_4KVYWAUu-6DQmsm2eCJQcTxm8pG1EByCBK3uOPkuI,1293
|
12
12
|
lmnr/openllmetry_sdk/tracing/content_allow_list.py,sha256=3feztm6PBWNelc8pAZUcQyEGyeSpNiVKjOaDk65l2ps,846
|
13
13
|
lmnr/openllmetry_sdk/tracing/context_manager.py,sha256=rdSus-p-TaevQ8hIAhfbnZr5dTqRvACDkzXGDpflncY,306
|
14
|
-
lmnr/openllmetry_sdk/tracing/tracing.py,sha256=
|
14
|
+
lmnr/openllmetry_sdk/tracing/tracing.py,sha256=pa8ZPhH4NSwP1QnvD5qNaOZ775H5Q4KVa9OwSki9KUE,32138
|
15
15
|
lmnr/openllmetry_sdk/utils/__init__.py,sha256=pNhf0G3vTd5ccoc03i1MXDbricSaiqCbi1DLWhSekK8,604
|
16
16
|
lmnr/openllmetry_sdk/utils/in_memory_span_exporter.py,sha256=H_4TRaThMO1H6vUQ0OpQvzJk_fZH0OOsRAM1iZQXsR8,2112
|
17
17
|
lmnr/openllmetry_sdk/utils/json_encoder.py,sha256=dK6b_axr70IYL7Vv-bu4wntvDDuyntoqsHaddqX7P58,463
|
@@ -22,12 +22,12 @@ lmnr/sdk/datasets.py,sha256=KNMp_v3z1ocIltIw7kTgj8o-l9R8N8Tgj0sw1ajQ9C8,1582
|
|
22
22
|
lmnr/sdk/decorators.py,sha256=ja2EUWUWvFOp28ER0k78PRuxNahwCVyH0TdM3U-xY7U,1856
|
23
23
|
lmnr/sdk/eval_control.py,sha256=G6Fg3Xx_KWv72iBaWlNMdyRTF2bZFQnwJ68sJNSpIcY,177
|
24
24
|
lmnr/sdk/evaluations.py,sha256=gLImD_uB9uXgw07QiJ_OYRTFDGxiPtFCO1c8HyOq2s0,15935
|
25
|
-
lmnr/sdk/laminar.py,sha256=
|
25
|
+
lmnr/sdk/laminar.py,sha256=4Saelm9m6pB9GWquCdHWY-1VhAB8Q2tWlq6hnmorzHU,31250
|
26
26
|
lmnr/sdk/log.py,sha256=cZBeUoSK39LMEV-X4-eEhTWOciULRfHaKfRK8YqIM8I,1532
|
27
|
-
lmnr/sdk/types.py,sha256=
|
27
|
+
lmnr/sdk/types.py,sha256=FCNoFoa0ingOvpXGfbiETVsakYyq9Zpoc56MXJ1YDzQ,6390
|
28
28
|
lmnr/sdk/utils.py,sha256=Uk8y15x-sd5tP2ERONahElLDJVEy_3dA_1_5g9A6auY,3358
|
29
|
-
lmnr-0.4.
|
30
|
-
lmnr-0.4.
|
31
|
-
lmnr-0.4.
|
32
|
-
lmnr-0.4.
|
33
|
-
lmnr-0.4.
|
29
|
+
lmnr-0.4.45.dist-info/LICENSE,sha256=67b_wJHVV1CBaWkrKFWU1wyqTPSdzH77Ls-59631COg,10411
|
30
|
+
lmnr-0.4.45.dist-info/METADATA,sha256=mA47njgTnxaXCPAvEBOeNIRzsuvicfdIVMVLXe1UUWg,12212
|
31
|
+
lmnr-0.4.45.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
32
|
+
lmnr-0.4.45.dist-info/entry_points.txt,sha256=K1jE20ww4jzHNZLnsfWBvU3YKDGBgbOiYG5Y7ivQcq4,37
|
33
|
+
lmnr-0.4.45.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|