lmnr 0.4.17b0__py2.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 +5 -0
- lmnr/cli.py +39 -0
- lmnr/sdk/__init__.py +0 -0
- lmnr/sdk/decorators.py +66 -0
- lmnr/sdk/evaluations.py +354 -0
- lmnr/sdk/laminar.py +403 -0
- lmnr/sdk/log.py +39 -0
- lmnr/sdk/types.py +155 -0
- lmnr/sdk/utils.py +99 -0
- lmnr/traceloop_sdk/.flake8 +12 -0
- lmnr/traceloop_sdk/.python-version +1 -0
- lmnr/traceloop_sdk/__init__.py +89 -0
- lmnr/traceloop_sdk/config/__init__.py +9 -0
- lmnr/traceloop_sdk/decorators/__init__.py +0 -0
- lmnr/traceloop_sdk/decorators/base.py +178 -0
- lmnr/traceloop_sdk/instruments.py +34 -0
- lmnr/traceloop_sdk/tests/__init__.py +1 -0
- lmnr/traceloop_sdk/tests/cassettes/test_association_properties/test_langchain_and_external_association_properties.yaml +101 -0
- lmnr/traceloop_sdk/tests/cassettes/test_association_properties/test_langchain_association_properties.yaml +99 -0
- lmnr/traceloop_sdk/tests/cassettes/test_manual/test_manual_report.yaml +98 -0
- lmnr/traceloop_sdk/tests/cassettes/test_manual/test_resource_attributes.yaml +98 -0
- lmnr/traceloop_sdk/tests/cassettes/test_privacy_no_prompts/test_simple_workflow.yaml +199 -0
- lmnr/traceloop_sdk/tests/cassettes/test_prompt_management/test_prompt_management.yaml +202 -0
- lmnr/traceloop_sdk/tests/cassettes/test_sdk_initialization/test_resource_attributes.yaml +199 -0
- lmnr/traceloop_sdk/tests/cassettes/test_tasks/test_task_io_serialization_with_langchain.yaml +96 -0
- lmnr/traceloop_sdk/tests/cassettes/test_workflows/test_simple_aworkflow.yaml +98 -0
- lmnr/traceloop_sdk/tests/cassettes/test_workflows/test_simple_workflow.yaml +199 -0
- lmnr/traceloop_sdk/tests/cassettes/test_workflows/test_streaming_workflow.yaml +167 -0
- lmnr/traceloop_sdk/tests/conftest.py +111 -0
- lmnr/traceloop_sdk/tests/test_association_properties.py +229 -0
- lmnr/traceloop_sdk/tests/test_manual.py +48 -0
- lmnr/traceloop_sdk/tests/test_nested_tasks.py +47 -0
- lmnr/traceloop_sdk/tests/test_privacy_no_prompts.py +50 -0
- lmnr/traceloop_sdk/tests/test_sdk_initialization.py +57 -0
- lmnr/traceloop_sdk/tests/test_tasks.py +32 -0
- lmnr/traceloop_sdk/tests/test_workflows.py +262 -0
- lmnr/traceloop_sdk/tracing/__init__.py +1 -0
- lmnr/traceloop_sdk/tracing/attributes.py +9 -0
- lmnr/traceloop_sdk/tracing/content_allow_list.py +24 -0
- lmnr/traceloop_sdk/tracing/context_manager.py +13 -0
- lmnr/traceloop_sdk/tracing/tracing.py +913 -0
- lmnr/traceloop_sdk/utils/__init__.py +26 -0
- lmnr/traceloop_sdk/utils/in_memory_span_exporter.py +61 -0
- lmnr/traceloop_sdk/utils/json_encoder.py +20 -0
- lmnr/traceloop_sdk/utils/package_check.py +8 -0
- lmnr/traceloop_sdk/version.py +1 -0
- lmnr-0.4.17b0.dist-info/LICENSE +75 -0
- lmnr-0.4.17b0.dist-info/METADATA +250 -0
- lmnr-0.4.17b0.dist-info/RECORD +50 -0
- lmnr-0.4.17b0.dist-info/WHEEL +4 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
def cameltosnake(camel_string: str) -> str:
|
2
|
+
if not camel_string:
|
3
|
+
return ""
|
4
|
+
elif camel_string[0].isupper():
|
5
|
+
return f"_{camel_string[0].lower()}{cameltosnake(camel_string[1:])}"
|
6
|
+
else:
|
7
|
+
return f"{camel_string[0]}{cameltosnake(camel_string[1:])}"
|
8
|
+
|
9
|
+
|
10
|
+
def camel_to_snake(s):
|
11
|
+
if len(s) <= 1:
|
12
|
+
return s.lower()
|
13
|
+
|
14
|
+
return cameltosnake(s[0].lower() + s[1:])
|
15
|
+
|
16
|
+
|
17
|
+
def is_notebook():
|
18
|
+
try:
|
19
|
+
from IPython import get_ipython
|
20
|
+
|
21
|
+
ip = get_ipython()
|
22
|
+
if ip is None:
|
23
|
+
return False
|
24
|
+
return True
|
25
|
+
except Exception:
|
26
|
+
return False
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Copyright The OpenTelemetry Authors
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
import threading
|
16
|
+
import typing
|
17
|
+
|
18
|
+
from opentelemetry.sdk.trace import ReadableSpan
|
19
|
+
from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult
|
20
|
+
|
21
|
+
|
22
|
+
class InMemorySpanExporter(SpanExporter):
|
23
|
+
"""Implementation of :class:`.SpanExporter` that stores spans in memory.
|
24
|
+
|
25
|
+
This class can be used for testing purposes. It stores the exported spans
|
26
|
+
in a list in memory that can be retrieved using the
|
27
|
+
:func:`.get_finished_spans` method.
|
28
|
+
"""
|
29
|
+
|
30
|
+
def __init__(self) -> None:
|
31
|
+
self._finished_spans: typing.List[ReadableSpan] = []
|
32
|
+
self._stopped = False
|
33
|
+
self._lock = threading.Lock()
|
34
|
+
|
35
|
+
def clear(self) -> None:
|
36
|
+
"""Clear list of collected spans."""
|
37
|
+
with self._lock:
|
38
|
+
self._finished_spans.clear()
|
39
|
+
|
40
|
+
def get_finished_spans(self) -> typing.Tuple[ReadableSpan, ...]:
|
41
|
+
"""Get list of collected spans."""
|
42
|
+
with self._lock:
|
43
|
+
return tuple(self._finished_spans)
|
44
|
+
|
45
|
+
def export(self, spans: typing.Sequence[ReadableSpan]) -> SpanExportResult:
|
46
|
+
"""Stores a list of spans in memory."""
|
47
|
+
if self._stopped:
|
48
|
+
return SpanExportResult.FAILURE
|
49
|
+
with self._lock:
|
50
|
+
self._finished_spans.extend(spans)
|
51
|
+
return SpanExportResult.SUCCESS
|
52
|
+
|
53
|
+
def shutdown(self) -> None:
|
54
|
+
"""Shut downs the exporter.
|
55
|
+
|
56
|
+
Calls to export after the exporter has been shut down will fail.
|
57
|
+
"""
|
58
|
+
self._stopped = True
|
59
|
+
|
60
|
+
def force_flush(self, timeout_millis: int = 30000) -> bool:
|
61
|
+
return True
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import dataclasses
|
2
|
+
import json
|
3
|
+
|
4
|
+
|
5
|
+
class JSONEncoder(json.JSONEncoder):
|
6
|
+
def default(self, o):
|
7
|
+
if isinstance(o, dict):
|
8
|
+
if "callbacks" in o:
|
9
|
+
del o["callbacks"]
|
10
|
+
return o
|
11
|
+
if dataclasses.is_dataclass(o):
|
12
|
+
return dataclasses.asdict(o)
|
13
|
+
|
14
|
+
if hasattr(o, "to_json"):
|
15
|
+
return o.to_json()
|
16
|
+
|
17
|
+
if hasattr(o, "json"):
|
18
|
+
return o.json()
|
19
|
+
|
20
|
+
return super().default(o)
|
@@ -0,0 +1 @@
|
|
1
|
+
__version__ = "0.30.0"
|
@@ -0,0 +1,75 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
Apache License
|
4
|
+
Version 2.0, January 2004
|
5
|
+
http://www.apache.org/licenses/
|
6
|
+
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
8
|
+
|
9
|
+
1. Definitions.
|
10
|
+
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
16
|
+
|
17
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
18
|
+
|
19
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
20
|
+
|
21
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
22
|
+
|
23
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
24
|
+
|
25
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
26
|
+
|
27
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
28
|
+
|
29
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
30
|
+
|
31
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
32
|
+
|
33
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
34
|
+
|
35
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
36
|
+
|
37
|
+
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
38
|
+
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
39
|
+
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
40
|
+
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
41
|
+
|
42
|
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
43
|
+
|
44
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
45
|
+
|
46
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
47
|
+
|
48
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
49
|
+
|
50
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
51
|
+
|
52
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
53
|
+
|
54
|
+
END OF TERMS AND CONDITIONS
|
55
|
+
|
56
|
+
|
57
|
+
APPENDIX: How to apply the Apache License to your work
|
58
|
+
|
59
|
+
Include a copy of the Apache License, typically in a file called LICENSE, in your work, and consider also including a NOTICE file that references the License.
|
60
|
+
|
61
|
+
To apply the Apache License to specific files in your work, attach the following boilerplate declaration, replacing the fields enclosed by brackets "[]" with your own identifying information. (Don't include the brackets!) Enclose the text in the appropriate comment syntax for the file format. We also recommend that you include a file or class name and description of purpose on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
62
|
+
|
63
|
+
Copyright 2024 LMNR AI, Inc.
|
64
|
+
|
65
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
66
|
+
you may not use this file except in compliance with the License.
|
67
|
+
You may obtain a copy of the License at
|
68
|
+
|
69
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
70
|
+
|
71
|
+
Unless required by applicable law or agreed to in writing, software
|
72
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
73
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
74
|
+
See the License for the specific language governing permissions and
|
75
|
+
limitations under the License.
|
@@ -0,0 +1,250 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: lmnr
|
3
|
+
Version: 0.4.17b0
|
4
|
+
Summary: Python SDK for Laminar
|
5
|
+
License: Apache-2.0
|
6
|
+
Author: lmnr.ai
|
7
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
8
|
+
Classifier: Programming Language :: Python :: 2
|
9
|
+
Classifier: Programming Language :: Python :: 2.7
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
11
|
+
Classifier: Programming Language :: Python :: 3.4
|
12
|
+
Classifier: Programming Language :: Python :: 3.5
|
13
|
+
Classifier: Programming Language :: Python :: 3.6
|
14
|
+
Classifier: Programming Language :: Python :: 3.7
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
20
|
+
Description-Content-Type: text/markdown
|
21
|
+
|
22
|
+
# Laminar Python
|
23
|
+
|
24
|
+
Python SDK for [Laminar](https://www.lmnr.ai).
|
25
|
+
|
26
|
+
[Laminar](https://www.lmnr.ai) is an open-source platform for engineering LLM products. Trace, evaluate, annotate, and analyze LLM data. Bring LLM applications to production with confidence.
|
27
|
+
|
28
|
+
Check our [open-source repo](https://github.com/lmnr-ai/lmnr) and don't forget to star it ⭐
|
29
|
+
|
30
|
+
<a href="https://pypi.org/project/lmnr/">  </a>
|
31
|
+

|
32
|
+

|
33
|
+
|
34
|
+
|
35
|
+
## Quickstart
|
36
|
+
|
37
|
+
First, install the package:
|
38
|
+
|
39
|
+
```sh
|
40
|
+
pip install lmnr
|
41
|
+
```
|
42
|
+
|
43
|
+
And then in the code
|
44
|
+
|
45
|
+
```python
|
46
|
+
from lmnr import Laminar as L
|
47
|
+
|
48
|
+
L.initialize(project_api_key="<PROJECT_API_KEY>")
|
49
|
+
```
|
50
|
+
|
51
|
+
This will automatically instrument most of the LLM, Vector DB, and related
|
52
|
+
calls with OpenTelemetry-compatible instrumentation.
|
53
|
+
|
54
|
+
Note that you need to only initialize Laminar once in your application.
|
55
|
+
|
56
|
+
## Instrumentation
|
57
|
+
|
58
|
+
### Manual instrumentation
|
59
|
+
|
60
|
+
To instrument any function in your code, we provide a simple `@observe()` decorator.
|
61
|
+
This can be useful if you want to trace a request handler or a function which combines multiple LLM calls.
|
62
|
+
|
63
|
+
```python
|
64
|
+
import os
|
65
|
+
from openai import OpenAI
|
66
|
+
from lmnr import Laminar as L, Instruments
|
67
|
+
|
68
|
+
L.initialize(project_api_key=os.environ["LMNR_PROJECT_API_KEY"])
|
69
|
+
|
70
|
+
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
|
71
|
+
|
72
|
+
def poem_writer(topic: str):
|
73
|
+
prompt = f"write a poem about {topic}"
|
74
|
+
messages = [
|
75
|
+
{"role": "system", "content": "You are a helpful assistant."},
|
76
|
+
{"role": "user", "content": prompt},
|
77
|
+
]
|
78
|
+
|
79
|
+
# OpenAI calls are still automatically instrumented
|
80
|
+
response = client.chat.completions.create(
|
81
|
+
model="gpt-4o",
|
82
|
+
messages=messages,
|
83
|
+
)
|
84
|
+
poem = response.choices[0].message.content
|
85
|
+
|
86
|
+
return poem
|
87
|
+
|
88
|
+
@observe()
|
89
|
+
def generate_poems():
|
90
|
+
poem1 = poem_writer(topic="laminar flow")
|
91
|
+
L.event("is_poem_generated", True)
|
92
|
+
poem2 = poem_writer(topic="turbulence")
|
93
|
+
L.event("is_poem_generated", True)
|
94
|
+
poems = f"{poem1}\n\n---\n\n{poem2}"
|
95
|
+
return poems
|
96
|
+
```
|
97
|
+
|
98
|
+
Also, you can use `Laminar.start_as_current_span` if you want to record a chunk of your code using `with` statement.
|
99
|
+
|
100
|
+
```python
|
101
|
+
def handle_user_request(topic: str):
|
102
|
+
with L.start_as_current_span(name="poem_writer", input=topic):
|
103
|
+
...
|
104
|
+
|
105
|
+
poem = poem_writer(topic=topic)
|
106
|
+
|
107
|
+
...
|
108
|
+
|
109
|
+
# while within the span, you can attach laminar events to it
|
110
|
+
L.event("is_poem_generated", True)
|
111
|
+
|
112
|
+
# Use set_span_output to record the output of the span
|
113
|
+
L.set_span_output(poem)
|
114
|
+
```
|
115
|
+
|
116
|
+
### Automatic instrumentation
|
117
|
+
|
118
|
+
Laminar allows you to automatically instrument majority of the most popular LLM, Vector DB, database, requests, and other libraries.
|
119
|
+
|
120
|
+
If you want to automatically instrument a default set of libraries, then simply do NOT pass `instruments` argument to `.initialize()`.
|
121
|
+
See the full list of available instrumentations in the [enum](/src/lmnr/traceloop_sdk/instruments.py).
|
122
|
+
|
123
|
+
If you want to automatically instrument only specific LLM, Vector DB, or other
|
124
|
+
calls with OpenTelemetry-compatible instrumentation, then pass the appropriate instruments to `.initialize()`.
|
125
|
+
For example, if you want to only instrument OpenAI and Anthropic, then do the following:
|
126
|
+
|
127
|
+
```python
|
128
|
+
from lmnr import Laminar as L, Instruments
|
129
|
+
|
130
|
+
L.initialize(project_api_key=os.environ["LMNR_PROJECT_API_KEY"], instruments={Instruments.OPENAI, Instruments.ANTHROPIC})
|
131
|
+
```
|
132
|
+
|
133
|
+
If you want to fully disable any kind of autoinstrumentation, pass an empty set as `instruments=set()` to `.initialize()`.
|
134
|
+
|
135
|
+
Autoinstrumentations are provided by Traceloop's [OpenLLMetry](https://github.com/traceloop/openllmetry).
|
136
|
+
|
137
|
+
## Sending events
|
138
|
+
|
139
|
+
You can send laminar events using `L.event(name, value)`.
|
140
|
+
|
141
|
+
Read our [docs](https://docs.lmnr.ai) to learn more about events and examples.
|
142
|
+
|
143
|
+
### Example
|
144
|
+
|
145
|
+
```python
|
146
|
+
from lmnr import Laminar as L
|
147
|
+
# ...
|
148
|
+
poem = response.choices[0].message.content
|
149
|
+
|
150
|
+
# this will register True or False value with Laminar
|
151
|
+
L.event("topic alignment", topic in poem)
|
152
|
+
|
153
|
+
```
|
154
|
+
|
155
|
+
## Evaluations
|
156
|
+
|
157
|
+
### Quickstart
|
158
|
+
|
159
|
+
Install the package:
|
160
|
+
|
161
|
+
```sh
|
162
|
+
pip install lmnr
|
163
|
+
```
|
164
|
+
|
165
|
+
Create a file named `my_first_eval.py` with the following code:
|
166
|
+
|
167
|
+
```python
|
168
|
+
from lmnr import evaluate
|
169
|
+
|
170
|
+
def write_poem(data):
|
171
|
+
return f"This is a good poem about {data['topic']}"
|
172
|
+
|
173
|
+
def contains_poem(output, target):
|
174
|
+
return 1 if output in target['poem'] else 0
|
175
|
+
|
176
|
+
# Evaluation data
|
177
|
+
data = [
|
178
|
+
{"data": {"topic": "flowers"}, "target": {"poem": "This is a good poem about flowers"}},
|
179
|
+
{"data": {"topic": "cars"}, "target": {"poem": "I like cars"}},
|
180
|
+
]
|
181
|
+
|
182
|
+
evaluate(
|
183
|
+
data=data,
|
184
|
+
executor=write_poem,
|
185
|
+
evaluators={
|
186
|
+
"containsPoem": contains_poem
|
187
|
+
},
|
188
|
+
group_id="my_first_feature"
|
189
|
+
)
|
190
|
+
```
|
191
|
+
|
192
|
+
Run the following commands:
|
193
|
+
|
194
|
+
```sh
|
195
|
+
export LMNR_PROJECT_API_KEY=<YOUR_PROJECT_API_KEY> # get from Laminar project settings
|
196
|
+
lmnr eval my_first_eval.py # run in the virtual environment where lmnr is installed
|
197
|
+
```
|
198
|
+
|
199
|
+
Visit the URL printed in the console to see the results.
|
200
|
+
|
201
|
+
### Overview
|
202
|
+
|
203
|
+
Bring rigor to the development of your LLM applications with evaluations.
|
204
|
+
|
205
|
+
You can run evaluations locally by providing executor (part of the logic used in your application) and evaluators (numeric scoring functions) to `evaluate` function.
|
206
|
+
|
207
|
+
`evaluate` takes in the following parameters:
|
208
|
+
- `data` – an array of `EvaluationDatapoint` objects, where each `EvaluationDatapoint` has two keys: `target` and `data`, each containing a key-value object. Alternatively, you can pass in dictionaries, and we will instantiate `EvaluationDatapoint`s with pydantic if possible
|
209
|
+
- `executor` – the logic you want to evaluate. This function must take `data` as the first argument, and produce any output. It can be both a function or an `async` function.
|
210
|
+
- `evaluators` – Dictionary which maps evaluator names to evaluators. Functions that take output of executor as the first argument, `target` as the second argument and produce a numeric scores. Each function can produce either a single number or `dict[str, int|float]` of scores. Each evaluator can be both a function or an `async` function.
|
211
|
+
- `name` – optional name for the evaluation. Automatically generated if not provided.
|
212
|
+
|
213
|
+
\* If you already have the outputs of executors you want to evaluate, you can specify the executor as an identity function, that takes in `data` and returns only needed value(s) from it.
|
214
|
+
|
215
|
+
[Read docs](https://docs.lmnr.ai/evaluations/introduction) to learn more about evaluations.
|
216
|
+
|
217
|
+
## Laminar pipelines as prompt chain managers
|
218
|
+
|
219
|
+
You can create Laminar pipelines in the UI and manage chains of LLM calls there.
|
220
|
+
|
221
|
+
After you are ready to use your pipeline in your code, deploy it in Laminar by selecting the target version for the pipeline.
|
222
|
+
|
223
|
+
Once your pipeline target is set, you can call it from Python in just a few lines.
|
224
|
+
|
225
|
+
Example use:
|
226
|
+
|
227
|
+
```python
|
228
|
+
from lmnr import Laminar as L
|
229
|
+
|
230
|
+
L.initialize('<YOUR_PROJECT_API_KEY>', instruments=set())
|
231
|
+
|
232
|
+
result = l.run(
|
233
|
+
pipeline = 'my_pipeline_name',
|
234
|
+
inputs = {'input_node_name': 'some_value'},
|
235
|
+
# all environment variables
|
236
|
+
env = {'OPENAI_API_KEY': 'sk-some-key'},
|
237
|
+
)
|
238
|
+
```
|
239
|
+
|
240
|
+
Resulting in:
|
241
|
+
|
242
|
+
```python
|
243
|
+
>>> result
|
244
|
+
PipelineRunResponse(
|
245
|
+
outputs={'output': {'value': [ChatMessage(role='user', content='hello')]}},
|
246
|
+
# useful to locate your trace
|
247
|
+
run_id='53b012d5-5759-48a6-a9c5-0011610e3669'
|
248
|
+
)
|
249
|
+
```
|
250
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
lmnr/__init__.py,sha256=5Ks8UIicCzCBgwSz0MOX3I7jVruPMUO3SmxIwUoODzQ,231
|
2
|
+
lmnr/cli.py,sha256=Ptvm5dsNLKUY5lwnN8XkT5GtCYjzpRNi2WvefknB3OQ,1079
|
3
|
+
lmnr/sdk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
+
lmnr/sdk/decorators.py,sha256=ZSDaEZyjo-RUzRCltsNbe6x0t9SKl2xRQ2q4uaKvXtk,2250
|
5
|
+
lmnr/sdk/evaluations.py,sha256=Tukl2pW_x13ittzG5XQpF1TweYo3fpD4eLInplQ4YYI,14152
|
6
|
+
lmnr/sdk/laminar.py,sha256=h1-qjutXkyfUNaKmnHmjSE7KYzbOc4g4juLAgaaOXMI,14719
|
7
|
+
lmnr/sdk/log.py,sha256=EgAMY77Zn1bv1imCqrmflD3imoAJ2yveOkIcrIP3e98,1170
|
8
|
+
lmnr/sdk/types.py,sha256=HvaZEqVRduCZbkF7Cp8rgS5oBbc1qPvOD3PP9tFrRu4,4826
|
9
|
+
lmnr/sdk/utils.py,sha256=s81p6uJehgJSaLWy3sR5fTpEDH7vzn3i_UujUHChl6M,3346
|
10
|
+
lmnr/traceloop_sdk/.flake8,sha256=bCxuDlGx3YQ55QHKPiGJkncHanh9qGjQJUujcFa3lAU,150
|
11
|
+
lmnr/traceloop_sdk/.python-version,sha256=9OLQBQVbD4zE4cJsPePhnAfV_snrPSoqEQw-PXgPMOs,6
|
12
|
+
lmnr/traceloop_sdk/__init__.py,sha256=hp3q1OsFaGgaQCEanJrL38BJN32hWqCNVCSjYpndEsY,2957
|
13
|
+
lmnr/traceloop_sdk/config/__init__.py,sha256=DliMGp2NjYAqRFLKpWQPUKjGMHRO8QsVfazBA1qENQ8,248
|
14
|
+
lmnr/traceloop_sdk/decorators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
15
|
+
lmnr/traceloop_sdk/decorators/base.py,sha256=-b8Q738m3StdLTgHARx8zw78m9htynKkZFFTYURQnOA,5524
|
16
|
+
lmnr/traceloop_sdk/instruments.py,sha256=oMvIASueW3GeChpjIdH-DD9aFBVB8OtHZ0HawppTrlI,942
|
17
|
+
lmnr/traceloop_sdk/tests/__init__.py,sha256=RYnG0-8zbXL0-2Ste1mEBf5sN4d_rQjGTCgPBuaZC74,20
|
18
|
+
lmnr/traceloop_sdk/tests/cassettes/test_association_properties/test_langchain_and_external_association_properties.yaml,sha256=26g0wRA0juicHg_XrhcE8H4vhs1lawDs0o0aLFn-I7w,3103
|
19
|
+
lmnr/traceloop_sdk/tests/cassettes/test_association_properties/test_langchain_association_properties.yaml,sha256=FNlSWlYCsWc3w7UPZzfGjDnxS3gAOhL-kpsu4BTxsDE,3061
|
20
|
+
lmnr/traceloop_sdk/tests/cassettes/test_manual/test_manual_report.yaml,sha256=iq_U_DBKNyM8mhgwGZrqw1OMalIb3g1422cqkvsrPHw,2956
|
21
|
+
lmnr/traceloop_sdk/tests/cassettes/test_manual/test_resource_attributes.yaml,sha256=IxAYRGTo46TtVsbxwLY2MPjgNehnvBVhzrH2ErHGxNA,2936
|
22
|
+
lmnr/traceloop_sdk/tests/cassettes/test_privacy_no_prompts/test_simple_workflow.yaml,sha256=4KUVSMVLOMzubVXqwKY7ukhrQEXTtysa0RyPXydMu0c,5861
|
23
|
+
lmnr/traceloop_sdk/tests/cassettes/test_prompt_management/test_prompt_management.yaml,sha256=ASroB5TiDVoJ1pUIQte4rajjlOs7XclIjDxPT9EpVmA,6142
|
24
|
+
lmnr/traceloop_sdk/tests/cassettes/test_sdk_initialization/test_resource_attributes.yaml,sha256=gUQ1mlrDG-2qmp7E6nmQ8ma7T0EeYL6Ve0nIZkmkEJ0,5877
|
25
|
+
lmnr/traceloop_sdk/tests/cassettes/test_tasks/test_task_io_serialization_with_langchain.yaml,sha256=OLtmIMglgFwNOIFSzZ5Xye6mO6PA5gPfHf2db6U_uPQ,2852
|
26
|
+
lmnr/traceloop_sdk/tests/cassettes/test_workflows/test_simple_aworkflow.yaml,sha256=xbol_wTn-SeEanT4kLY4Y2_HLCTZf0ZHRFkPw402gqI,2944
|
27
|
+
lmnr/traceloop_sdk/tests/cassettes/test_workflows/test_simple_workflow.yaml,sha256=ueiJY_6pyKQwbuMpeTAqHui4Ux7kYq_KTBZSob-cAjc,5866
|
28
|
+
lmnr/traceloop_sdk/tests/cassettes/test_workflows/test_streaming_workflow.yaml,sha256=flOkiaW0DnQfD4rn_9F9dA0nIGMFjqwR3UzPyaanVjE,7947
|
29
|
+
lmnr/traceloop_sdk/tests/conftest.py,sha256=XG6U9T6OyQliJUS8sBTXStjIP7Bb6ZChWTt0fulvHuc,3039
|
30
|
+
lmnr/traceloop_sdk/tests/test_association_properties.py,sha256=D_LxhiVLwyXE0eW70uztmvZh3RRbVucM0L2C7O1oaFk,6735
|
31
|
+
lmnr/traceloop_sdk/tests/test_manual.py,sha256=YHmVYfDfFUalAzYQsz50PIzXdj3Jfjcl4erpBU4ae4A,1759
|
32
|
+
lmnr/traceloop_sdk/tests/test_nested_tasks.py,sha256=o7GPLVdgQOI5YH5HMBjInW4sprY4Nlu4SuwjMr1dxWU,1377
|
33
|
+
lmnr/traceloop_sdk/tests/test_privacy_no_prompts.py,sha256=lS8bwg_xOS4gcwwzrrWflMkTSn8eZWyTmAxL3h3hZA0,1478
|
34
|
+
lmnr/traceloop_sdk/tests/test_sdk_initialization.py,sha256=fRaf6lrxFzJIN94P1Tav_z_eywOsF5JXLPWzbJPMMyQ,1477
|
35
|
+
lmnr/traceloop_sdk/tests/test_tasks.py,sha256=xlEx8BKp4yG83SCjK5WkPGfyC33JSrx4h8VyjVwGbgw,906
|
36
|
+
lmnr/traceloop_sdk/tests/test_workflows.py,sha256=RVcfY3WAFIDZC15-aSua21aoQyYeWE7KypDyUsm-2EM,9372
|
37
|
+
lmnr/traceloop_sdk/tracing/__init__.py,sha256=Ckq7zCM26VdJVB5tIZv0GTPyMZKyfso_KWD5yPHaqdo,66
|
38
|
+
lmnr/traceloop_sdk/tracing/attributes.py,sha256=PXwS1GCZKdjQSypl__BSkQNZhh21RyzwTPnDOh61bnQ,250
|
39
|
+
lmnr/traceloop_sdk/tracing/content_allow_list.py,sha256=3feztm6PBWNelc8pAZUcQyEGyeSpNiVKjOaDk65l2ps,846
|
40
|
+
lmnr/traceloop_sdk/tracing/context_manager.py,sha256=csVlB6kDmbgSPsROHwnddvGGblx55v6lJMRj0wsSMQM,304
|
41
|
+
lmnr/traceloop_sdk/tracing/tracing.py,sha256=pB8vImUZRMaahkHLaQP73cbMtYDyvpvEdWsa49520Yo,36061
|
42
|
+
lmnr/traceloop_sdk/utils/__init__.py,sha256=pNhf0G3vTd5ccoc03i1MXDbricSaiqCbi1DLWhSekK8,604
|
43
|
+
lmnr/traceloop_sdk/utils/in_memory_span_exporter.py,sha256=H_4TRaThMO1H6vUQ0OpQvzJk_fZH0OOsRAM1iZQXsR8,2112
|
44
|
+
lmnr/traceloop_sdk/utils/json_encoder.py,sha256=dK6b_axr70IYL7Vv-bu4wntvDDuyntoqsHaddqX7P58,463
|
45
|
+
lmnr/traceloop_sdk/utils/package_check.py,sha256=TZSngzJOpFhfUZLXIs38cpMxQiZSmp0D-sCrIyhz7BA,251
|
46
|
+
lmnr/traceloop_sdk/version.py,sha256=OlatFEFA4ttqSSIiV8jdE-sq3KG5zu2hnC4B4mzWF3s,23
|
47
|
+
lmnr-0.4.17b0.dist-info/LICENSE,sha256=67b_wJHVV1CBaWkrKFWU1wyqTPSdzH77Ls-59631COg,10411
|
48
|
+
lmnr-0.4.17b0.dist-info/METADATA,sha256=366GkUooPoQdQ7MUtHf4RaUqJqsdNNpPSCX9s1tkJag,8273
|
49
|
+
lmnr-0.4.17b0.dist-info/WHEEL,sha256=IrRNNNJ-uuL1ggO5qMvT1GGhQVdQU54d6ZpYqEZfEWo,92
|
50
|
+
lmnr-0.4.17b0.dist-info/RECORD,,
|