Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions examples/callback/repair_prompt.pdl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
- text: |
Given the following code:
```python
${code_line}
```
and the following error:
${error_msg}
Please repair the code!
contribute: [context]
lastOf:
- |
Given the following code:
```python
${code_line}
```
and the following error:
${error_msg}
Please repair the code!

- def: raw_output
model: replicate/ibm-granite/granite-3.0-8b-instruct
Expand Down
32 changes: 9 additions & 23 deletions examples/cldk/cldk-assistant.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@ text:
text:
- model: replicate/ibm-granite/granite-3.0-8b-instruct
def: PDL
input:
- |
input: |
Question: What are all the classes?
Answer:
```
text:
- lang: python
code:
- |
code:|
classes = PDL_SESSION.cldk_state.get_classes().keys()
result = ", ".join(classes)
```
Expand All @@ -56,8 +54,7 @@ text:
```
text:
- lang: python
code:
- |
code: |
constructors = PDL_SESSION.cldk_state.get_constructors("org.ibm.App")
result = ", ".join(constructors)
```
Expand All @@ -67,8 +64,7 @@ text:
```
text:
- lang: python
code:
- |
code: |
fields = PDL_SESSION.cldk_state.get_fields("org.ibm.App")
names = sum([f.variables for f in fields], [])
result = ", ".join(names)
Expand All @@ -79,8 +75,7 @@ text:
```
text:
- lang: python
code:
- |
code: |
methods = PDL_SESSION.cldk_state.get_methods_in_class("org.ibm.App")
result = ", ".join(methods)
```
Expand All @@ -90,8 +85,7 @@ text:
```
text:
- lang: python
code:
- |
code: |
graph = PDL_SESSION.cldk_state.get_class_call_graph("org.ibm.App", method_name=None)
result = graph
```
Expand All @@ -101,8 +95,7 @@ text:
```
text:
- lang: python
code:
- |
code: |
method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)")
result = method.code
```
Expand All @@ -112,8 +105,7 @@ text:
```
text:
- lang: python
code:
- |
code: |
method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)")
result = method
- "\n\nGenerate a summary of method Foo\n\n"
Expand All @@ -125,8 +117,7 @@ text:
```
text:
- lang: python
code:
- |
code: |
method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)")
result = method
- "\n\nGenerate a different comment for method Foo(string)\n\n"
Expand All @@ -151,8 +142,3 @@ text:
result = exec_str(pdl)

until: ${ query == 'quit' }





21 changes: 10 additions & 11 deletions examples/code/code.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ defs:
text:
- "\n${ CODE.source_code }\n"
- model: replicate/ibm-granite/granite-3.0-8b-instruct
input:
- |
Here is some info about the location of the function in the repo.
repo:
${ CODE.repo_info.repo }
path: ${ CODE.repo_info.path }
Function_name: ${ CODE.repo_info.function_name }
input: |
Here is some info about the location of the function in the repo.
repo:
${ CODE.repo_info.repo }
path: ${ CODE.repo_info.path }
Function_name: ${ CODE.repo_info.function_name }


Explain the following code:
```
${ CODE.source_code }```
Explain the following code:
```
${ CODE.source_code }```
parameters:
temperature: 0
7 changes: 3 additions & 4 deletions examples/demo/1-gen-data.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ text:
- for:
question: ${ data.questions }
answer: ${ data.answers }
repeat:
- |
${ question }
${ answer }
repeat: |
${ question }
${ answer }
- >
Question: Create a JSON object with fields 'name' and 'age'
and set them appropriately. Write the age in letters.
Expand Down
60 changes: 31 additions & 29 deletions examples/demo/2-teacher.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ defs:
icl_answer: str
spec: [{icl_question: str, icl_answer: str, question: str}]
return:
- defs:
defs:
prompt_data:
call: question_template_freeform
spec: { introduction: str, principles: str, examples: str, generation: str, max_new_tokens: int }
Expand All @@ -73,7 +73,7 @@ defs:
parser:
regex: '### Question [0-9]+:\s*([^#\n]+)'
mode: findall
- for:
for:
question: ${teacher_output}
repeat:
data:
Expand All @@ -89,7 +89,7 @@ defs:
seed_examples: [{question: str, answer: str}]
spec: [{icl_question: str, icl_answer: str, question: str}]
return:
- defs:
defs:
list_of_lists:
for:
example: ${seed_examples}
Expand All @@ -102,7 +102,7 @@ defs:
icl_answer: ${example.answer}
join:
as: array
- lang: python
lang: python
code: | # flatten list_of_lists into simple list
result = [q for qs in ${list_of_lists} for q in qs]

Expand Down Expand Up @@ -137,7 +137,7 @@ defs:
question: str
spec: float
return:
- defs:
defs:
prompt_data:
call: filter_questions_template
spec: {introduction: str, principles: str, generation: str, max_new_tokens: int}
Expand All @@ -164,25 +164,26 @@ defs:
# regex: "Rating.*\\[\\[(?P<rating>\\d+\\.?\\d*)\\]\\]"
regex: 'Rating.*\[\[(?P<rating>\d+\.?\d*)\]\]'
mode: search
- ${ teacher_output.rating | float }
data: ${ teacher_output.rating | float }

filter_questions:
function:
task_description: str
questions: [{icl_question: str, icl_answer: str, question: str}]
spec: [{icl_question: str, icl_answer: str, question: str}]
return:
- defs:
defs:
list_of_pairs:
for:
question: ${questions}
repeat:
- def: filter_output
call: filter_questions_inner
args:
task_description: ${task_description}
question: ${question.question}
- data:
defs:
filter_output:
call: filter_questions_inner
args:
task_description: ${task_description}
question: ${question.question}
data:
question: ${question}
keep: ${filter_output}
join:
Expand All @@ -191,7 +192,7 @@ defs:
lang: python
code: | # keep only if "keep" column is non-zero
result = [p["question"] for p in ${ list_of_pairs } if p["keep"]]
- ${filtered}
data: ${filtered}


answer_template:
Expand Down Expand Up @@ -230,7 +231,7 @@ defs:
question: {icl_question: str, icl_answer: str, question: str}
spec: {question: str, answer: str}
return:
- defs:
defs:
prompt_data:
call: answer_template
spec: {introduction: str, principles: str, examples: str, generation: str, max_new_tokens: int, additional_stop_tokens: [str]}
Expand Down Expand Up @@ -262,7 +263,7 @@ defs:
result = result[result.find("[Response]") + len("[Response]"):]
if "[Question]" in result:
result = result[:result.find("[Question]")]
- data:
data:
question: ${question.question}
answer: ${parsed_answer}

Expand All @@ -271,7 +272,7 @@ defs:
questions: [{icl_question: str, icl_answer: str, question: str}]
spec: [{question: str, answer: str}]
return:
- defs:
defs:
all_results:
spec: [{question: str, answer: str}]
for:
Expand All @@ -282,7 +283,7 @@ defs:
question: ${question}
join:
as: array
- lang: python
lang: python
spec: [{question: str, answer: str}]
code: | # keep only if answer non-empty
result = [r for r in ${all_results} if len(r["answer"]) > 0]
Expand Down Expand Up @@ -319,7 +320,7 @@ defs:
answer: str
spec: float
return:
- defs:
defs:
prompt_data:
call: filter_qa_template
spec: {introduction: str, principles: str, generation: str, max_new_tokens: int}
Expand All @@ -345,25 +346,26 @@ defs:
spec: { "rating": str }
regex: 'Rating.*\[\[(?P<rating>\d+\.?\d*)\]\]'
mode: search
- ${ (teacher_output.rating if teacher_output.rating is not none else 0.0) | float}
data: ${ (teacher_output.rating if teacher_output.rating is not none else 0.0) | float}

filter_question_answer_pair:
function:
qa_pairs: [{question: str, answer: str}]
spec: [{question: str, answer: str}]
return:
- defs:
defs:
ratings:
for:
qa_pair: ${qa_pairs}
repeat:
- def: filter_output
call: filter_question_answer_pair_inner
spec: float
args:
question: ${qa_pair.question}
answer: ${qa_pair.answer}
- data:
defs:
filter_output:
call: filter_question_answer_pair_inner
spec: float
args:
question: ${qa_pair.question}
answer: ${qa_pair.answer}
data:
qa_pair: ${qa_pair}
rating: ${filter_output}
join:
Expand All @@ -373,7 +375,7 @@ defs:
spec: [{question: str, answer: str}]
code: | # keep only if rating is at least two
result = [p["qa_pair"] for p in ${ratings} if p["rating"] >= 2]
- ${filtered}
data: ${filtered}


text:
Expand Down
2 changes: 1 addition & 1 deletion examples/hello/hello-data.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ text:
- def: stutter
function:
return:
- ${ something }
${ something }
- "Hello World!\n"
- call: stutter
- "\n"
Expand Down
3 changes: 1 addition & 2 deletions examples/hello/hello-parser-json.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ text:
- for:
question: ${ data.questions }
answer: ${ data.answers }
repeat:
- |
repeat: |
${ question }
${ answer }
- >
Expand Down
3 changes: 1 addition & 2 deletions examples/rag/rag.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ text:
- for:
prompt: ${ RETRIEVED.prompt }
code: ${ RETRIEVED.code }
repeat:
- |
repeat: |

Q: ${ prompt }
A: ```${ code }```
Expand Down
14 changes: 7 additions & 7 deletions examples/react/demo.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ text:
result = str(e)
- "\n"
else:
- if: ${ action.name == "Calc" }
then:
text:
- "\nObs: "
- lang: python
code: result = ${ action.arguments.expr }
- "\n"
if: ${ action.name == "Calc" }
then:
text:
- "\nObs: "
- lang: python
code: result = ${ action.arguments.expr }
- "\n"
until: ${ action.name != "Search" }

Loading