Skip to content
Merged
Show file tree
Hide file tree
Changes from 72 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
03dc654
feat: remove tauri cli support for running python interpreter
starpit Apr 10, 2025
1379876
chore: bump rust dependencies to resolve alert
starpit Apr 10, 2025
8cb0ae8
test: tauri github actions test should apt install the deb
starpit Apr 10, 2025
cb0b34b
feat: support for --data and --data-file in rust interpreter
starpit Apr 10, 2025
8f122b6
Add optimizer module
claudiosv Apr 10, 2025
72d0e64
Remove BAM
claudiosv Apr 13, 2025
3d773a8
Initial prompt library
claudiosv Apr 10, 2025
0f31164
Clean up & bring in changes
claudiosv Apr 14, 2025
f08326c
AST dump fixes
claudiosv Apr 21, 2025
36cc142
Documentation and fixes
claudiosv Apr 14, 2025
566d52c
Finish prompt lib docs
claudiosv Apr 21, 2025
b6b9f2a
Address feedback
claudiosv Apr 23, 2025
dfab1e8
Lint
claudiosv Apr 23, 2025
c1542cb
fix: begin phasing in Metadata (common defs, etc. attrs) into rust AST
starpit Apr 10, 2025
ade9c69
chore: update granite-io dependency (#896)
mandel Apr 10, 2025
d73622c
refactor: move def attr into Metadata (rust interpreter)
starpit Apr 11, 2025
087e1d2
feat: introduce Expr typing and apply it to IfBlock.condition
starpit Apr 11, 2025
0ffa988
feat: update rust Call AST to use Expr for condition attr
starpit Apr 11, 2025
0962c0d
chore: bump to rust 2024 edition
starpit Apr 11, 2025
a4f935f
feat: continue to flesh out block metadata structure in rust
starpit Apr 11, 2025
a3a9849
refactor: add metadata attr to remaining rust block asts
starpit Apr 11, 2025
a0232f9
feat: update rust Repeat AST to use Expr for `for` attr (#904)
mandel Apr 11, 2025
71bd1da
refactor: introduce Advanced enum to rust AST
starpit Apr 11, 2025
23eff68
refactor: refactor rust ast to place metadata in common struct
starpit Apr 13, 2025
98e5944
fix: improve deserialization of python-generated model block traces
starpit Apr 13, 2025
2df4341
fix: in rust ast, allow ModelBlock model to be an expr
starpit Apr 13, 2025
a92ce92
feat: initial pdl__id and --trace support for rust interpreter
starpit Apr 13, 2025
ba861d3
fix: update rust interpreter to create Data blocks for expr eval, and…
starpit Apr 14, 2025
0ca9930
fix: populate trace context field in rust interpreter
starpit Apr 14, 2025
9dce51a
Update stop sequences in parameters (#861)
jgchn Apr 14, 2025
3bc9291
refactor: extract platform-generic logic from run_ollama_model() handler
starpit Apr 14, 2025
6aede65
fix: rust interpreter was not handling pdl__context for re-runs of tr…
starpit Apr 15, 2025
5f69858
feat: improve support for importing stdlib in python code blocks
starpit Apr 15, 2025
99fca95
skeleton-of-thought example (#919)
vazirim Apr 15, 2025
9ad6ef2
Bump litellm and openai versions (#920)
vazirim Apr 16, 2025
725549c
fix: improve support for rust interpreter python imports from venv
starpit Apr 16, 2025
8cf57a8
chore: bump tauri and npm dependencies
starpit Apr 16, 2025
db0119b
chore: bump ui to 0.6.1 (#921)
starpit Apr 18, 2025
164a40f
fix: rust ast support for gsm8k, including jsonl parser
starpit Apr 18, 2025
e8f8ae9
chore: bump rust dependencies
starpit Apr 18, 2025
c013192
feat: improve support for tool calling in ollama-rs
starpit Apr 18, 2025
3ba5cab
Fully qualify import (#930)
esnible Apr 22, 2025
3106dce
feat: some regex parser support for rust interpreter
starpit Apr 22, 2025
16d35e6
Change to sys.path for python code block (#931)
vazirim Apr 22, 2025
881e1a1
granite-io hallucination demo example and notebook (#932)
vazirim Apr 22, 2025
6acb270
Lint
claudiosv May 4, 2025
a810769
Refactor
claudiosv May 5, 2025
a19cbef
Tests
claudiosv May 5, 2025
0272c66
Formatting
claudiosv May 5, 2025
c01605f
Lint
claudiosv May 5, 2025
6e7747f
Skip tests for now
claudiosv May 5, 2025
66e1b61
Update schema
claudiosv May 5, 2025
5bb9d70
Add contrib. prompt library (#927)
claudiosv Apr 23, 2025
4a9aed4
Fixed the bug where pdl.__version__ was not set (#882)
vite-falcon Apr 30, 2025
c3f635f
chore: update pre-commit tools (#937)
mandel May 2, 2025
311b59b
Use granite-io async interface (#936)
mandel May 2, 2025
1361fc8
Lint
claudiosv May 5, 2025
091b68d
chore: bump ui dependences
starpit May 3, 2025
3a43a4d
fix: skip failing execution tests (#938)
mandel May 6, 2025
c388836
independent implementation (#934)
vazirim May 6, 2025
8c5fbce
feat: add a `parse_dict` function to `pdl_parser` (#943)
mandel May 7, 2025
bb5367e
Address feedback 1
claudiosv May 9, 2025
ec21e7e
Address feedback 2
claudiosv May 10, 2025
6c7ae94
Lint & fix mypy module warning
claudiosv May 10, 2025
1f8a748
Skip tests again
claudiosv May 10, 2025
cf8d805
Try to resolve wikipedia package in ci
claudiosv May 10, 2025
eb7878e
Fix rebase
claudiosv May 10, 2025
c706ea7
Fix pyproject
claudiosv May 10, 2025
ff5b999
Merge remote-tracking branch 'origin/main' into optimizer-merge
claudiosv May 10, 2025
2b3a607
Move multiprocess to optional
claudiosv May 10, 2025
0913a18
Add ipython to pdl-live
claudiosv May 10, 2025
32f511c
Fix trace metadata
claudiosv May 12, 2025
5001f92
Add documentation
claudiosv May 15, 2025
ee45d5e
Add optimizer test PDL
claudiosv May 16, 2025
91408e0
Add config and expand docs
claudiosv May 16, 2025
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
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ repos:
rev: 'v1.15.0'
hooks:
- id: mypy
args: [--explicit-package-bases]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this line, mypy reports this error:

src/pdl/_version.py: error: Source file found twice under different module names: "optimizer.fever_evaluator" and "examples.optimizer.fever_evaluator"
src/pdl/_version.py: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules for more info
src/pdl/_version.py: note: Common resolutions include: a) adding `__init__.py` somewhere, b) using `--explicit-package-bases` or adjusting MYPYPATH
Found 1 error in 1 file (errors prevented further checking)

This is because examples.optimizer.fever_evaluator is imported in test_optimizer.py as from examples.optimizer.fever_evaluator import FEVEREvaluator, but also from within examples/optimizer/optimize.py as from .fever_evaluator import FEVEREvaluator

verbose: true
additional_dependencies: ['types-PyYAML']
# type check the Python code using pyright
Expand Down
47 changes: 24 additions & 23 deletions contrib/prompt_library/ReAct.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,28 @@ defs:
trajectory: ${ trajectory }
repeat:
text:
- def: type
text: ${ trajectory.keys()|first }
contribute: []
- if: ${ type == 'question'}
then: |
Question: ${ trajectory[type]|trim }
- if: ${ type == 'task'}
then: |
Task: ${ trajectory[type]|trim }
- if: ${ type == 'thought'}
then: |
Tho: ${ trajectory[type]|trim }
- if: ${ type == 'action'}
then: |
Act: ${ trajectory[type]|trim }
- if: ${ type == 'observation'}
then: |
Obs: ${ trajectory[type]|trim }
- if: ${ type not in ['question', 'task', 'thought', 'action', 'observation'] }
then: "${ type }: ${ trajectory[type]|trim }"
- defs:
type:
text: ${ trajectory.keys()|first }
- match: ${ type }
with:
- case: question
then: |
Question: ${ trajectory[type]|trim }
- case: task
then: |
Task: ${ trajectory[type]|trim }
- case: thought
then: |
Tho: ${ trajectory[type]|trim }
- case: action
then: |
Act: ${ trajectory[type]|trim }
- case: observation
then: |
Obs: ${ trajectory[type]|trim }
- if: ${ type not in ['question', 'task', 'thought', 'action', 'observation'] }
then: "${ type }: ${ trajectory[type]|trim }"
- "\n"

react:
Expand Down Expand Up @@ -101,13 +103,12 @@ defs:
then:
text:
- "\nObs: "
- if: ${ action.name in tools }
- if: ${ action.name.lower() in tools }
then:
call: ${ tools[action.name] }
call: ${ tools[action.name.lower()] }
args:
arguments: ${ action.arguments }
else: "Invalid action. Valid actions are ${ tool_names[:-1]|join(', ') }, and ${ tool_names[-1] }."
# - "\n"
else:
def: exit
contribute: []
Expand Down
43 changes: 24 additions & 19 deletions contrib/prompt_library/ReWoo.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,29 @@ defs:
text: ${ trajectory.keys()|first }
content:
text: ${ trajectory.values()|first }
- if: ${ type in ['task', 'question'] }
then: |-
Task: ${ content|trim }
- if: ${ type == 'thought'}
then: |-
- match: ${ type }
with:
- case: task
then: |-
Task: ${ content|trim }
- case: question
then: |-
Task: ${ content|trim }
- case: thought
then: |-

Plan: ${ content|trim }
- if: ${ type == 'action'}
then:
text:
- " #E${ i } = ${ content|trim }"
- defs:
i:
data: ${ i+1 }
- if: ${ type == 'observation'}
then: ""
- if: ${ type not in ['question', 'task', 'thought', 'action', 'observation'] }
then: "${ type }: ${ content|trim }\n"
Plan: ${ content|trim }
- case: action
then:
text:
- " #E${ i } = ${ content|trim }"
- defs:
i:
data: ${ i+1 }
- case: observation
then: ""
- if: ${ type not in ['question', 'task', 'thought', 'action', 'observation'] }
then: "${ type }: ${ content|trim }\n"
- "\n"

rewoo:
Expand Down Expand Up @@ -120,9 +125,9 @@ defs:
ACTION_RAW = ACTION_RAW.replace(k, v)
result = ACTION_RAW
tool_output:
if: ${ ACTION.name in tools }
if: ${ ACTION.name.lower() in tools }
then:
call: ${ tools[ACTION.name] }
call: ${ tools[ACTION.name.lower()] }
args:
arguments: ${ ACTION.arguments }
else: "Invalid action. Valid actions are ${ tools.keys() }"
Expand Down
4 changes: 4 additions & 0 deletions docs/autopdl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

# AutoPDL Tutorial

The following sections show how to use the AutoPDL optimizer to produce optimized PDL programs for specific tasks.
Empty file added examples/optimizer/__init__.py
Empty file.
63 changes: 63 additions & 0 deletions examples/optimizer/fever.pdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
description: Demo of ReAct template fever
defs:
cot:
import: ../../contrib/prompt_library/CoT
react:
import: ../../contrib/prompt_library/ReAct
rewoo:
import: ../../contrib/prompt_library/ReWoo
tools:
import: ../../contrib/prompt_library/tools

search_tools:
data:
- name: Search
description: Search Wikipedia for a summary
parameters:
type: object
properties:
topic:
type: string
description: The topic of interest
required:
- topic

task: |-
Task: On June 2017, the following claim was made: ${ claim }
Q: Was this claim true or false?
match: ${ prompt_pattern }
with:
# CoT
- case: cot
then:
text:
call: ${ cot.chain_of_thought }
args:
examples: "${ demonstrations }"
question: "${ task }"
model: "${ model }"

# ReAct
- case: react
then:
text:
call: ${ react.react }
args:
task: ${ task }
model: ${ model }
tool_schema: ${ search_tools }
tools: ${ tools.tools }
trajectories: ${ demonstrations }

# ReWOO
- case: rewoo
then:
text:
call: ${ rewoo.rewoo }
args:
task: ${ task }
model: ${ model }
tool_schema: ${ search_tools }
tools: ${ tools.tools }
trajectories: ${ demonstrations }
show_plans: false
86 changes: 86 additions & 0 deletions examples/optimizer/fever_evaluator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from typing import Any

from pdl.optimize.optimizer_evaluator import OptimizerEvaluator
from pdl.pdl_ast import ScopeType
from pdl.pdl_interpreter import empty_scope


class FEVEREvaluator(OptimizerEvaluator):
def __init__(
self,
*args,
**kwargs,
) -> None:
super().__init__(*args, **kwargs)
self.answer_key = "label"

def get_scope(self) -> ScopeType:
demo_var = self.config.demonstrations_variable_name

scope = {}

for k in self.config.variables:
if k in self.candidate:
scope[k] = self.candidate[k]

match self.candidate.get("prompt_pattern", None):
case "cot":
scope[demo_var] = [
{
"question": q["claim"],
"reasoning": q["cot"].strip(),
"answer": str(q[self.answer_key]).lower(),
}
for q in self.candidate[demo_var]
]
case "react":
scope[demo_var] = [
[
{key: value}
for key, value in zip(
q["traj_keys"],
q["traj_values"],
strict=True,
)
]
for q in self.candidate[demo_var]
]
case "rewoo":
scope[demo_var] = [
[
{key: value}
for key, value in zip(
q["rewoo_traj_keys"],
q["rewoo_traj_values"],
strict=True,
)
]
for q in self.candidate[demo_var]
]
case _:
pass

scope["claim"] = self.example["claim"]
return empty_scope | scope

def extract_answer(self, document: str) -> bool | None:
# "SUPPORTS", and otherwise with "REFUTES"
response = document.splitlines()[-1].lower()
if "```" in response:
response = response.split("```")[1]
supports = "true" in response
refutes = "false" in response

if (supports and refutes) or not (supports or refutes):
return None # ""

if supports:
return True # "true"

if refutes:
return False # "false"

return None

def answer_correct(self, document: str, answer: Any, truth: Any) -> bool:
return answer == truth or document.lower().endswith(str(truth).lower())
50 changes: 50 additions & 0 deletions examples/optimizer/gsm8k.pdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
description: Demo of template
defs:
cot:
import: ../../contrib/prompt_library/CoT
react:
import: ../../contrib/prompt_library/ReAct
rewoo:
import: ../../contrib/prompt_library/ReWoo
tools:
import: ../../contrib/prompt_library/tools
match: ${ prompt_pattern }
with:
# CoT
- case: cot
then:
text:
- "Answer the questions to the best of your abilities.\n\n"
- call: ${ cot.chain_of_thought }
def: ANSWER
contribute: []
args:
examples: "${ demonstrations }"
question: "${ question|trim }"
model: "${ model }"
- "\nThe answer is ${ ANSWER.answer|trim }"

# ReAct
- case: react
then:
text:
call: ${ react.react }
args:
task: "Question: ${ question|trim }"
model: ${ model }
tool_schema: ${ tools.tool_schema }
tools: ${ tools.tools }
trajectories: ${ demonstrations }

# ReWOO
- case: rewoo
then:
text:
call: ${ rewoo.rewoo }
args:
task: ${ question|trim }
model: ${ model }
tool_schema: ${ tools.tool_schema }
tools: ${ tools.tools }
trajectories: ${ demonstrations }
show_plans: false
Loading