prompty 0.1.7__tar.gz → 0.1.8__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. {prompty-0.1.7 → prompty-0.1.8}/PKG-INFO +1 -1
  2. {prompty-0.1.7 → prompty-0.1.8}/prompty/tracer.py +67 -33
  3. {prompty-0.1.7 → prompty-0.1.8}/pyproject.toml +1 -1
  4. {prompty-0.1.7 → prompty-0.1.8}/LICENSE +0 -0
  5. {prompty-0.1.7 → prompty-0.1.8}/README.md +0 -0
  6. {prompty-0.1.7 → prompty-0.1.8}/prompty/__init__.py +0 -0
  7. {prompty-0.1.7 → prompty-0.1.8}/prompty/cli.py +0 -0
  8. {prompty-0.1.7 → prompty-0.1.8}/prompty/core.py +0 -0
  9. {prompty-0.1.7 → prompty-0.1.8}/prompty/executors.py +0 -0
  10. {prompty-0.1.7 → prompty-0.1.8}/prompty/parsers.py +0 -0
  11. {prompty-0.1.7 → prompty-0.1.8}/prompty/processors.py +0 -0
  12. {prompty-0.1.7 → prompty-0.1.8}/prompty/renderers.py +0 -0
  13. {prompty-0.1.7 → prompty-0.1.8}/tests/__init__.py +0 -0
  14. {prompty-0.1.7 → prompty-0.1.8}/tests/generated/1contoso.md +0 -0
  15. {prompty-0.1.7 → prompty-0.1.8}/tests/generated/2contoso.md +0 -0
  16. {prompty-0.1.7 → prompty-0.1.8}/tests/generated/3contoso.md +0 -0
  17. {prompty-0.1.7 → prompty-0.1.8}/tests/generated/4contoso.md +0 -0
  18. {prompty-0.1.7 → prompty-0.1.8}/tests/generated/basic.prompty.md +0 -0
  19. {prompty-0.1.7 → prompty-0.1.8}/tests/generated/camping.jpg +0 -0
  20. {prompty-0.1.7 → prompty-0.1.8}/tests/generated/context.prompty.md +0 -0
  21. {prompty-0.1.7 → prompty-0.1.8}/tests/generated/contoso_multi.md +0 -0
  22. {prompty-0.1.7 → prompty-0.1.8}/tests/generated/faithfulness.prompty.md +0 -0
  23. {prompty-0.1.7 → prompty-0.1.8}/tests/generated/groundedness.prompty.md +0 -0
  24. {prompty-0.1.7 → prompty-0.1.8}/tests/hello_world-goodbye_world-hello_again.embedding.json +0 -0
  25. {prompty-0.1.7 → prompty-0.1.8}/tests/hello_world.embedding.json +0 -0
  26. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/__init__.py +0 -0
  27. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/basic.prompty +0 -0
  28. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/basic.prompty.execution.json +0 -0
  29. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/basic_json_output.prompty +0 -0
  30. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/camping.jpg +0 -0
  31. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/chat.prompty +0 -0
  32. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/context.json +0 -0
  33. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/context.prompty +0 -0
  34. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/context.prompty.execution.json +0 -0
  35. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/embedding.prompty +0 -0
  36. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/embedding.prompty.execution.json +0 -0
  37. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/evaluation.prompty +0 -0
  38. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/faithfulness.prompty +0 -0
  39. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/faithfulness.prompty.execution.json +0 -0
  40. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/fake.prompty +0 -0
  41. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/funcfile.json +0 -0
  42. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/funcfile.prompty +0 -0
  43. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/functions.prompty +0 -0
  44. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/functions.prompty.execution.json +0 -0
  45. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/groundedness.prompty +0 -0
  46. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/groundedness.prompty.execution.json +0 -0
  47. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/prompty.json +0 -0
  48. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/streaming.prompty +0 -0
  49. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/streaming.prompty.execution.json +0 -0
  50. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/sub/__init__.py +0 -0
  51. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/sub/basic.prompty +0 -0
  52. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/sub/sub/__init__.py +0 -0
  53. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/sub/sub/basic.prompty +0 -0
  54. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/sub/sub/prompty.json +0 -0
  55. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/sub/sub/test.py +0 -0
  56. {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/test.py +0 -0
  57. {prompty-0.1.7 → prompty-0.1.8}/tests/prompty.json +0 -0
  58. {prompty-0.1.7 → prompty-0.1.8}/tests/test_common.py +0 -0
  59. {prompty-0.1.7 → prompty-0.1.8}/tests/test_execute.py +0 -0
  60. {prompty-0.1.7 → prompty-0.1.8}/tests/test_factory_invoker.py +0 -0
  61. {prompty-0.1.7 → prompty-0.1.8}/tests/test_path_exec.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prompty
3
- Version: 0.1.7
3
+ Version: 0.1.8
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
@@ -89,58 +89,92 @@ class Trace:
89
89
  return str(obj)
90
90
 
91
91
 
92
- def trace(func: Callable = None, *, description: str = None) -> Callable:
93
- if func is None:
94
- return partial(trace, description=description)
92
+ def _name(func: Callable, args):
93
+ if hasattr(func, "__qualname__"):
94
+ signature = f"{func.__module__}.{func.__qualname__}"
95
+ else:
96
+ signature = f"{func.__module__}.{func.__name__}"
97
+
98
+ # core invoker gets special treatment
99
+ core_invoker = signature == "prompty.core.Invoker.__call__"
100
+ if core_invoker:
101
+ name = type(args[0]).__name__
102
+ signature = f"{args[0].__module__}.{args[0].__class__.__name__}.invoke"
103
+ else:
104
+ name = func.__name__
105
+
106
+ return name, signature
107
+
108
+
109
+ def _inputs(func: Callable, args, kwargs) -> dict:
110
+ ba = inspect.signature(func).bind(*args, **kwargs)
111
+ ba.apply_defaults()
112
+
113
+ inputs = {k: Trace.to_dict(v) for k, v in ba.arguments.items() if k != "self"}
114
+
115
+ return inputs
95
116
 
117
+ def _results(result: Any) -> dict:
118
+ return {
119
+ "result": Trace.to_dict(result) if result is not None else "None",
120
+ }
121
+
122
+ def _trace_sync(func: Callable = None, *, description: str = None) -> Callable:
96
123
  description = description or ""
97
124
 
98
125
  @wraps(func)
99
126
  def wrapper(*args, **kwargs):
100
- if hasattr(func, "__qualname__"):
101
- signature = f"{func.__module__}.{func.__qualname__}"
102
- else:
103
- signature = f"{func.__module__}.{func.__name__}"
127
+ name, signature = _name(func, args)
128
+ Trace.start(name)
129
+ Trace.add("signature", signature)
130
+ if description and description != "":
131
+ Trace.add("description", description)
104
132
 
105
- # core invoker gets special treatment
106
- core_invoker = signature == "prompty.core.Invoker.__call__"
107
- if core_invoker:
108
- name = type(args[0]).__name__
109
- else:
110
- name = func.__name__
133
+ inputs = _inputs(func, args, kwargs)
134
+ Trace.add("inputs", inputs)
111
135
 
112
- Trace.start(name)
136
+ result = func(*args, **kwargs)
137
+ Trace.add("result", _results(result))
113
138
 
114
- if core_invoker:
115
- Trace.add(
116
- "signature",
117
- f"{args[0].__module__}.{args[0].__class__.__name__}.invoke",
118
- )
119
- else:
120
- Trace.add("signature", signature)
139
+ Trace.end()
121
140
 
122
- if len(description) > 0:
123
- Trace.add("description", description)
141
+ return result
142
+
143
+ return wrapper
124
144
 
125
- ba = inspect.signature(func).bind(*args, **kwargs)
126
- ba.apply_defaults()
145
+ def _trace_async(func: Callable = None, *, description: str = None) -> Callable:
146
+ description = description or ""
127
147
 
128
- inputs = {k: Trace.to_dict(v) for k, v in ba.arguments.items() if k != "self"}
148
+ @wraps(func)
149
+ async def wrapper(*args, **kwargs):
150
+ name, signature = _name(func, args)
151
+ Trace.start(name)
152
+ Trace.add("signature", signature)
153
+ if description and description != "":
154
+ Trace.add("description", description)
129
155
 
130
- Trace.add("input", Trace.to_dict(inputs))
131
- result = func(*args, **kwargs)
156
+ inputs = _inputs(func, args, kwargs)
157
+ Trace.add("inputs", inputs)
132
158
 
133
- Trace.add(
134
- "result",
135
- Trace.to_dict(result) if result is not None else "None",
136
- )
159
+ result = await func(*args, **kwargs)
160
+ Trace.add("result", _results(result))
137
161
 
138
162
  Trace.end()
139
163
 
140
164
  return result
141
-
165
+
142
166
  return wrapper
143
167
 
168
+ def trace(func: Callable = None, *, description: str = None) -> Callable:
169
+ if func is None:
170
+ return partial(trace, description=description)
171
+
172
+ wrapped_method = (
173
+ _trace_async if inspect.iscoroutinefunction(func) else _trace_sync
174
+ )
175
+
176
+ return wrapped_method(func, description=description)
177
+
144
178
 
145
179
  class PromptyTracer(Tracer):
146
180
  _stack: List[Dict[str, Any]] = []
@@ -16,7 +16,7 @@ dependencies = [
16
16
  ]
17
17
  requires-python = ">=3.9"
18
18
  readme = "README.md"
19
- version = "0.1.7"
19
+ version = "0.1.8"
20
20
 
21
21
  [project.license]
22
22
  text = "MIT"
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
File without changes
File without changes
File without changes
File without changes