prompty 0.1.23__tar.gz → 0.1.24__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {prompty-0.1.23 → prompty-0.1.24}/PKG-INFO +5 -5
- {prompty-0.1.23 → prompty-0.1.24}/README.md +4 -4
- {prompty-0.1.23 → prompty-0.1.24}/prompty/tracer.py +54 -35
- {prompty-0.1.23 → prompty-0.1.24}/pyproject.toml +1 -1
- {prompty-0.1.23 → prompty-0.1.24}/LICENSE +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/prompty/__init__.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/prompty/azure/__init__.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/prompty/azure/executor.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/prompty/azure/processor.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/prompty/cli.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/prompty/core.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/prompty/openai/__init__.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/prompty/openai/executor.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/prompty/openai/processor.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/prompty/parsers.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/prompty/renderers.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/prompty/serverless/__init__.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/prompty/serverless/executor.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/prompty/serverless/processor.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/fake_azure_executor.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/fake_serverless_executor.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/generated/1contoso.md +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/generated/2contoso.md +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/generated/3contoso.md +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/generated/4contoso.md +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/generated/basic.prompty.md +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/generated/camping.jpg +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/generated/context.prompty.md +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/generated/contoso_multi.md +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/generated/faithfulness.prompty.md +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/generated/groundedness.prompty.md +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/hello_world-goodbye_world-hello_again.embedding.json +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/hello_world.embedding.json +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/__init__.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/basic.prompty +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/basic.prompty.execution.json +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/basic_json_output.prompty +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/camping.jpg +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/chat.prompty +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/context.json +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/context.prompty +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/context.prompty.execution.json +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/embedding.prompty +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/embedding.prompty.execution.json +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/evaluation.prompty +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/faithfulness.prompty +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/faithfulness.prompty.execution.json +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/fake.prompty +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/funcfile.json +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/funcfile.prompty +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/functions.prompty +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/functions.prompty.execution.json +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/groundedness.prompty +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/groundedness.prompty.execution.json +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/prompty.json +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/serverless.prompty +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/serverless.prompty.execution.json +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/serverless_stream.prompty +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/serverless_stream.prompty.execution.json +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/streaming.prompty +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/streaming.prompty.execution.json +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/sub/__init__.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/sub/basic.prompty +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/sub/sub/__init__.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/sub/sub/basic.prompty +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/sub/sub/prompty.json +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/sub/sub/test.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompts/test.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/prompty.json +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/test_common.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/test_execute.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/test_factory_invoker.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/test_path_exec.py +0 -0
- {prompty-0.1.23 → prompty-0.1.24}/tests/test_tracing.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.24
|
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
|
Requires-Dist: pyyaml>=6.0.1
|
@@ -22,7 +22,7 @@ Prompty is an asset class and format for LLM prompts designed to enhance observa
|
|
22
22
|
|
23
23
|
The file format has a supporting toolchain with a VS Code extension and runtimes in multiple programming languages to simplify and accelerate your AI application development.
|
24
24
|
|
25
|
-
The tooling comes together in three ways: the *prompty file asset*, the *VS Code extension tool*, and *runtimes* in multiple programming
|
25
|
+
The tooling comes together in three ways: the *prompty file asset*, the *VS Code extension tool*, and *runtimes* in multiple programming languages.
|
26
26
|
|
27
27
|
## The Prompty File Format
|
28
28
|
Prompty is a language agnostic prompt asset for creating prompts and engineering the responses. Learn more about the format [here](https://prompty.ai/docs/prompty-file-spec).
|
@@ -95,7 +95,7 @@ The Prompty runtime comes with a set of built-in invokers that can be used to ex
|
|
95
95
|
|
96
96
|
|
97
97
|
## Using Tracing in Prompty
|
98
|
-
Prompty supports tracing to help you understand the execution of your prompts. This functionality is
|
98
|
+
Prompty supports tracing to help you understand the execution of your prompts. This functionality is customizable and can be used to trace the execution of your prompts in a way that makes sense to you. Prompty has two default traces built in: `console_tracer` and `PromptyTracer`. The `console_tracer` writes the trace to the console, and the `PromptyTracer` writes the trace to a JSON file. You can also create your own tracer by creating your own hook.
|
99
99
|
|
100
100
|
```python
|
101
101
|
import prompty
|
@@ -117,7 +117,7 @@ print(response)
|
|
117
117
|
```
|
118
118
|
|
119
119
|
You can also bring your own tracer by your own tracing hook. The `console_tracer` is the simplest example of a tracer. It writes the trace to the console.
|
120
|
-
This is what it
|
120
|
+
This is what it looks like:
|
121
121
|
|
122
122
|
```python
|
123
123
|
@contextlib.contextmanager
|
@@ -212,4 +212,4 @@ prompty -s path/to/prompty/file -e .env
|
|
212
212
|
This will execute the prompt and print the response to the console. If there are any environment variables the CLI should take into account, you can pass those in via the `-e` flag. It also has default tracing enabled.
|
213
213
|
|
214
214
|
## Contributing
|
215
|
-
We welcome contributions to the Prompty project! This community led project is open to all contributors. The project
|
215
|
+
We welcome contributions to the Prompty project! This community led project is open to all contributors. The project can be found on [GitHub](https://github.com/Microsoft/prompty).
|
@@ -3,7 +3,7 @@ Prompty is an asset class and format for LLM prompts designed to enhance observa
|
|
3
3
|
|
4
4
|
The file format has a supporting toolchain with a VS Code extension and runtimes in multiple programming languages to simplify and accelerate your AI application development.
|
5
5
|
|
6
|
-
The tooling comes together in three ways: the *prompty file asset*, the *VS Code extension tool*, and *runtimes* in multiple programming
|
6
|
+
The tooling comes together in three ways: the *prompty file asset*, the *VS Code extension tool*, and *runtimes* in multiple programming languages.
|
7
7
|
|
8
8
|
## The Prompty File Format
|
9
9
|
Prompty is a language agnostic prompt asset for creating prompts and engineering the responses. Learn more about the format [here](https://prompty.ai/docs/prompty-file-spec).
|
@@ -76,7 +76,7 @@ The Prompty runtime comes with a set of built-in invokers that can be used to ex
|
|
76
76
|
|
77
77
|
|
78
78
|
## Using Tracing in Prompty
|
79
|
-
Prompty supports tracing to help you understand the execution of your prompts. This functionality is
|
79
|
+
Prompty supports tracing to help you understand the execution of your prompts. This functionality is customizable and can be used to trace the execution of your prompts in a way that makes sense to you. Prompty has two default traces built in: `console_tracer` and `PromptyTracer`. The `console_tracer` writes the trace to the console, and the `PromptyTracer` writes the trace to a JSON file. You can also create your own tracer by creating your own hook.
|
80
80
|
|
81
81
|
```python
|
82
82
|
import prompty
|
@@ -98,7 +98,7 @@ print(response)
|
|
98
98
|
```
|
99
99
|
|
100
100
|
You can also bring your own tracer by your own tracing hook. The `console_tracer` is the simplest example of a tracer. It writes the trace to the console.
|
101
|
-
This is what it
|
101
|
+
This is what it looks like:
|
102
102
|
|
103
103
|
```python
|
104
104
|
@contextlib.contextmanager
|
@@ -193,4 +193,4 @@ prompty -s path/to/prompty/file -e .env
|
|
193
193
|
This will execute the prompt and print the response to the console. If there are any environment variables the CLI should take into account, you can pass those in via the `-e` flag. It also has default tracing enabled.
|
194
194
|
|
195
195
|
## Contributing
|
196
|
-
We welcome contributions to the Prompty project! This community led project is open to all contributors. The project
|
196
|
+
We welcome contributions to the Prompty project! This community led project is open to all contributors. The project can be found on [GitHub](https://github.com/Microsoft/prompty).
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import os
|
2
2
|
import json
|
3
3
|
import inspect
|
4
|
+
import numbers
|
4
5
|
import traceback
|
5
6
|
import importlib
|
6
7
|
import contextlib
|
@@ -139,7 +140,11 @@ def _trace_sync(
|
|
139
140
|
{
|
140
141
|
"exception": {
|
141
142
|
"type": type(e),
|
142
|
-
"traceback":
|
143
|
+
"traceback": (
|
144
|
+
traceback.format_tb(tb=e.__traceback__)
|
145
|
+
if e.__traceback__
|
146
|
+
else None
|
147
|
+
),
|
143
148
|
"message": str(e),
|
144
149
|
"args": to_dict(e.args),
|
145
150
|
}
|
@@ -179,7 +184,11 @@ def _trace_async(
|
|
179
184
|
{
|
180
185
|
"exception": {
|
181
186
|
"type": type(e),
|
182
|
-
"traceback":
|
187
|
+
"traceback": (
|
188
|
+
traceback.format_tb(tb=e.__traceback__)
|
189
|
+
if e.__traceback__
|
190
|
+
else None
|
191
|
+
),
|
183
192
|
"message": str(e),
|
184
193
|
"args": to_dict(e.args),
|
185
194
|
}
|
@@ -250,11 +259,10 @@ class PromptyTracer:
|
|
250
259
|
# hoist usage to parent frame
|
251
260
|
if "result" in frame and isinstance(frame["result"], dict):
|
252
261
|
if "usage" in frame["result"]:
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
frame["__usage"] = frame["result"]["usage"]
|
262
|
+
frame["__usage"] = self.hoist_item(
|
263
|
+
frame["result"]["usage"],
|
264
|
+
frame["__usage"] if "__usage" in frame else {},
|
265
|
+
)
|
258
266
|
|
259
267
|
# streamed results may have usage as well
|
260
268
|
if "result" in frame and isinstance(frame["result"], list):
|
@@ -264,48 +272,59 @@ class PromptyTracer:
|
|
264
272
|
and "usage" in result
|
265
273
|
and isinstance(result["usage"], dict)
|
266
274
|
):
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
frame["__usage"][key] = value
|
272
|
-
else:
|
273
|
-
frame["__usage"][key] += value
|
275
|
+
frame["__usage"] = self.hoist_item(
|
276
|
+
result["usage"],
|
277
|
+
frame["__usage"] if "__usage" in frame else {},
|
278
|
+
)
|
274
279
|
|
275
280
|
# add any usage frames from below
|
276
281
|
if "__frames" in frame:
|
277
282
|
for child in frame["__frames"]:
|
278
283
|
if "__usage" in child:
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
frame["__usage"][key] = value
|
284
|
-
else:
|
285
|
-
frame["__usage"][key] += value
|
284
|
+
frame["__usage"] = self.hoist_item(
|
285
|
+
child["__usage"],
|
286
|
+
frame["__usage"] if "__usage" in frame else {},
|
287
|
+
)
|
286
288
|
|
287
289
|
# if stack is empty, dump the frame
|
288
290
|
if len(self.stack) == 0:
|
289
|
-
|
290
|
-
self.output
|
291
|
-
/ f"{frame['name']}.{datetime.now().strftime('%Y%m%d.%H%M%S')}.tracy"
|
292
|
-
)
|
293
|
-
|
294
|
-
v = importlib.metadata.version("prompty")
|
295
|
-
enriched_frame = {
|
296
|
-
"runtime": "python",
|
297
|
-
"version": v,
|
298
|
-
"trace": frame,
|
299
|
-
}
|
300
|
-
|
301
|
-
with open(trace_file, "w") as f:
|
302
|
-
json.dump(enriched_frame, f, indent=4)
|
291
|
+
self.write_trace(frame)
|
303
292
|
# otherwise, append the frame to the parent
|
304
293
|
else:
|
305
294
|
if "__frames" not in self.stack[-1]:
|
306
295
|
self.stack[-1]["__frames"] = []
|
307
296
|
self.stack[-1]["__frames"].append(frame)
|
308
297
|
|
298
|
+
def hoist_item(self, src: Dict[str, Any], cur: Dict[str, Any]) -> None:
|
299
|
+
for key, value in src.items():
|
300
|
+
if value is None or isinstance(value, list) or isinstance(value, dict):
|
301
|
+
continue
|
302
|
+
try:
|
303
|
+
if key not in cur:
|
304
|
+
cur[key] = value
|
305
|
+
else:
|
306
|
+
cur[key] += value
|
307
|
+
except:
|
308
|
+
continue
|
309
|
+
|
310
|
+
return cur
|
311
|
+
|
312
|
+
def write_trace(self, frame: Dict[str, Any]) -> None:
|
313
|
+
trace_file = (
|
314
|
+
self.output
|
315
|
+
/ f"{frame['name']}.{datetime.now().strftime('%Y%m%d.%H%M%S')}.tracy"
|
316
|
+
)
|
317
|
+
|
318
|
+
v = importlib.metadata.version("prompty")
|
319
|
+
enriched_frame = {
|
320
|
+
"runtime": "python",
|
321
|
+
"version": v,
|
322
|
+
"trace": frame,
|
323
|
+
}
|
324
|
+
|
325
|
+
with open(trace_file, "w") as f:
|
326
|
+
json.dump(enriched_frame, f, indent=4)
|
327
|
+
|
309
328
|
|
310
329
|
@contextlib.contextmanager
|
311
330
|
def console_tracer(name: str) -> Iterator[Callable[[str, Any], None]]:
|
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
|
{prompty-0.1.23 → prompty-0.1.24}/tests/hello_world-goodbye_world-hello_again.embedding.json
RENAMED
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
|