prompty 0.1.36__py3-none-any.whl → 0.1.38__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.
prompty/tracer.py CHANGED
@@ -28,6 +28,10 @@ def sanitize(key: str, value: Any) -> Any:
28
28
  class Tracer:
29
29
  _tracers: Dict[str, Callable[[str], Iterator[Callable[[str, Any], None]]]] = {}
30
30
 
31
+ SIGNATURE = "signature"
32
+ INPUTS = "inputs"
33
+ RESULT = "result"
34
+
31
35
  @classmethod
32
36
  def add(
33
37
  cls, name: str, tracer: Callable[[str], Iterator[Callable[[str, Any], None]]]
@@ -40,11 +44,17 @@ class Tracer:
40
44
 
41
45
  @classmethod
42
46
  @contextlib.contextmanager
43
- def start(cls, name: str) -> Iterator[Callable[[str, Any], None]]:
47
+ def start(cls, name: str, attributes: Dict[str, Any] = None) -> Iterator[Callable[[str, Any], None]]:
44
48
  with contextlib.ExitStack() as stack:
45
49
  traces = [
46
50
  stack.enter_context(tracer(name)) for tracer in cls._tracers.values()
47
51
  ]
52
+
53
+ if attributes:
54
+ for trace in traces:
55
+ for key, value in attributes.items():
56
+ trace(key, value)
57
+
48
58
  yield lambda key, value: [
49
59
  # normalize and sanitize any trace values
50
60
  trace(key, sanitize(key, to_dict(value)))
@@ -124,7 +134,17 @@ def _trace_sync(
124
134
  @wraps(func)
125
135
  def wrapper(*args, **kwargs):
126
136
  name, signature = _name(func, args)
137
+ altname: str = None
138
+ # special case
139
+ if "name" in okwargs:
140
+ altname = name
141
+ name = okwargs["name"]
142
+ del okwargs["name"]
143
+
127
144
  with Tracer.start(name) as trace:
145
+ if altname != None:
146
+ trace("function", altname)
147
+
128
148
  trace("signature", signature)
129
149
 
130
150
  # support arbitrary keyword
@@ -168,10 +188,20 @@ def _trace_async(
168
188
  @wraps(func)
169
189
  async def wrapper(*args, **kwargs):
170
190
  name, signature = _name(func, args)
191
+ altname: str = None
192
+ # special case
193
+ if "name" in okwargs:
194
+ altname = name
195
+ name = okwargs["name"]
196
+ del okwargs["name"]
197
+
171
198
  with Tracer.start(name) as trace:
199
+ if altname != None:
200
+ trace("function", altname)
201
+
172
202
  trace("signature", signature)
173
203
 
174
- # support arbitrary keyword
204
+ # support arbitrary keyword
175
205
  # arguments for trace decorator
176
206
  for k, v in okwargs.items():
177
207
  trace(k, to_dict(v))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prompty
3
- Version: 0.1.36
3
+ Version: 0.1.38
4
4
  Summary: Prompty is a new asset class and format for LLM prompts that aims to provide observability, understandability, and portability for developers. It includes spec, tooling, and a runtime. This Prompty runtime supports Python
5
5
  Author-Email: Seth Juarez <seth.juarez@microsoft.com>
6
6
  License: MIT
@@ -1,7 +1,7 @@
1
- prompty-0.1.36.dist-info/METADATA,sha256=hkRNP31HOI6NKNO8EW3juLAZOOc1EPhrV-XTE6CtjYA,9164
2
- prompty-0.1.36.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
3
- prompty-0.1.36.dist-info/entry_points.txt,sha256=a3i7Kvf--3DOkkv9VQpstwaNKgsnXwDGaPL18lPpKeI,60
4
- prompty-0.1.36.dist-info/licenses/LICENSE,sha256=KWSC4z9cfML_t0xThoQYjzTdcZQj86Y_mhXdatzU-KM,1052
1
+ prompty-0.1.38.dist-info/METADATA,sha256=m7yAPiF7NsDcD6RQMfdkSbBM-w9uphfEQY_4mwUaJ1w,9164
2
+ prompty-0.1.38.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
3
+ prompty-0.1.38.dist-info/entry_points.txt,sha256=a3i7Kvf--3DOkkv9VQpstwaNKgsnXwDGaPL18lPpKeI,60
4
+ prompty-0.1.38.dist-info/licenses/LICENSE,sha256=KWSC4z9cfML_t0xThoQYjzTdcZQj86Y_mhXdatzU-KM,1052
5
5
  prompty/__init__.py,sha256=HCAvInBgNcIDO54rR4-RDIF4KUmGVQ2TRam_dS7xHEk,16561
6
6
  prompty/azure/__init__.py,sha256=WI8qeNWfxqggj21bznL-mxGUS-v67bUrunX0Lf2hsI8,295
7
7
  prompty/azure/executor.py,sha256=RJXMB0W7KcVvQ7l3xJaau7YM8PqOCQwuN4IwIe0sTLg,7930
@@ -19,6 +19,6 @@ prompty/renderers.py,sha256=80HNtCp3osgaLfhKxkG4j1kiRhJ727ITzT_yL5JLjEQ,1104
19
19
  prompty/serverless/__init__.py,sha256=xoXOTRXO8C631swNKaa-ek5_R3X-87bJpTm0z_Rsg6A,282
20
20
  prompty/serverless/executor.py,sha256=PUDJsYcJLQx9JSTh-R3HdJd0ehEC6w2Ch5OEqz52uVI,8395
21
21
  prompty/serverless/processor.py,sha256=ZSL9y8JC-G4qbtWOSbQAqEcFMWEaLskyOr5VjLthelU,3660
22
- prompty/tracer.py,sha256=WUR7PsvhBLQf7WcnKQPOeLeii9l4xPKB2owjvJ50d0E,10907
22
+ prompty/tracer.py,sha256=GdCvqJLiW6PEyW2lnElSD45y4IBmgw5gtNczImbg-44,11700
23
23
  prompty/utils.py,sha256=jm7HEzOGk3zz8d5aquXK3zWIQWuDpBpJTzlz5sswtdg,2836
24
- prompty-0.1.36.dist-info/RECORD,,
24
+ prompty-0.1.38.dist-info/RECORD,,