lmnr 0.3.0__tar.gz → 0.3.1__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lmnr
3
- Version: 0.3.0
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
- lmnr_context.event("topic_alignment") # send an event with a pre-defined name
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.check_span_event("excessive_wordiness")
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 = None)` - emit a custom event at any point
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=None)
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, not only `llm_span.check_span_event()`
131
- llm_span.end(output=poem, check_event_names=["excessive_wordiness"])
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="user", session_id="session", release="release")
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
 
@@ -10,6 +10,24 @@ source .myenv/bin/activate # or use your favorite env management tool
10
10
  pip install lmnr
11
11
  ```
12
12
 
13
+ Create .env file at the root and add `LMNR_PROJECT_API_KEY` value to it.
14
+
15
+ Read more [here](https://docs.lmnr.ai/api-reference/introduction#authentication) on how to get `LMNR_PROJECT_API_KEY`.
16
+
17
+ ## Sending events
18
+
19
+ You can send events in two ways:
20
+ - `.event(name, value)` – for a pre-defined event with one of possible values.
21
+ - `.evaluate_event(name, data)` – for an event that our agent checks for and assigns a value from possible values.
22
+
23
+ There are 3 types of events:
24
+ - SCORE - this is an integer score where you specify inclusive minimum and maximum.
25
+ - CLASS - this is a classifier with one of the possible values.
26
+ - TAG - this event has no value and can be assigned to a span.
27
+
28
+ Important notes:
29
+ - If event name does not match anything pre-defined in the UI, the event won't be saved.
30
+ - If event value (when sent with `.event()`) is not in the domain, the event won't be saved.
13
31
 
14
32
  ## Decorator instrumentation example
15
33
 
@@ -44,10 +62,11 @@ def poem_writer(topic="turbulence"):
44
62
  poem = response.choices[0].message.content
45
63
 
46
64
  if topic in poem:
47
- lmnr_context.event("topic_alignment") # send an event with a pre-defined name
65
+ # send an event with a pre-defined name
66
+ lmnr_context.event("topic_alignment", "good")
48
67
 
49
68
  # to trigger an automatic check for a possible event do:
50
- lmnr_context.check_span_event("excessive_wordiness")
69
+ lmnr_context.evaluate_event("excessive_wordiness", poem)
51
70
 
52
71
  return poem
53
72
 
@@ -73,7 +92,7 @@ Both `TraceContext` and `SpanContext` expose the following interfaces:
73
92
  - `end(**kwargs)` – update the current span, and terminate it
74
93
 
75
94
  In addition, `SpanContext` allows you to:
76
- - `event(name: str, value: str | int = None)` - emit a custom event at any point
95
+ - `event(name: str, value: str | int)` - emit a custom event at any point
77
96
  - `evaluate_event(name: str, data: str)` - register a possible event for automatic checking by Laminar.
78
97
 
79
98
  Example:
@@ -82,11 +101,11 @@ Example:
82
101
  import os
83
102
  from openai import OpenAI
84
103
 
85
- from lmnr import trace, TraceContext, SpanContext
104
+ from lmnr import trace, TraceContext, SpanContext, EvaluateEvent
86
105
  client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
87
106
 
88
107
  def poem_writer(t: TraceContext, topic = "turbulence"):
89
- span: SpanContext = t.span(name="poem_writer", input=None)
108
+ span: SpanContext = t.span(name="poem_writer", input=topic)
90
109
 
91
110
  prompt = f"write a poem about {topic}"
92
111
  messages = [
@@ -105,15 +124,19 @@ def poem_writer(t: TraceContext, topic = "turbulence"):
105
124
  )
106
125
  poem = response.choices[0].message.content
107
126
  if topic in poem:
108
- llm_span.event("topic_alignment") # send an event with a pre-defined name
127
+ llm_span.event("topic_alignment", "good") # send an event with a pre-defined name
109
128
 
110
- # note that you can register possible events here as well, not only `llm_span.check_span_event()`
111
- llm_span.end(output=poem, check_event_names=["excessive_wordiness"])
129
+ # note that you can register possible events here as well,
130
+ # not only `llm_span.evaluate_event()`
131
+ llm_span.end(
132
+ output=poem,
133
+ evaluate_events=[EvaluateEvent(name="excessive_wordines", data=poem)]
134
+ )
112
135
  span.end(output=poem)
113
136
  return poem
114
137
 
115
138
 
116
- t: TraceContext = trace(user_id="user", session_id="session", release="release")
139
+ t: TraceContext = trace(user_id="user123", session_id="session123", release="release")
117
140
  main(t, topic="laminar flow")
118
141
  t.end(success=True)
119
142
  ```
@@ -159,6 +182,3 @@ PipelineRunResponse(
159
182
  )
160
183
  ```
161
184
 
162
- ## PROJECT_API_KEY
163
-
164
- Read more [here](https://docs.lmnr.ai/api-reference/introduction#authentication) on how to get `PROJECT_API_KEY`.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "lmnr"
3
- version = "0.3.0"
3
+ version = "0.3.1"
4
4
  description = "Python SDK for Laminar AI"
5
5
  authors = [
6
6
  { name = "lmnr.ai", email = "founders@lmnr.ai" }
@@ -11,7 +11,7 @@ license = "Apache-2.0"
11
11
 
12
12
  [tool.poetry]
13
13
  name = "lmnr"
14
- version = "0.3.0"
14
+ version = "0.3.1"
15
15
  description = "Python SDK for Laminar AI"
16
16
  authors = ["lmnr.ai"]
17
17
  readme = "README.md"
@@ -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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes