Skip to content

Commit becac0e

Browse files
committed
cleanup
Signed-off-by: Mandana Vaziri <[email protected]>
1 parent fee2e37 commit becac0e

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

src/pdl/pdl_context.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
from typing import Any
21
from enum import StrEnum
2+
from typing import Any
3+
34
from .pdl_lazy import (
45
PdlDict,
56
PdlList,
6-
PdlLazy,
77
)
88

9+
910
class SerializeMode(StrEnum):
1011
LITELLM = "litellm"
1112
GRANITEIO = "graniteio"
1213

14+
1315
class PDLContext():
16+
1417
def serialize(self, mode: SerializeMode) -> list[dict[str, Any]]:
1518
return []
1619

@@ -30,14 +33,12 @@ def serialize(self, mode: SerializeMode) -> list[dict[str, Any]]:
3033
return [result]
3134

3235

33-
3436
class IndependentContext(PDLContext):
3537
context: PdlList[PDLContext]
3638

3739
def __init__(self, context: PdlList[PDLContext]):
3840
self.context = context
3941

40-
4142
def serialize(self, mode: SerializeMode) -> list[dict[str, Any]]:
4243
result = self.context.result()
4344
contexts = [m.serialize(mode) for m in result]
@@ -57,9 +58,9 @@ def serialize(self, mode: SerializeMode) -> list[dict[str, Any]]:
5758
result = self.context.result()
5859
contexts = [m.serialize(mode) for m in result]
5960
return [x for xs in contexts for x in xs]
60-
6161

62-
def deserialize(context: list[dict[str, Any]]) -> DependentContext: # Only support dependent for now
62+
63+
def deserialize(context: list[dict[str, Any]]) -> DependentContext: # Only support dependent for now
6364
ret: DependentContext = DependentContext(PdlList([]))
6465
for message in context:
6566
if isinstance(message, dict):
@@ -71,4 +72,4 @@ def deserialize(context: list[dict[str, Any]]) -> DependentContext: # Only suppo
7172
else:
7273
ret = DependentContext(PdlList([ret, message]))
7374

74-
return ret
75+
return ret

tests/test_context.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
from pdl.pdl_context import DependentContext, BaseMessage, IndependentContext, SerializeMode
1+
from pdl.pdl_context import (
2+
BaseMessage,
3+
DependentContext,
4+
IndependentContext,
5+
SerializeMode,
6+
)
27
from pdl.pdl_lazy import PdlList
38

49
a = BaseMessage({"role": "user", "content": "hello"})
@@ -17,6 +22,7 @@
1722
p = DependentContext(PdlList([d1, d2]))
1823
p1 = DependentContext(PdlList([d1, i]))
1924

25+
2026
def test_p():
2127
assert p.serialize(SerializeMode.LITELLM) == [{"role": "user", "content": "hello"},
2228
{"role": "user", "content": "bye"},
@@ -27,11 +33,11 @@ def test_p():
2733

2834
def test_p1():
2935
assert p1.serialize(SerializeMode.LITELLM) == [{"role": "user", "content": "hello"},
30-
{"role": "user", "content": "bye"},
31-
{"role": "user", "content": "hello2"},
32-
{"role": "user", "content": "bye2"}]
33-
36+
{"role": "user", "content": "bye"},
37+
{"role": "user", "content": "hello2"},
38+
{"role": "user", "content": "bye2"}]
39+
3440
assert p1.serialize(SerializeMode.GRANITEIO) == [{"role": "user", "content": "hello"},
35-
{"role": "user", "content": "bye"},
36-
{"independent": [{"role": "user", "content": "hello2"},
37-
{"role": "user", "content": "bye2"}]}]
41+
{"role": "user", "content": "bye"},
42+
{"independent": [{"role": "user", "content": "hello2"},
43+
{"role": "user", "content": "bye2"}]}]

0 commit comments

Comments
 (0)