Skip to content

Commit

Permalink
The code block and input field of the api block are sequences instead…
Browse files Browse the repository at this point in the history
… of documents (#303)
  • Loading branch information
mandel authored and GitHub Enterprise committed Aug 28, 2024
1 parent 34fd90e commit 47d9285
Show file tree
Hide file tree
Showing 20 changed files with 85 additions and 96 deletions.
3 changes: 1 addition & 2 deletions examples/arith/Arith-new.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ document:
- '= '
- def: RESULT
lan: python
code:
- result = {{ EXPR }}
code: result = {{ EXPR }}
- ' >>'
until: '{{ "The answer is" in REASON_OR_CALC }}'
- "\n\n"
Expand Down
4 changes: 1 addition & 3 deletions examples/arith/Arith.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ document:
- '= '
- def: RESULT
lan: python
code:
- 'result = '
- get: EXPR
code: result = {{ EXPR }}
- ' >>'
else: ""
until: '{{ "The answer is" in REASON_OR_CALC }}'
Expand Down
11 changes: 3 additions & 8 deletions examples/cldk/cldk-assistant.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ document:
- lan: python
def: analysis
show_result: false
code:
- |
code: |
import os
from rich import print # Optional, for pretty printing.
from cldk import CLDK
Expand Down Expand Up @@ -144,19 +143,15 @@ document:
- "\n\n***Executing the above PDL code:\n\n"
- lan: python
show_result: false
code:
- |
code: |
from pdl import pdl_ast, pdl_interpreter
from pdl.pdl_ast import Program
from pdl.pdl_interpreter import process_prog
from pdl.pdl_interpreter import InterpreterState
from pdl.pdl_interpreter import empty_scope
import re
import yaml
s = """'
- get: PDL
- |
'"""
s = """'{{ PDL }}'"""
pdl = s.split("```")[1]
obj = yaml.safe_load(pdl)
state = InterpreterState()
Expand Down
4 changes: 4 additions & 0 deletions examples/cldk/inputs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/Users/lmandel/ml4code/codellm-devkit-examples/sample.daytrader8-1.2
What are all the methods of class com.ibm.websphere.samples.daytrader.impl.direct.AsyncOrder
Generate a summary for method run() of the class com.ibm.websphere.samples.daytrader.impl.direct.AsyncOrder
quit
6 changes: 2 additions & 4 deletions examples/cldk/ns.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ document:
- lan: python
def: analysis
show_result: false
code:
- |
code: |
from northstar import Northstar
from pprint import pprint

Expand Down Expand Up @@ -68,8 +67,7 @@ document:
then:
- model: meta-llama/llama-3-70b-instruct
platform: bam
input:
- |
input: |
In the following code, {{ query }}
{{ analysis }}
until: "{{ query == 'quit' }}"
8 changes: 2 additions & 6 deletions examples/demo/4-arith-detector.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,15 @@ document:
show_result: false

- lan: python
code:
- |
code: |
from pdl import pdl_ast, pdl_interpreter
from pdl.pdl_ast import Program
from pdl.pdl_interpreter import process_prog
from pdl.pdl_interpreter import InterpreterState
from pdl.pdl_interpreter import empty_scope
import re
import yaml
s = """'
- get: PDL
- |
'"""
s = """'{{ PDL }}'"""
pdl = s.split("```")[1]
obj = yaml.safe_load(pdl)
state = InterpreterState()
Expand Down
4 changes: 3 additions & 1 deletion examples/fibonacci/fib-new.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ document:
- def: CODE
model: ibm/granite-20b-code-instruct
platform: bam
input: "Write just the definition for an efficient Python function to compute the Fibonacci sequence\n\n"
input: "Write just the definition for an efficient Python function to compute the Fibonacci sequence called fib\n\n"
parameters:
include_stop_sequence: false
- "\nFind a random number between 1 and 20\n"
- def: N
lan: python
Expand Down
12 changes: 6 additions & 6 deletions examples/fibonacci/fib-small.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ document:
model: ibm/granite-20b-code-instruct
platform: bam
input: "Write just the definition for an efficient Python function to compute the Fibonacci sequence\n\n"
parameters:
include_stop_sequence: false
- def: N
lan: python
code:
Expand All @@ -15,12 +17,10 @@ document:
- get: N
- ') = '
- lan: python
code:
- get: CODE
- result = fibonacci(
- get: N
- )

code: |
{{ CODE }}
result = fibonacci({{ N }})




22 changes: 13 additions & 9 deletions examples/fibonacci/fib-small1.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@ document:
- def: CODE
model: ibm/granite-20b-code-instruct-v2
platform: bam
parameters:
include_stop_sequence: false
- "What is the name of the function above?\n"
- def: FUNCTION
model: ibm/granite-20b-code-instruct
parameters:
stop_sequences: [" "]
include_stop_sequence: false
input:
document:
- get: context
- "Answer: "
- def: N
lan: python
code:
- "import random\n"
- result = random.randint(1, 20)
code: |
import random
result = random.randint(1, 20)
show_result: false
- "\nfibonacci("
- get: N
- ') = '
- |


{{ FUNCTION }}({{ N }}) =
- lan: python
code:
- get: CODE
- result = fibonacci(N)
code: |
{{ CODE }}
result = {{FUNCTION}}({{N}})
16 changes: 8 additions & 8 deletions examples/fibonacci/fib.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ document:
model: ibm/granite-20b-code-instruct
platform: bam
input: "Write just the definition for an efficient Python function to compute the Fibonacci sequence\n\n"
parameters:
include_stop_sequence: false
- "\nFind a random number between 1 and 20\n"
- def: N
lan: python
code:
- "import random\n"
- result = random.randint(1, 20)
code: |
import random
result = random.randint(1, 20)
show_result: true
- "\nNow computing fibonacci("
- get: N
- ")\n"
- def: RESULT
lan: python
code:
- get: CODE
- result = fibonacci(
- get: N
- )
code: |
{{ CODE }}
result = fibonacci({{ N }})
show_result: false
- 'The result is: '
- get: RESULT
Expand Down
8 changes: 2 additions & 6 deletions examples/gsm8k/math-jinja.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,15 @@ document:
include_stop_sequence: false
show_result: true
- lan: python
code:
- |
code: |
from pdl import pdl_ast, pdl_interpreter
from pdl.pdl_ast import Program
from pdl.pdl_interpreter import process_prog
from pdl.pdl_interpreter import InterpreterState
from pdl.pdl_interpreter import empty_scope
import re
import yaml
s = """'
- get: PDL
- |
'"""
s = """'{{ PDL }}'"""
pdl = s.split("```")[1]
obj = yaml.safe_load(pdl)
state = InterpreterState()
Expand Down
8 changes: 2 additions & 6 deletions examples/gsm8k/math.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,15 @@ document:
include_stop_sequence: false
show_result: true
- lan: python
code:
- |
code: |
from pdl import pdl_ast, pdl_interpreter
from pdl.pdl_ast import Program
from pdl.pdl_interpreter import process_prog
from pdl.pdl_interpreter import InterpreterState
from pdl.pdl_interpreter import empty_scope
import re
import yaml
s = """'
- get: PDL
- |
'"""
s = """'{{ PDL }}'"""
pdl = s.split("```")[1]
obj = yaml.safe_load(pdl)
state = InterpreterState()
Expand Down
8 changes: 2 additions & 6 deletions examples/meta/arith.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,15 @@ document:
show_result: false

- lan: python
code:
- |
code: |
from pdl import pdl_ast, pdl_interpreter
from pdl.pdl_ast import Program
from pdl.pdl_interpreter import process_prog
from pdl.pdl_interpreter import InterpreterState
from pdl.pdl_interpreter import empty_scope
import re
import yaml
s = """'
- get: PDL
- |
'"""
s = """'{{ PDL }}'"""
pdl = s.split("```")[1]
obj = yaml.safe_load(pdl)
state = InterpreterState()
Expand Down
15 changes: 2 additions & 13 deletions pdl/pdl_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,11 +642,6 @@ def step_blocks(
trace: BlocksType
results = []
iteration_state = state
# match iteration_type:
# case IterationType.DOCUMENT:
# iteration_state = state
# case _:
# iteration_state = state.with_yield_output(False)
if not isinstance(blocks, str) and isinstance(blocks, Sequence):
background = []
trace = []
Expand All @@ -666,12 +661,6 @@ def step_blocks(
)
results.append(block_result)
result = combine_results(iteration_type, results)
# match iteration_type:
# case IterationType.DOCUMENT:
# pass
# case _:
# if state.yield_output:
# yield OutputMessage(stringify(result))
return result, background, scope, trace


Expand Down Expand Up @@ -1000,7 +989,7 @@ def step_call_api(
]:
background: Messages
input_value, _, _, input_trace = yield from step_blocks(
IterationType.DOCUMENT,
IterationType.SEQUENCE,
state.with_yield_output(False),
scope,
block.input,
Expand Down Expand Up @@ -1034,7 +1023,7 @@ def step_call_code(
]:
background: Messages
code_s, _, _, code_trace = yield from step_blocks(
IterationType.DOCUMENT,
IterationType.SEQUENCE,
state.with_yield_output(False),
scope,
block.code,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_for_data():
"sequence": [
{
"def": "I",
"document": [{"lan": "python", "code": ["result = 0"]}],
"document": [{"lan": "python", "code": "result = 0"}],
"show_result": False,
},
{
Expand Down
4 changes: 3 additions & 1 deletion tests/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"Hello, ",
{
"lan": "python",
"code": ["import random\n", "import string\n", "result = 'Tracy'"],
"code": {
"document": ["import random\n", "import string\n", "result = 'Tracy'"]
},
},
"!\n",
],
Expand Down
Loading

0 comments on commit 47d9285

Please sign in to comment.