lmnr 0.5.1a0__py3-none-any.whl → 0.5.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.
- lmnr/__init__.py +2 -10
- lmnr/cli.py +10 -8
- lmnr/{openllmetry_sdk → opentelemetry_lib}/__init__.py +8 -36
- lmnr/{openllmetry_sdk → opentelemetry_lib}/decorators/base.py +27 -20
- lmnr/{openllmetry_sdk → opentelemetry_lib}/instruments.py +2 -0
- lmnr/opentelemetry_lib/opentelemetry/instrumentation/google_genai/__init__.py +454 -0
- lmnr/opentelemetry_lib/opentelemetry/instrumentation/google_genai/config.py +9 -0
- lmnr/opentelemetry_lib/opentelemetry/instrumentation/google_genai/utils.py +216 -0
- lmnr/opentelemetry_lib/tracing/__init__.py +1 -0
- lmnr/opentelemetry_lib/tracing/context_manager.py +13 -0
- lmnr/{openllmetry_sdk → opentelemetry_lib}/tracing/tracing.py +253 -257
- lmnr/sdk/browser/browser_use_otel.py +20 -3
- lmnr/sdk/browser/patchright_otel.py +177 -0
- lmnr/sdk/browser/playwright_otel.py +55 -62
- lmnr/sdk/browser/pw_utils.py +122 -116
- lmnr/sdk/browser/rrweb/rrweb.umd.min.cjs +98 -0
- lmnr/sdk/client/asynchronous/async_client.py +0 -34
- lmnr/sdk/client/asynchronous/resources/__init__.py +0 -4
- lmnr/sdk/client/asynchronous/resources/agent.py +115 -6
- lmnr/sdk/client/synchronous/resources/__init__.py +1 -3
- lmnr/sdk/client/synchronous/resources/agent.py +112 -6
- lmnr/sdk/client/synchronous/sync_client.py +0 -36
- lmnr/sdk/decorators.py +19 -5
- lmnr/sdk/eval_control.py +3 -2
- lmnr/sdk/evaluations.py +8 -14
- lmnr/sdk/laminar.py +10 -10
- lmnr/sdk/types.py +86 -170
- lmnr/sdk/utils.py +8 -1
- lmnr/version.py +1 -1
- {lmnr-0.5.1a0.dist-info → lmnr-0.5.3.dist-info}/METADATA +58 -58
- lmnr-0.5.3.dist-info/RECORD +55 -0
- {lmnr-0.5.1a0.dist-info → lmnr-0.5.3.dist-info}/WHEEL +1 -1
- lmnr/openllmetry_sdk/tracing/__init__.py +0 -0
- lmnr/sdk/browser/rrweb/rrweb.min.js +0 -18
- lmnr/sdk/client/asynchronous/resources/pipeline.py +0 -89
- lmnr/sdk/client/asynchronous/resources/semantic_search.py +0 -60
- lmnr/sdk/client/synchronous/resources/pipeline.py +0 -89
- lmnr/sdk/client/synchronous/resources/semantic_search.py +0 -60
- lmnr-0.5.1a0.dist-info/RECORD +0 -54
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/.flake8 +0 -0
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/config/__init__.py +0 -0
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/decorators/__init__.py +0 -0
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/tracing/attributes.py +0 -0
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/tracing/content_allow_list.py +0 -0
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/utils/__init__.py +0 -0
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/utils/in_memory_span_exporter.py +0 -0
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/utils/json_encoder.py +0 -0
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/utils/package_check.py +0 -0
- {lmnr-0.5.1a0.dist-info → lmnr-0.5.3.dist-info}/LICENSE +0 -0
- {lmnr-0.5.1a0.dist-info → lmnr-0.5.3.dist-info}/entry_points.txt +0 -0
lmnr/__init__.py
CHANGED
@@ -6,26 +6,21 @@ from .sdk.laminar import Laminar
|
|
6
6
|
from .sdk.types import (
|
7
7
|
AgentOutput,
|
8
8
|
FinalOutputChunkContent,
|
9
|
-
ChatMessage,
|
10
9
|
HumanEvaluator,
|
11
|
-
NodeInput,
|
12
|
-
PipelineRunError,
|
13
|
-
PipelineRunResponse,
|
14
10
|
RunAgentResponseChunk,
|
15
11
|
StepChunkContent,
|
16
12
|
TracingLevel,
|
17
13
|
)
|
18
14
|
from .sdk.decorators import observe
|
19
15
|
from .sdk.types import LaminarSpanContext
|
20
|
-
from .
|
21
|
-
from .
|
16
|
+
from .opentelemetry_lib import Instruments
|
17
|
+
from .opentelemetry_lib.tracing.attributes import Attributes
|
22
18
|
from opentelemetry.trace import use_span
|
23
19
|
|
24
20
|
__all__ = [
|
25
21
|
"AgentOutput",
|
26
22
|
"AsyncLaminarClient",
|
27
23
|
"Attributes",
|
28
|
-
"ChatMessage",
|
29
24
|
"EvaluationDataset",
|
30
25
|
"FinalOutputChunkContent",
|
31
26
|
"HumanEvaluator",
|
@@ -34,9 +29,6 @@ __all__ = [
|
|
34
29
|
"LaminarClient",
|
35
30
|
"LaminarDataset",
|
36
31
|
"LaminarSpanContext",
|
37
|
-
"NodeInput",
|
38
|
-
"PipelineRunError",
|
39
|
-
"PipelineRunResponse",
|
40
32
|
"RunAgentResponseChunk",
|
41
33
|
"StepChunkContent",
|
42
34
|
"TracingLevel",
|
lmnr/cli.py
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
from argparse import ArgumentParser
|
2
2
|
import asyncio
|
3
3
|
import importlib.util
|
4
|
-
import logging
|
5
4
|
import os
|
6
5
|
import re
|
7
6
|
import sys
|
7
|
+
from typing import Optional
|
8
|
+
|
9
|
+
from lmnr.sdk.evaluations import Evaluation
|
8
10
|
|
9
11
|
from .sdk.eval_control import PREPARE_ONLY, EVALUATION_INSTANCE
|
10
|
-
from .sdk.log import
|
12
|
+
from .sdk.log import get_default_logger
|
11
13
|
|
12
|
-
LOG =
|
13
|
-
console_log_handler = logging.StreamHandler()
|
14
|
-
console_log_handler.setFormatter(ColorfulFormatter())
|
15
|
-
LOG.addHandler(console_log_handler)
|
14
|
+
LOG = get_default_logger(__name__)
|
16
15
|
|
17
16
|
|
18
17
|
EVAL_DIR = "evals"
|
@@ -28,7 +27,10 @@ async def run_evaluation(args):
|
|
28
27
|
if re.match(r".*_eval\.py$", f) or re.match(r"eval_.*\.py$", f)
|
29
28
|
]
|
30
29
|
if len(files) == 0:
|
31
|
-
LOG.error("No evaluation files found in evals directory")
|
30
|
+
LOG.error("No evaluation files found in `evals` directory")
|
31
|
+
LOG.info(
|
32
|
+
"Eval files must be located in the `evals` directory and must be named *_eval.py or eval_*.py"
|
33
|
+
)
|
32
34
|
return
|
33
35
|
files.sort()
|
34
36
|
LOG.info(f"Located {len(files)} evaluation files in {EVAL_DIR}")
|
@@ -53,7 +55,7 @@ async def run_evaluation(args):
|
|
53
55
|
sys.modules[name] = mod
|
54
56
|
|
55
57
|
spec.loader.exec_module(mod)
|
56
|
-
evaluation = EVALUATION_INSTANCE.get()
|
58
|
+
evaluation: Optional[Evaluation] = EVALUATION_INSTANCE.get()
|
57
59
|
if evaluation is None:
|
58
60
|
LOG.warning("Evaluation instance not found")
|
59
61
|
if args.fail_on_error:
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import sys
|
2
2
|
|
3
|
-
from contextlib import contextmanager
|
4
3
|
from typing import Optional, Set
|
5
4
|
from opentelemetry.sdk.trace import SpanProcessor
|
6
5
|
from opentelemetry.sdk.trace.export import SpanExporter
|
@@ -8,18 +7,17 @@ from opentelemetry.sdk.resources import SERVICE_NAME
|
|
8
7
|
from opentelemetry.propagators.textmap import TextMapPropagator
|
9
8
|
from opentelemetry.util.re import parse_env_headers
|
10
9
|
|
11
|
-
from lmnr.
|
12
|
-
from lmnr.
|
10
|
+
from lmnr.opentelemetry_lib.instruments import Instruments
|
11
|
+
from lmnr.opentelemetry_lib.config import (
|
13
12
|
is_content_tracing_enabled,
|
14
13
|
is_tracing_enabled,
|
15
14
|
)
|
16
|
-
from lmnr.
|
15
|
+
from lmnr.opentelemetry_lib.tracing.tracing import TracerWrapper
|
17
16
|
from typing import Dict
|
18
17
|
|
19
18
|
|
20
19
|
class TracerManager:
|
21
20
|
__tracer_wrapper: TracerWrapper
|
22
|
-
__initialized: bool = False
|
23
21
|
|
24
22
|
@staticmethod
|
25
23
|
def init(
|
@@ -53,6 +51,9 @@ class TracerManager:
|
|
53
51
|
|
54
52
|
# Tracer init
|
55
53
|
resource_attributes.update({SERVICE_NAME: app_name})
|
54
|
+
TracerWrapper.set_static_params(
|
55
|
+
resource_attributes, enable_content_tracing, api_endpoint, headers
|
56
|
+
)
|
56
57
|
TracerManager.__tracer_wrapper = TracerWrapper(
|
57
58
|
disable_batch=disable_batch,
|
58
59
|
processor=processor,
|
@@ -63,41 +64,12 @@ class TracerManager:
|
|
63
64
|
base_http_url=base_http_url,
|
64
65
|
project_api_key=project_api_key,
|
65
66
|
max_export_batch_size=max_export_batch_size,
|
66
|
-
resource_attributes=resource_attributes,
|
67
|
-
enable_content_tracing=enable_content_tracing,
|
68
|
-
endpoint=api_endpoint,
|
69
|
-
headers=headers,
|
70
67
|
)
|
71
|
-
TracerManager.__initialized = True
|
72
68
|
|
73
69
|
@staticmethod
|
74
70
|
def flush() -> bool:
|
75
71
|
return TracerManager.__tracer_wrapper.flush()
|
76
72
|
|
77
73
|
@staticmethod
|
78
|
-
def shutdown()
|
79
|
-
|
80
|
-
res = TracerManager.__tracer_wrapper.shutdown()
|
81
|
-
TracerManager.__tracer_wrapper = None
|
82
|
-
TracerManager.__initialized = False
|
83
|
-
return res
|
84
|
-
except Exception:
|
85
|
-
return False
|
86
|
-
|
87
|
-
@staticmethod
|
88
|
-
def is_initialized() -> bool:
|
89
|
-
return TracerManager.__initialized
|
90
|
-
|
91
|
-
@staticmethod
|
92
|
-
def get_tracer_wrapper() -> TracerWrapper:
|
93
|
-
return TracerManager.__tracer_wrapper
|
94
|
-
|
95
|
-
|
96
|
-
@contextmanager
|
97
|
-
def get_tracer(flush_on_exit: bool = False):
|
98
|
-
wrapper = TracerManager.get_tracer_wrapper()
|
99
|
-
try:
|
100
|
-
yield wrapper.get_tracer()
|
101
|
-
finally:
|
102
|
-
if flush_on_exit:
|
103
|
-
wrapper.flush()
|
74
|
+
def shutdown():
|
75
|
+
TracerManager.__tracer_wrapper.shutdown()
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import json
|
2
2
|
from functools import wraps
|
3
3
|
import logging
|
4
|
-
import os
|
5
4
|
import pydantic
|
6
5
|
import types
|
7
6
|
from typing import Any, Literal, Optional, Union
|
@@ -11,11 +10,11 @@ from opentelemetry import context as context_api
|
|
11
10
|
from opentelemetry.trace import Span
|
12
11
|
|
13
12
|
from lmnr.sdk.utils import get_input_from_func_args, is_method
|
14
|
-
from lmnr.
|
15
|
-
from lmnr.
|
16
|
-
from lmnr.
|
17
|
-
from lmnr.
|
18
|
-
from lmnr.
|
13
|
+
from lmnr.opentelemetry_lib.tracing import get_tracer
|
14
|
+
from lmnr.opentelemetry_lib.tracing.attributes import SPAN_INPUT, SPAN_OUTPUT, SPAN_TYPE
|
15
|
+
from lmnr.opentelemetry_lib.tracing.tracing import TracerWrapper
|
16
|
+
from lmnr.opentelemetry_lib.utils.json_encoder import JSONEncoder
|
17
|
+
from lmnr.opentelemetry_lib.config import MAX_MANUAL_SPAN_PAYLOAD_SIZE
|
19
18
|
|
20
19
|
|
21
20
|
class CustomJSONEncoder(JSONEncoder):
|
@@ -40,13 +39,14 @@ def json_dumps(data: dict) -> str:
|
|
40
39
|
def entity_method(
|
41
40
|
name: Optional[str] = None,
|
42
41
|
ignore_input: bool = False,
|
42
|
+
ignore_inputs: Optional[list[str]] = None,
|
43
43
|
ignore_output: bool = False,
|
44
44
|
span_type: Union[Literal["DEFAULT"], Literal["LLM"], Literal["TOOL"]] = "DEFAULT",
|
45
45
|
):
|
46
46
|
def decorate(fn):
|
47
47
|
@wraps(fn)
|
48
48
|
def wrap(*args, **kwargs):
|
49
|
-
if not
|
49
|
+
if not TracerWrapper.verify_initialized():
|
50
50
|
return fn(*args, **kwargs)
|
51
51
|
|
52
52
|
span_name = name or fn.__name__
|
@@ -58,9 +58,15 @@ def entity_method(
|
|
58
58
|
ctx_token = context_api.attach(ctx)
|
59
59
|
|
60
60
|
try:
|
61
|
-
if
|
61
|
+
if not ignore_input:
|
62
62
|
inp = json_dumps(
|
63
|
-
get_input_from_func_args(
|
63
|
+
get_input_from_func_args(
|
64
|
+
fn,
|
65
|
+
is_method=is_method(fn),
|
66
|
+
func_args=args,
|
67
|
+
func_kwargs=kwargs,
|
68
|
+
ignore_inputs=ignore_inputs,
|
69
|
+
)
|
64
70
|
)
|
65
71
|
if len(inp) > MAX_MANUAL_SPAN_PAYLOAD_SIZE:
|
66
72
|
span.set_attribute(
|
@@ -83,7 +89,7 @@ def entity_method(
|
|
83
89
|
return _handle_generator(span, res)
|
84
90
|
|
85
91
|
try:
|
86
|
-
if
|
92
|
+
if not ignore_output:
|
87
93
|
output = json_dumps(res)
|
88
94
|
if len(output) > MAX_MANUAL_SPAN_PAYLOAD_SIZE:
|
89
95
|
span.set_attribute(
|
@@ -108,13 +114,14 @@ def entity_method(
|
|
108
114
|
def aentity_method(
|
109
115
|
name: Optional[str] = None,
|
110
116
|
ignore_input: bool = False,
|
117
|
+
ignore_inputs: Optional[list[str]] = None,
|
111
118
|
ignore_output: bool = False,
|
112
119
|
span_type: Union[Literal["DEFAULT"], Literal["LLM"], Literal["TOOL"]] = "DEFAULT",
|
113
120
|
):
|
114
121
|
def decorate(fn):
|
115
122
|
@wraps(fn)
|
116
123
|
async def wrap(*args, **kwargs):
|
117
|
-
if not
|
124
|
+
if not TracerWrapper.verify_initialized():
|
118
125
|
return await fn(*args, **kwargs)
|
119
126
|
|
120
127
|
span_name = name or fn.__name__
|
@@ -126,9 +133,15 @@ def aentity_method(
|
|
126
133
|
ctx_token = context_api.attach(ctx)
|
127
134
|
|
128
135
|
try:
|
129
|
-
if
|
136
|
+
if not ignore_input:
|
130
137
|
inp = json_dumps(
|
131
|
-
get_input_from_func_args(
|
138
|
+
get_input_from_func_args(
|
139
|
+
fn,
|
140
|
+
is_method=is_method(fn),
|
141
|
+
func_args=args,
|
142
|
+
func_kwargs=kwargs,
|
143
|
+
ignore_inputs=ignore_inputs,
|
144
|
+
)
|
132
145
|
)
|
133
146
|
if len(inp) > MAX_MANUAL_SPAN_PAYLOAD_SIZE:
|
134
147
|
span.set_attribute(
|
@@ -151,7 +164,7 @@ def aentity_method(
|
|
151
164
|
return await _ahandle_generator(span, ctx_token, res)
|
152
165
|
|
153
166
|
try:
|
154
|
-
if
|
167
|
+
if not ignore_output:
|
155
168
|
output = json_dumps(res)
|
156
169
|
if len(output) > MAX_MANUAL_SPAN_PAYLOAD_SIZE:
|
157
170
|
span.set_attribute(
|
@@ -192,12 +205,6 @@ async def _ahandle_generator(span, ctx_token, res):
|
|
192
205
|
context_api.detach(ctx_token)
|
193
206
|
|
194
207
|
|
195
|
-
def _should_send_prompts():
|
196
|
-
return (
|
197
|
-
os.getenv("TRACELOOP_TRACE_CONTENT") or "true"
|
198
|
-
).lower() == "true" or context_api.get_value("override_enable_content_tracing")
|
199
|
-
|
200
|
-
|
201
208
|
def _process_exception(span: Span, e: Exception):
|
202
209
|
# Note that this `escaped` is sent as a StringValue("True"), not a boolean.
|
203
210
|
span.record_exception(e, escaped=True)
|
@@ -11,6 +11,7 @@ class Instruments(Enum):
|
|
11
11
|
CHROMA = "chroma"
|
12
12
|
COHERE = "cohere"
|
13
13
|
GOOGLE_GENERATIVEAI = "google_generativeai"
|
14
|
+
GOOGLE_GENAI = "google_genai"
|
14
15
|
GROQ = "groq"
|
15
16
|
HAYSTACK = "haystack"
|
16
17
|
LANCEDB = "lancedb"
|
@@ -23,6 +24,7 @@ class Instruments(Enum):
|
|
23
24
|
OPENAI = "openai"
|
24
25
|
PINECONE = "pinecone"
|
25
26
|
PLAYWRIGHT = "playwright"
|
27
|
+
PATCHRIGHT = "patchright"
|
26
28
|
QDRANT = "qdrant"
|
27
29
|
REPLICATE = "replicate"
|
28
30
|
SAGEMAKER = "sagemaker"
|