lmnr 0.4.43__tar.gz → 0.4.45__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.
- {lmnr-0.4.43 → lmnr-0.4.45}/PKG-INFO +8 -11
- {lmnr-0.4.43 → lmnr-0.4.45}/pyproject.toml +9 -12
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/__init__.py +1 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/openllmetry_sdk/decorators/base.py +28 -2
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/openllmetry_sdk/tracing/attributes.py +1 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/openllmetry_sdk/tracing/tracing.py +4 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/sdk/laminar.py +48 -14
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/sdk/types.py +8 -2
- {lmnr-0.4.43 → lmnr-0.4.45}/LICENSE +0 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/README.md +0 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/cli.py +0 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/openllmetry_sdk/.flake8 +0 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/openllmetry_sdk/.python-version +0 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/openllmetry_sdk/__init__.py +0 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/openllmetry_sdk/config/__init__.py +0 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/openllmetry_sdk/decorators/__init__.py +0 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/openllmetry_sdk/instruments.py +0 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/openllmetry_sdk/tracing/__init__.py +0 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/openllmetry_sdk/tracing/content_allow_list.py +0 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/openllmetry_sdk/tracing/context_manager.py +0 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/openllmetry_sdk/utils/__init__.py +0 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/openllmetry_sdk/utils/in_memory_span_exporter.py +0 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/openllmetry_sdk/utils/json_encoder.py +0 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/openllmetry_sdk/utils/package_check.py +0 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/openllmetry_sdk/version.py +0 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/sdk/__init__.py +0 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/sdk/datasets.py +0 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/sdk/decorators.py +0 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/sdk/eval_control.py +0 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/sdk/evaluations.py +0 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/sdk/log.py +0 -0
- {lmnr-0.4.43 → lmnr-0.4.45}/src/lmnr/sdk/utils.py +0 -0
@@ -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
|
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
[project]
|
8
8
|
name = "lmnr"
|
9
|
-
version = "0.4.
|
9
|
+
version = "0.4.45"
|
10
10
|
description = "Python SDK for Laminar AI"
|
11
11
|
authors = [
|
12
12
|
{ name = "lmnr.ai", email = "founders@lmnr.ai" }
|
@@ -17,7 +17,7 @@ license = "Apache-2.0"
|
|
17
17
|
|
18
18
|
[tool.poetry]
|
19
19
|
name = "lmnr"
|
20
|
-
version = "0.4.
|
20
|
+
version = "0.4.45"
|
21
21
|
description = "Python SDK for Laminar AI"
|
22
22
|
authors = ["lmnr.ai"]
|
23
23
|
readme = "README.md"
|
@@ -25,10 +25,9 @@ license = "Apache-2.0"
|
|
25
25
|
|
26
26
|
[tool.poetry.dependencies]
|
27
27
|
python = ">=3.9,<4"
|
28
|
-
pydantic = "
|
29
|
-
requests = "
|
30
|
-
python-dotenv = "
|
31
|
-
backoff = "~=2.0"
|
28
|
+
pydantic = ">=2.7"
|
29
|
+
requests = ">=2.0"
|
30
|
+
python-dotenv = ">=1.0"
|
32
31
|
opentelemetry-api = ">=1.28.0"
|
33
32
|
opentelemetry-sdk = ">=1.28.0"
|
34
33
|
opentelemetry-exporter-otlp-proto-http = ">=1.28.0"
|
@@ -38,12 +37,10 @@ opentelemetry-instrumentation-sqlalchemy = "^0.49b0"
|
|
38
37
|
opentelemetry-instrumentation-urllib3 = "^0.49b0"
|
39
38
|
opentelemetry-instrumentation-threading = "^0.49b0"
|
40
39
|
opentelemetry-semantic-conventions-ai = "0.4.2"
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
argparse = "~=1.0"
|
46
|
-
aiohttp = "~=3.0"
|
40
|
+
deprecated = ">=1.0"
|
41
|
+
tqdm = ">=4.0"
|
42
|
+
argparse = ">=1.0"
|
43
|
+
aiohttp = ">=3.0"
|
47
44
|
opentelemetry-instrumentation-alephalpha = {version = ">=0.33.12", optional = true}
|
48
45
|
opentelemetry-instrumentation-anthropic = {version = ">=0.33.12", optional = true}
|
49
46
|
opentelemetry-instrumentation-bedrock = {version = ">=0.33.12", optional = true}
|
@@ -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
|
|
@@ -59,6 +59,7 @@ from .types import (
|
|
59
59
|
SemanticSearchRequest,
|
60
60
|
SemanticSearchResponse,
|
61
61
|
TraceType,
|
62
|
+
TracingLevel,
|
62
63
|
)
|
63
64
|
|
64
65
|
|
@@ -558,6 +559,39 @@ class Laminar:
|
|
558
559
|
if output is not None and span != trace.INVALID_SPAN:
|
559
560
|
span.set_attribute(SPAN_OUTPUT, json_dumps(output))
|
560
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
|
+
|
561
595
|
@classmethod
|
562
596
|
def set_span_attributes(
|
563
597
|
cls,
|
@@ -643,20 +677,6 @@ class Laminar:
|
|
643
677
|
props.pop(k)
|
644
678
|
set_association_properties(props)
|
645
679
|
|
646
|
-
@classmethod
|
647
|
-
def _set_trace_type(
|
648
|
-
cls,
|
649
|
-
trace_type: TraceType,
|
650
|
-
):
|
651
|
-
"""Set the trace_type for the current span and the context
|
652
|
-
Args:
|
653
|
-
trace_type (TraceType): Type of the trace
|
654
|
-
"""
|
655
|
-
association_properties = {
|
656
|
-
TRACE_TYPE: trace_type.value,
|
657
|
-
}
|
658
|
-
update_association_properties(association_properties)
|
659
|
-
|
660
680
|
@classmethod
|
661
681
|
def clear_session(cls):
|
662
682
|
"""Clear the session and user id from the context"""
|
@@ -732,6 +752,20 @@ class Laminar:
|
|
732
752
|
"Content-Type": "application/json",
|
733
753
|
}
|
734
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
|
+
|
735
769
|
@classmethod
|
736
770
|
async def __run(
|
737
771
|
cls,
|
@@ -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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|