lmnr 0.4.66__py3-none-any.whl → 0.5.1__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 +30 -0
- lmnr/openllmetry_sdk/__init__.py +4 -16
- lmnr/openllmetry_sdk/tracing/attributes.py +0 -1
- lmnr/openllmetry_sdk/tracing/tracing.py +30 -10
- lmnr/sdk/browser/browser_use_otel.py +4 -4
- lmnr/sdk/browser/playwright_otel.py +299 -228
- lmnr/sdk/browser/pw_utils.py +289 -0
- lmnr/sdk/browser/utils.py +18 -53
- lmnr/sdk/client/asynchronous/async_client.py +157 -0
- lmnr/sdk/client/asynchronous/resources/__init__.py +13 -0
- lmnr/sdk/client/asynchronous/resources/agent.py +220 -0
- lmnr/sdk/client/asynchronous/resources/base.py +32 -0
- lmnr/sdk/client/asynchronous/resources/browser_events.py +40 -0
- lmnr/sdk/client/asynchronous/resources/evals.py +64 -0
- lmnr/sdk/client/asynchronous/resources/pipeline.py +89 -0
- lmnr/sdk/client/asynchronous/resources/semantic_search.py +60 -0
- lmnr/sdk/client/synchronous/resources/__init__.py +7 -0
- lmnr/sdk/client/synchronous/resources/agent.py +215 -0
- lmnr/sdk/client/synchronous/resources/base.py +32 -0
- lmnr/sdk/client/synchronous/resources/browser_events.py +40 -0
- lmnr/sdk/client/synchronous/resources/evals.py +102 -0
- lmnr/sdk/client/synchronous/resources/pipeline.py +89 -0
- lmnr/sdk/client/synchronous/resources/semantic_search.py +60 -0
- lmnr/sdk/client/synchronous/sync_client.py +170 -0
- lmnr/sdk/datasets.py +7 -2
- lmnr/sdk/evaluations.py +59 -35
- lmnr/sdk/laminar.py +34 -174
- lmnr/sdk/types.py +124 -23
- lmnr/sdk/utils.py +10 -0
- lmnr/version.py +6 -6
- {lmnr-0.4.66.dist-info → lmnr-0.5.1.dist-info}/METADATA +88 -38
- lmnr-0.5.1.dist-info/RECORD +55 -0
- {lmnr-0.4.66.dist-info → lmnr-0.5.1.dist-info}/WHEEL +1 -1
- lmnr/sdk/client.py +0 -313
- lmnr-0.4.66.dist-info/RECORD +0 -39
- {lmnr-0.4.66.dist-info → lmnr-0.5.1.dist-info}/LICENSE +0 -0
- {lmnr-0.4.66.dist-info → lmnr-0.5.1.dist-info}/entry_points.txt +0 -0
lmnr/__init__.py
CHANGED
@@ -1,12 +1,18 @@
|
|
1
|
+
from .sdk.client.synchronous.sync_client import LaminarClient
|
2
|
+
from .sdk.client.asynchronous.async_client import AsyncLaminarClient
|
1
3
|
from .sdk.datasets import EvaluationDataset, LaminarDataset
|
2
4
|
from .sdk.evaluations import evaluate
|
3
5
|
from .sdk.laminar import Laminar
|
4
6
|
from .sdk.types import (
|
7
|
+
AgentOutput,
|
8
|
+
FinalOutputChunkContent,
|
5
9
|
ChatMessage,
|
6
10
|
HumanEvaluator,
|
7
11
|
NodeInput,
|
8
12
|
PipelineRunError,
|
9
13
|
PipelineRunResponse,
|
14
|
+
RunAgentResponseChunk,
|
15
|
+
StepChunkContent,
|
10
16
|
TracingLevel,
|
11
17
|
)
|
12
18
|
from .sdk.decorators import observe
|
@@ -14,3 +20,27 @@ from .sdk.types import LaminarSpanContext
|
|
14
20
|
from .openllmetry_sdk import Instruments
|
15
21
|
from .openllmetry_sdk.tracing.attributes import Attributes
|
16
22
|
from opentelemetry.trace import use_span
|
23
|
+
|
24
|
+
__all__ = [
|
25
|
+
"AgentOutput",
|
26
|
+
"AsyncLaminarClient",
|
27
|
+
"Attributes",
|
28
|
+
"ChatMessage",
|
29
|
+
"EvaluationDataset",
|
30
|
+
"FinalOutputChunkContent",
|
31
|
+
"HumanEvaluator",
|
32
|
+
"Instruments",
|
33
|
+
"Laminar",
|
34
|
+
"LaminarClient",
|
35
|
+
"LaminarDataset",
|
36
|
+
"LaminarSpanContext",
|
37
|
+
"NodeInput",
|
38
|
+
"PipelineRunError",
|
39
|
+
"PipelineRunResponse",
|
40
|
+
"RunAgentResponseChunk",
|
41
|
+
"StepChunkContent",
|
42
|
+
"TracingLevel",
|
43
|
+
"evaluate",
|
44
|
+
"observe",
|
45
|
+
"use_span",
|
46
|
+
]
|
lmnr/openllmetry_sdk/__init__.py
CHANGED
@@ -16,7 +16,7 @@ from lmnr.openllmetry_sdk.tracing.tracing import TracerWrapper
|
|
16
16
|
from typing import Dict
|
17
17
|
|
18
18
|
|
19
|
-
class
|
19
|
+
class TracerManager:
|
20
20
|
__tracer_wrapper: TracerWrapper
|
21
21
|
|
22
22
|
@staticmethod
|
@@ -44,17 +44,6 @@ class Traceloop:
|
|
44
44
|
if isinstance(headers, str):
|
45
45
|
headers = parse_env_headers(headers)
|
46
46
|
|
47
|
-
if (
|
48
|
-
not exporter
|
49
|
-
and not processor
|
50
|
-
and api_endpoint == "https://api.lmnr.ai"
|
51
|
-
and not api_key
|
52
|
-
):
|
53
|
-
print(
|
54
|
-
"Set the LMNR_PROJECT_API_KEY environment variable to your project API key"
|
55
|
-
)
|
56
|
-
return
|
57
|
-
|
58
47
|
if api_key and not exporter and not processor and not headers:
|
59
48
|
headers = {
|
60
49
|
"Authorization": f"Bearer {api_key}",
|
@@ -65,7 +54,7 @@ class Traceloop:
|
|
65
54
|
TracerWrapper.set_static_params(
|
66
55
|
resource_attributes, enable_content_tracing, api_endpoint, headers
|
67
56
|
)
|
68
|
-
|
57
|
+
TracerManager.__tracer_wrapper = TracerWrapper(
|
69
58
|
disable_batch=disable_batch,
|
70
59
|
processor=processor,
|
71
60
|
propagator=propagator,
|
@@ -78,6 +67,5 @@ class Traceloop:
|
|
78
67
|
)
|
79
68
|
|
80
69
|
@staticmethod
|
81
|
-
def flush():
|
82
|
-
|
83
|
-
Traceloop.__tracer_wrapper.flush()
|
70
|
+
def flush() -> bool:
|
71
|
+
return TracerManager.__tracer_wrapper.flush()
|
@@ -9,7 +9,6 @@ SPAN_IDS_PATH = "lmnr.span.ids_path"
|
|
9
9
|
SPAN_INSTRUMENTATION_SOURCE = "lmnr.span.instrumentation_source"
|
10
10
|
SPAN_SDK_VERSION = "lmnr.span.sdk_version"
|
11
11
|
SPAN_LANGUAGE_VERSION = "lmnr.span.language_version"
|
12
|
-
OVERRIDE_PARENT_SPAN = "lmnr.internal.override_parent_span"
|
13
12
|
|
14
13
|
ASSOCIATION_PROPERTIES = "lmnr.association.properties"
|
15
14
|
SESSION_ID = "session_id"
|
@@ -4,6 +4,8 @@ import logging
|
|
4
4
|
import uuid
|
5
5
|
|
6
6
|
from contextvars import Context
|
7
|
+
from lmnr.sdk.client.asynchronous.async_client import AsyncLaminarClient
|
8
|
+
from lmnr.sdk.client.synchronous.sync_client import LaminarClient
|
7
9
|
from lmnr.sdk.log import VerboseColorfulFormatter
|
8
10
|
from lmnr.openllmetry_sdk.instruments import Instruments
|
9
11
|
from lmnr.openllmetry_sdk.tracing.attributes import (
|
@@ -41,7 +43,7 @@ from opentelemetry.trace import get_tracer_provider, ProxyTracerProvider
|
|
41
43
|
|
42
44
|
from typing import Dict, Optional, Set
|
43
45
|
|
44
|
-
from lmnr.version import
|
46
|
+
from lmnr.version import __version__, PYTHON_VERSION
|
45
47
|
|
46
48
|
module_logger = logging.getLogger(__name__)
|
47
49
|
console_log_handler = logging.StreamHandler()
|
@@ -80,6 +82,8 @@ class TracerWrapper(object):
|
|
80
82
|
__logger: logging.Logger = None
|
81
83
|
__span_id_to_path: dict[int, list[str]] = {}
|
82
84
|
__span_id_lists: dict[int, list[str]] = {}
|
85
|
+
__client: LaminarClient = None
|
86
|
+
__async_client: AsyncLaminarClient = None
|
83
87
|
|
84
88
|
def __new__(
|
85
89
|
cls,
|
@@ -99,6 +103,15 @@ class TracerWrapper(object):
|
|
99
103
|
if not TracerWrapper.endpoint:
|
100
104
|
return obj
|
101
105
|
|
106
|
+
obj.__client = LaminarClient(
|
107
|
+
base_url=base_http_url,
|
108
|
+
project_api_key=project_api_key,
|
109
|
+
)
|
110
|
+
obj.__async_client = AsyncLaminarClient(
|
111
|
+
base_url=base_http_url,
|
112
|
+
project_api_key=project_api_key,
|
113
|
+
)
|
114
|
+
|
102
115
|
obj.__resource = Resource(attributes=TracerWrapper.resource_attributes)
|
103
116
|
obj.__tracer_provider = init_tracer_provider(resource=obj.__resource)
|
104
117
|
if processor:
|
@@ -135,8 +148,8 @@ class TracerWrapper(object):
|
|
135
148
|
instrument_set = init_instrumentations(
|
136
149
|
should_enrich_metrics,
|
137
150
|
instruments,
|
138
|
-
|
139
|
-
|
151
|
+
client=obj.__client,
|
152
|
+
async_client=obj.__async_client,
|
140
153
|
)
|
141
154
|
|
142
155
|
if not instrument_set:
|
@@ -184,7 +197,7 @@ class TracerWrapper(object):
|
|
184
197
|
self.__span_id_lists[span.get_span_context().span_id] = span_ids_path
|
185
198
|
|
186
199
|
span.set_attribute(SPAN_INSTRUMENTATION_SOURCE, "python")
|
187
|
-
span.set_attribute(SPAN_SDK_VERSION,
|
200
|
+
span.set_attribute(SPAN_SDK_VERSION, __version__)
|
188
201
|
span.set_attribute(SPAN_LANGUAGE_VERSION, f"python@{PYTHON_VERSION}")
|
189
202
|
|
190
203
|
association_properties = get_value("association_properties")
|
@@ -223,8 +236,13 @@ class TracerWrapper(object):
|
|
223
236
|
cls.__span_id_to_path = {}
|
224
237
|
cls.__span_id_lists = {}
|
225
238
|
|
226
|
-
def
|
239
|
+
def shutdown(self):
|
227
240
|
self.__spans_processor.force_flush()
|
241
|
+
self.__spans_processor.shutdown()
|
242
|
+
self.__tracer_provider.shutdown()
|
243
|
+
|
244
|
+
def flush(self):
|
245
|
+
return self.__spans_processor.force_flush()
|
228
246
|
|
229
247
|
def get_tracer(self):
|
230
248
|
return self.__tracer_provider.get_tracer(TRACER_NAME)
|
@@ -320,8 +338,8 @@ def init_instrumentations(
|
|
320
338
|
should_enrich_metrics: bool,
|
321
339
|
instruments: Optional[Set[Instruments]] = None,
|
322
340
|
block_instruments: Optional[Set[Instruments]] = None,
|
323
|
-
|
324
|
-
|
341
|
+
client: Optional[LaminarClient] = None,
|
342
|
+
async_client: Optional[AsyncLaminarClient] = None,
|
325
343
|
):
|
326
344
|
block_instruments = block_instruments or set()
|
327
345
|
# These libraries are not instrumented by default,
|
@@ -434,7 +452,7 @@ def init_instrumentations(
|
|
434
452
|
if init_weaviate_instrumentor():
|
435
453
|
instrument_set = True
|
436
454
|
elif instrument == Instruments.PLAYWRIGHT:
|
437
|
-
if init_playwright_instrumentor():
|
455
|
+
if init_playwright_instrumentor(client, async_client):
|
438
456
|
instrument_set = True
|
439
457
|
elif instrument == Instruments.BROWSER_USE:
|
440
458
|
if init_browser_use_instrumentor():
|
@@ -465,12 +483,14 @@ def init_browser_use_instrumentor():
|
|
465
483
|
return False
|
466
484
|
|
467
485
|
|
468
|
-
def init_playwright_instrumentor(
|
486
|
+
def init_playwright_instrumentor(
|
487
|
+
client: LaminarClient, async_client: AsyncLaminarClient
|
488
|
+
):
|
469
489
|
try:
|
470
490
|
if is_package_installed("playwright"):
|
471
491
|
from lmnr.sdk.browser.playwright_otel import PlaywrightInstrumentor
|
472
492
|
|
473
|
-
instrumentor = PlaywrightInstrumentor()
|
493
|
+
instrumentor = PlaywrightInstrumentor(client, async_client)
|
474
494
|
instrumentor.instrument()
|
475
495
|
return True
|
476
496
|
except Exception as e:
|
@@ -1,7 +1,7 @@
|
|
1
1
|
from lmnr.openllmetry_sdk.decorators.base import json_dumps
|
2
|
-
from lmnr.sdk.browser.utils import
|
2
|
+
from lmnr.sdk.browser.utils import with_tracer_wrapper
|
3
3
|
from lmnr.sdk.utils import get_input_from_func_args
|
4
|
-
from lmnr.version import
|
4
|
+
from lmnr.version import __version__
|
5
5
|
|
6
6
|
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
|
7
7
|
from opentelemetry.instrumentation.utils import unwrap
|
@@ -50,7 +50,7 @@ WRAPPED_METHODS = [
|
|
50
50
|
]
|
51
51
|
|
52
52
|
|
53
|
-
@
|
53
|
+
@with_tracer_wrapper
|
54
54
|
async def _wrap(tracer: Tracer, to_wrap, wrapped, instance, args, kwargs):
|
55
55
|
span_name = to_wrap.get("span_name")
|
56
56
|
attributes = {
|
@@ -86,7 +86,7 @@ class BrowserUseInstrumentor(BaseInstrumentor):
|
|
86
86
|
|
87
87
|
def _instrument(self, **kwargs):
|
88
88
|
tracer_provider = kwargs.get("tracer_provider")
|
89
|
-
tracer = get_tracer(__name__,
|
89
|
+
tracer = get_tracer(__name__, __version__, tracer_provider)
|
90
90
|
|
91
91
|
for wrapped_method in WRAPPED_METHODS:
|
92
92
|
wrap_package = wrapped_method.get("package")
|