lmnr 0.3.0__py3-none-any.whl → 0.3.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 +1 -0
- {lmnr-0.3.0.dist-info → lmnr-0.3.1.dist-info}/METADATA +33 -13
- {lmnr-0.3.0.dist-info → lmnr-0.3.1.dist-info}/RECORD +6 -6
- {lmnr-0.3.0.dist-info → lmnr-0.3.1.dist-info}/LICENSE +0 -0
- {lmnr-0.3.0.dist-info → lmnr-0.3.1.dist-info}/WHEEL +0 -0
- {lmnr-0.3.0.dist-info → lmnr-0.3.1.dist-info}/entry_points.txt +0 -0
lmnr/__init__.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
from .sdk.client import Laminar
|
2
2
|
from .sdk.decorators import observe, lmnr_context, wrap_llm_call
|
3
3
|
from .sdk.interface import trace, TraceContext, SpanContext
|
4
|
+
from .sdk.tracing_types import EvaluateEvent
|
4
5
|
from .sdk.types import ChatMessage, PipelineRunError, PipelineRunResponse, NodeInput
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: lmnr
|
3
|
-
Version: 0.3.
|
3
|
+
Version: 0.3.1
|
4
4
|
Summary: Python SDK for Laminar AI
|
5
5
|
License: Apache-2.0
|
6
6
|
Author: lmnr.ai
|
@@ -30,6 +30,24 @@ source .myenv/bin/activate # or use your favorite env management tool
|
|
30
30
|
pip install lmnr
|
31
31
|
```
|
32
32
|
|
33
|
+
Create .env file at the root and add `LMNR_PROJECT_API_KEY` value to it.
|
34
|
+
|
35
|
+
Read more [here](https://docs.lmnr.ai/api-reference/introduction#authentication) on how to get `LMNR_PROJECT_API_KEY`.
|
36
|
+
|
37
|
+
## Sending events
|
38
|
+
|
39
|
+
You can send events in two ways:
|
40
|
+
- `.event(name, value)` – for a pre-defined event with one of possible values.
|
41
|
+
- `.evaluate_event(name, data)` – for an event that our agent checks for and assigns a value from possible values.
|
42
|
+
|
43
|
+
There are 3 types of events:
|
44
|
+
- SCORE - this is an integer score where you specify inclusive minimum and maximum.
|
45
|
+
- CLASS - this is a classifier with one of the possible values.
|
46
|
+
- TAG - this event has no value and can be assigned to a span.
|
47
|
+
|
48
|
+
Important notes:
|
49
|
+
- If event name does not match anything pre-defined in the UI, the event won't be saved.
|
50
|
+
- If event value (when sent with `.event()`) is not in the domain, the event won't be saved.
|
33
51
|
|
34
52
|
## Decorator instrumentation example
|
35
53
|
|
@@ -64,10 +82,11 @@ def poem_writer(topic="turbulence"):
|
|
64
82
|
poem = response.choices[0].message.content
|
65
83
|
|
66
84
|
if topic in poem:
|
67
|
-
|
85
|
+
# send an event with a pre-defined name
|
86
|
+
lmnr_context.event("topic_alignment", "good")
|
68
87
|
|
69
88
|
# to trigger an automatic check for a possible event do:
|
70
|
-
lmnr_context.
|
89
|
+
lmnr_context.evaluate_event("excessive_wordiness", poem)
|
71
90
|
|
72
91
|
return poem
|
73
92
|
|
@@ -93,7 +112,7 @@ Both `TraceContext` and `SpanContext` expose the following interfaces:
|
|
93
112
|
- `end(**kwargs)` – update the current span, and terminate it
|
94
113
|
|
95
114
|
In addition, `SpanContext` allows you to:
|
96
|
-
- `event(name: str, value: str | int
|
115
|
+
- `event(name: str, value: str | int)` - emit a custom event at any point
|
97
116
|
- `evaluate_event(name: str, data: str)` - register a possible event for automatic checking by Laminar.
|
98
117
|
|
99
118
|
Example:
|
@@ -102,11 +121,11 @@ Example:
|
|
102
121
|
import os
|
103
122
|
from openai import OpenAI
|
104
123
|
|
105
|
-
from lmnr import trace, TraceContext, SpanContext
|
124
|
+
from lmnr import trace, TraceContext, SpanContext, EvaluateEvent
|
106
125
|
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
|
107
126
|
|
108
127
|
def poem_writer(t: TraceContext, topic = "turbulence"):
|
109
|
-
span: SpanContext = t.span(name="poem_writer", input=
|
128
|
+
span: SpanContext = t.span(name="poem_writer", input=topic)
|
110
129
|
|
111
130
|
prompt = f"write a poem about {topic}"
|
112
131
|
messages = [
|
@@ -125,15 +144,19 @@ def poem_writer(t: TraceContext, topic = "turbulence"):
|
|
125
144
|
)
|
126
145
|
poem = response.choices[0].message.content
|
127
146
|
if topic in poem:
|
128
|
-
llm_span.event("topic_alignment") # send an event with a pre-defined name
|
147
|
+
llm_span.event("topic_alignment", "good") # send an event with a pre-defined name
|
129
148
|
|
130
|
-
# note that you can register possible events here as well,
|
131
|
-
llm_span.
|
149
|
+
# note that you can register possible events here as well,
|
150
|
+
# not only `llm_span.evaluate_event()`
|
151
|
+
llm_span.end(
|
152
|
+
output=poem,
|
153
|
+
evaluate_events=[EvaluateEvent(name="excessive_wordines", data=poem)]
|
154
|
+
)
|
132
155
|
span.end(output=poem)
|
133
156
|
return poem
|
134
157
|
|
135
158
|
|
136
|
-
t: TraceContext = trace(user_id="
|
159
|
+
t: TraceContext = trace(user_id="user123", session_id="session123", release="release")
|
137
160
|
main(t, topic="laminar flow")
|
138
161
|
t.end(success=True)
|
139
162
|
```
|
@@ -179,7 +202,4 @@ PipelineRunResponse(
|
|
179
202
|
)
|
180
203
|
```
|
181
204
|
|
182
|
-
## PROJECT_API_KEY
|
183
|
-
|
184
|
-
Read more [here](https://docs.lmnr.ai/api-reference/introduction#authentication) on how to get `PROJECT_API_KEY`.
|
185
205
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
lmnr/__init__.py,sha256=
|
1
|
+
lmnr/__init__.py,sha256=zNJSRkUBTC0iKNvW7vitPS_W7uLnMc4ymAXJrnSM1gk,287
|
2
2
|
lmnr/sdk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
3
|
lmnr/sdk/client.py,sha256=e6cIvJq38a6XAU8FGWYtNXVAPlEoZEyKS7hC3M_6EkU,5749
|
4
4
|
lmnr/sdk/collector.py,sha256=6LRmPhOcmGplUDWm_sJh0dVrLTHknd_kmq7POGuAvoQ,5338
|
@@ -14,8 +14,8 @@ lmnr/sdk/providers/utils.py,sha256=ROt82VrvezExYOxionAynD3dp6oX5JoPW6F1ayTm7q8,9
|
|
14
14
|
lmnr/sdk/tracing_types.py,sha256=RvVb8yCLjCu9DT59OX_tvUxaOTCtE6fcsDH4nMddzHA,6399
|
15
15
|
lmnr/sdk/types.py,sha256=hVxOsa3oCQQ-8aS_WkOtErg4nHJRkBVySfYlTgDlDyk,2084
|
16
16
|
lmnr/sdk/utils.py,sha256=1yhXtdGmVXfnc8SOQiTH_zAZGbZrzO8oaFd7q5nE7eY,3349
|
17
|
-
lmnr-0.3.
|
18
|
-
lmnr-0.3.
|
19
|
-
lmnr-0.3.
|
20
|
-
lmnr-0.3.
|
21
|
-
lmnr-0.3.
|
17
|
+
lmnr-0.3.1.dist-info/LICENSE,sha256=67b_wJHVV1CBaWkrKFWU1wyqTPSdzH77Ls-59631COg,10411
|
18
|
+
lmnr-0.3.1.dist-info/METADATA,sha256=tPHT-aNx5QDEHS6kJs7Z1gk_21_Z6y7hPfpA1klh4Cc,7505
|
19
|
+
lmnr-0.3.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
20
|
+
lmnr-0.3.1.dist-info/entry_points.txt,sha256=Qg7ZRax4k-rcQsZ26XRYQ8YFSBiyY2PNxYfq4a6PYXI,41
|
21
|
+
lmnr-0.3.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|