prompty 0.1.9__py3-none-any.whl → 0.1.10__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
prompty/core.py CHANGED
@@ -8,7 +8,7 @@ import abc
8
8
  from pathlib import Path
9
9
  from .tracer import Tracer, trace, to_dict
10
10
  from pydantic import BaseModel, Field, FilePath
11
- from typing import Iterator, List, Literal, Dict, Callable, Set
11
+ from typing import AsyncIterator, Iterator, List, Literal, Dict, Callable, Set
12
12
 
13
13
 
14
14
  class PropertySettings(BaseModel):
@@ -479,3 +479,33 @@ class PromptyStream(Iterator):
479
479
  trace("items", [to_dict(s) for s in self.items])
480
480
 
481
481
  raise StopIteration
482
+
483
+
484
+ class AsyncPromptyStream(AsyncIterator):
485
+ """AsyncPromptyStream class to iterate over LLM stream.
486
+ Necessary for Prompty to handle streaming data when tracing."""
487
+
488
+ def __init__(self, name: str, iterator: AsyncIterator):
489
+ self.name = name
490
+ self.iterator = iterator
491
+ self.items: List[any] = []
492
+ self.__name__ = "AsyncPromptyStream"
493
+
494
+ def __aiter__(self):
495
+ return self
496
+
497
+ async def __anext__(self):
498
+ try:
499
+ # enumerate but add to list
500
+ o = await self.iterator.__anext__()
501
+ self.items.append(o)
502
+ return o
503
+
504
+ except StopIteration:
505
+ # StopIteration is raised
506
+ # contents are exhausted
507
+ if len(self.items) > 0:
508
+ with Tracer.start(f"{self.name}.AsyncPromptyStream") as trace:
509
+ trace("items", [to_dict(s) for s in self.items])
510
+
511
+ raise StopIteration
prompty/tracer.py CHANGED
@@ -46,6 +46,8 @@ def to_dict(obj: Any) -> Dict[str, Any]:
46
46
  # safe PromptyStream obj serialization
47
47
  elif type(obj).__name__ == "PromptyStream":
48
48
  return "PromptyStream"
49
+ elif type(obj).__name__ == "AsyncPromptyStream":
50
+ return "AsyncPromptyStream"
49
51
  # pydantic models have their own json serialization
50
52
  elif isinstance(obj, BaseModel):
51
53
  return obj.model_dump()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prompty
3
- Version: 0.1.9
3
+ Version: 0.1.10
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,12 +1,12 @@
1
- prompty-0.1.9.dist-info/METADATA,sha256=6YLGAUn8xPP0LW4VEGKpsYesMAIrx5usRw7ToD8CvkI,4668
2
- prompty-0.1.9.dist-info/WHEEL,sha256=rSwsxJWe3vzyR5HCwjWXQruDgschpei4h_giTm0dJVE,90
3
- prompty-0.1.9.dist-info/licenses/LICENSE,sha256=KWSC4z9cfML_t0xThoQYjzTdcZQj86Y_mhXdatzU-KM,1052
1
+ prompty-0.1.10.dist-info/METADATA,sha256=nO36pVf-OKjnsEZRKWV0q7XHuKLBOI7Hw2a9_8dtrIs,4669
2
+ prompty-0.1.10.dist-info/WHEEL,sha256=rSwsxJWe3vzyR5HCwjWXQruDgschpei4h_giTm0dJVE,90
3
+ prompty-0.1.10.dist-info/licenses/LICENSE,sha256=KWSC4z9cfML_t0xThoQYjzTdcZQj86Y_mhXdatzU-KM,1052
4
4
  prompty/__init__.py,sha256=Msp8eiKdrDq0wyl6G5DFDH8r5BxM2_E60uzzL7_MJ5w,11183
5
5
  prompty/cli.py,sha256=_bx_l5v7OGhtAn4d_73b8tyfEw7OOkjCqGMQPu0YP5A,2489
6
- prompty/core.py,sha256=N6BTwLzmGovUVPBRp0Gg9YJa2Uo-5Q7SQnEBGU0czI8,14432
6
+ prompty/core.py,sha256=osKfdwc_uDhQpsRpB8TyvWELUfXPBAoS2iLEU-hPJW0,15373
7
7
  prompty/executors.py,sha256=z_SXF-i2qBbxmsBexQ4Ouiqwil6L0lU2wWfwIeSN-eE,3083
8
8
  prompty/parsers.py,sha256=4mmIn4SVNs8B0R1BufanqUJk8v4r0OEEo8yx6UOxQpA,4670
9
9
  prompty/processors.py,sha256=VaB7fGyaeIPRGuAZ9KTwktx7MIkfCtPALLQgNko1-Gk,2310
10
10
  prompty/renderers.py,sha256=RSHFQFx7AtKLUfsMLCXR0a56Mb7DL1NJNgjUqgg3IqU,776
11
- prompty/tracer.py,sha256=GRHsm6661K8eyA7FkgU2ell0lw8pl2QCZXtjLboR-PY,6244
12
- prompty-0.1.9.dist-info/RECORD,,
11
+ prompty/tracer.py,sha256=_C8bSoGNvucYnuS-DZSx6dq6iuEsVWWZxj-hUrgiTIw,6333
12
+ prompty-0.1.10.dist-info/RECORD,,