lmnr 0.4.9__py3-none-any.whl → 0.4.10__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 CHANGED
@@ -2,3 +2,4 @@ from .sdk.evaluations import Evaluation
2
2
  from .sdk.laminar import Laminar
3
3
  from .sdk.types import ChatMessage, PipelineRunError, PipelineRunResponse, NodeInput
4
4
  from .sdk.decorators import observe
5
+ from .traceloop_sdk import Instruments
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lmnr
3
- Version: 0.4.9
3
+ Version: 0.4.10
4
4
  Summary: Python SDK for Laminar AI
5
5
  License: Apache-2.0
6
6
  Author: lmnr.ai
@@ -77,18 +77,19 @@ pip install lmnr
77
77
  And the in your main Python file
78
78
 
79
79
  ```python
80
- from lmnr import Laminar as L
80
+ from lmnr import Laminar as L, Instruments
81
81
 
82
- L.initialize(project_api_key="<LMNR_PROJECT_API_KEY>", instruments=set())
82
+ L.initialize(project_api_key="<LMNR_PROJECT_API_KEY>", instruments={Instruments.OPENAI, Instruments.ANTHROPIC})
83
83
  ```
84
84
 
85
85
  If you want to automatically instrument particular LLM, Vector DB, and related
86
86
  calls with OpenTelemetry-compatible instrumentation, then pass the appropriate instruments to `.initialize()`.
87
87
 
88
+ You can pass an empty set as `instruments=set()` to disable any kind of automatic instrumentation.
88
89
  Also if you want to automatically instrument all supported libraries, then pass `instruments=None` or don't pass `instruments` at all.
89
90
 
90
- We rely on the amazing [OpenLLMetry](https://github.com/traceloop/openllmetry), open-source package
91
- by TraceLoop, to achieve that.
91
+ Our code is based on the [OpenLLMetry](https://github.com/traceloop/openllmetry), open-source package
92
+ by TraceLoop. Also, we are grateful to Traceloop for implementing autoinstrumentations for many libraries.
92
93
 
93
94
  ### Project API key
94
95
 
@@ -107,8 +108,8 @@ import os
107
108
  from openai import OpenAI
108
109
 
109
110
 
110
- from lmnr import observe, Laminar as L
111
- L.initialize(project_api_key="<LMNR_PROJECT_API_KEY>", instruments=set())
111
+ from lmnr import observe, Laminar as L, Instruments
112
+ L.initialize(project_api_key="<LMNR_PROJECT_API_KEY>", instruments={Instruments.OPENAI})
112
113
 
113
114
  client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
114
115
 
@@ -130,40 +131,32 @@ print(poem_writer(topic="laminar flow"))
130
131
 
131
132
  ### Manual instrumentation
132
133
 
133
- Our manual instrumentation is a very thin wrapper around OpenTelemetry's
134
- `trace.start_span`. Our wrapper sets the span into the active context.
135
- You don't have to explicitly pass the spans around, it is enough to
136
- just call `L.start_span`, and OpenTelemetry will handle the context management
134
+ Also, you can `Laminar.start_as_current_span` if you want to record a chunk of your code.
137
135
 
138
136
  ```python
139
- from lmnr import observe, Laminar as L
140
- L.initialize(project_api_key="<LMNR_PROJECT_API_KEY>", instruments=set())
137
+ from lmnr import observe, Laminar as L, Instruments
138
+ L.initialize(project_api_key="<LMNR_PROJECT_API_KEY>", instruments={Instruments.OPENAI})
141
139
 
142
140
  def poem_writer(topic="turbulence"):
143
-
144
- span = L.start_span("poem_writer", topic) # start a span
145
-
146
141
  prompt = f"write a poem about {topic}"
147
-
148
- # OpenAI calls are still automatically instrumented with OpenLLMetry
149
- response = client.chat.completions.create(
150
- model="gpt-4o",
151
- messages=[
152
- {"role": "system", "content": "You are a helpful assistant."},
153
- {"role": "user", "content": prompt},
154
- ],
155
- )
156
- poem = response.choices[0].message.content
157
- # while within the span, you can attach laminar events to it
158
- L.event("event_name", "event_value")
159
-
160
- L.set_span_output(poem) # set an output
161
-
162
- # IMPORTANT: don't forget to end all the spans (usually in `finally` blocks)
163
- # Otherwise, the trace may not be sent/displayed correctly
164
- span.end()
165
-
166
- return poem
142
+ messages = [
143
+ {"role": "system", "content": "You are a helpful assistant."},
144
+ {"role": "user", "content": prompt},
145
+ ]
146
+
147
+ with L.start_as_current_span(name="poem_writer", input=messages):
148
+ # OpenAI calls are still automatically instrumented with OpenLLMetry
149
+ response = client.chat.completions.create(
150
+ model="gpt-4o",
151
+ messages=messages,
152
+ )
153
+ poem = response.choices[0].message.content
154
+ # while within the span, you can attach laminar events to it
155
+ L.event("event_name", "event_value")
156
+
157
+ L.set_span_output(poem) # set an output
158
+
159
+ return poem
167
160
  ```
168
161
 
169
162
 
@@ -1,4 +1,4 @@
1
- lmnr/__init__.py,sha256=wQwnHl662Xcz7GdSofFsEjmAK0nxioYA2Yq6Q78m4ps,194
1
+ lmnr/__init__.py,sha256=bA1f7JsEdSdU93HTz3SQLSanq-UgZGvb5I2OE0CWGR8,233
2
2
  lmnr/sdk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  lmnr/sdk/decorators.py,sha256=W46diLcINe0HAhxktrjbfQnaIfklSb0AydBHHxiko9U,2314
4
4
  lmnr/sdk/evaluations.py,sha256=EaRcwbdXxj4w2yzak1xFv-YhDuxRVentQcJ-CypBoH0,6307
@@ -45,8 +45,8 @@ lmnr/traceloop_sdk/utils/in_memory_span_exporter.py,sha256=H_4TRaThMO1H6vUQ0OpQv
45
45
  lmnr/traceloop_sdk/utils/json_encoder.py,sha256=dK6b_axr70IYL7Vv-bu4wntvDDuyntoqsHaddqX7P58,463
46
46
  lmnr/traceloop_sdk/utils/package_check.py,sha256=TZSngzJOpFhfUZLXIs38cpMxQiZSmp0D-sCrIyhz7BA,251
47
47
  lmnr/traceloop_sdk/version.py,sha256=OlatFEFA4ttqSSIiV8jdE-sq3KG5zu2hnC4B4mzWF3s,23
48
- lmnr-0.4.9.dist-info/LICENSE,sha256=67b_wJHVV1CBaWkrKFWU1wyqTPSdzH77Ls-59631COg,10411
49
- lmnr-0.4.9.dist-info/METADATA,sha256=jFA2U8-94qC2U_bK3kSaDG-ATSnlIRbgpiqTtUN6RsY,11023
50
- lmnr-0.4.9.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
51
- lmnr-0.4.9.dist-info/entry_points.txt,sha256=Qg7ZRax4k-rcQsZ26XRYQ8YFSBiyY2PNxYfq4a6PYXI,41
52
- lmnr-0.4.9.dist-info/RECORD,,
48
+ lmnr-0.4.10.dist-info/LICENSE,sha256=67b_wJHVV1CBaWkrKFWU1wyqTPSdzH77Ls-59631COg,10411
49
+ lmnr-0.4.10.dist-info/METADATA,sha256=VPXsfYwAy1uTv_qucCqgAmyGyZMngr0HuysSSdpX8Jw,10999
50
+ lmnr-0.4.10.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
51
+ lmnr-0.4.10.dist-info/entry_points.txt,sha256=Qg7ZRax4k-rcQsZ26XRYQ8YFSBiyY2PNxYfq4a6PYXI,41
52
+ lmnr-0.4.10.dist-info/RECORD,,
File without changes
File without changes