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.
- {prompty-0.1.7 → prompty-0.1.8}/PKG-INFO +1 -1
- {prompty-0.1.7 → prompty-0.1.8}/prompty/tracer.py +67 -33
- {prompty-0.1.7 → prompty-0.1.8}/pyproject.toml +1 -1
- {prompty-0.1.7 → prompty-0.1.8}/LICENSE +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/README.md +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/prompty/__init__.py +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/prompty/cli.py +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/prompty/core.py +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/prompty/executors.py +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/prompty/parsers.py +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/prompty/processors.py +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/prompty/renderers.py +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/__init__.py +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/generated/1contoso.md +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/generated/2contoso.md +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/generated/3contoso.md +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/generated/4contoso.md +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/generated/basic.prompty.md +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/generated/camping.jpg +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/generated/context.prompty.md +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/generated/contoso_multi.md +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/generated/faithfulness.prompty.md +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/generated/groundedness.prompty.md +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/hello_world-goodbye_world-hello_again.embedding.json +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/hello_world.embedding.json +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/__init__.py +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/basic.prompty +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/basic.prompty.execution.json +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/basic_json_output.prompty +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/camping.jpg +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/chat.prompty +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/context.json +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/context.prompty +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/context.prompty.execution.json +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/embedding.prompty +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/embedding.prompty.execution.json +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/evaluation.prompty +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/faithfulness.prompty +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/faithfulness.prompty.execution.json +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/fake.prompty +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/funcfile.json +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/funcfile.prompty +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/functions.prompty +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/functions.prompty.execution.json +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/groundedness.prompty +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/groundedness.prompty.execution.json +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/prompty.json +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/streaming.prompty +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/streaming.prompty.execution.json +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/sub/__init__.py +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/sub/basic.prompty +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/sub/sub/__init__.py +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/sub/sub/basic.prompty +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/sub/sub/prompty.json +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/sub/sub/test.py +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompts/test.py +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/prompty.json +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/test_common.py +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/test_execute.py +0 -0
- {prompty-0.1.7 → prompty-0.1.8}/tests/test_factory_invoker.py +0 -0
- {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.
|
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
|
93
|
-
if func
|
94
|
-
|
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
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|
-
|
106
|
-
|
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
|
-
|
136
|
+
result = func(*args, **kwargs)
|
137
|
+
Trace.add("result", _results(result))
|
113
138
|
|
114
|
-
|
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
|
-
|
123
|
-
|
141
|
+
return result
|
142
|
+
|
143
|
+
return wrapper
|
124
144
|
|
125
|
-
|
126
|
-
|
145
|
+
def _trace_async(func: Callable = None, *, description: str = None) -> Callable:
|
146
|
+
description = description or ""
|
127
147
|
|
128
|
-
|
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
|
-
|
131
|
-
|
156
|
+
inputs = _inputs(func, args, kwargs)
|
157
|
+
Trace.add("inputs", inputs)
|
132
158
|
|
133
|
-
|
134
|
-
|
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]] = []
|
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
|
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
|
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
|
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
|