Skip to content

Commit 8eef7be

Browse files
authored
PDL Python decorator (#1166)
* pdl generative Signed-off-by: Mandana Vaziri <[email protected]>
1 parent 9c20383 commit 8eef7be

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

examples/tutorial/sdk/lib.pdl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
defs:
2+
hello:
3+
data: Hello there!

examples/tutorial/sdk/run_pdl.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from pdl.pdl import pdl
2+
3+
4+
@pdl
5+
def my_pdl_program(scope):
6+
"""
7+
model: ${ model }
8+
input: ${ input }
9+
"""
10+
return
11+
12+
13+
@pdl
14+
def another(scope):
15+
"""
16+
defs:
17+
lib:
18+
import: lib
19+
text:
20+
- ${ lib.hello }
21+
"""
22+
23+
24+
def main():
25+
result1 = my_pdl_program(
26+
scope={"model": "ollama_chat/granite3.2:2b", "input": "Hello\n"}
27+
)
28+
result2 = another(scope={})
29+
print(result1)
30+
print(result2)
31+
32+
33+
if __name__ == "__main__":
34+
main()

src/pdl/pdl.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ def exec_file(
160160
return result
161161

162162

163+
def pdl(func):
164+
def pdl_wrapper(scope):
165+
result = exec_str(prog=func.__doc__, scope=scope)
166+
return result
167+
168+
return pdl_wrapper
169+
170+
163171
def main():
164172
parser = argparse.ArgumentParser("")
165173
parser.add_argument(

tests/test_examples_run.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ skip:
3535
- examples/optimizer/eval_levenshtein.pdl
3636
- examples/requirements/email.pdl
3737
- examples/skeleton-of-thought/tips.pdl
38+
- examples/tutorial/sdk/lib.pdl
3839
with_inputs:
3940
examples/tutorial/programs/chatbot.pdl:
4041
stdin: |

0 commit comments

Comments
 (0)