New Features
The main new features are:
contributeto a file or standard input and error@pdlPython decorator
contribute to files
The user can declare a file aggregator that can be used in the contribute to accumulate the results of the blocks.
For example, in the following program, an aggregator named log associated to the file /tmp/log.txt is declared.
This aggregator is used to store the output of the model in the file /tmp/log.txt.
defs:
log:
aggregator:
file: /tmp/log.txt
text:
- Hello
- model: ollama_chat/granite3.3:2b
contribute: [ result, context, log ]
By default, the aggregator stdin and stderr are available to contribute to the standard input and standard error.
It is useful, for example to outpout debug information. In the following program, the raw output of the model is emitted
on the standard error:
text:
- Hello
- model: ollama_chat/granite3.3:2b
modelResponse: raw_response
contribute:
- result
- context
- stderr:
value: ${raw_response}
@pdl Python decorator
In order to make it easy to define functions as PDL programs, we provide a @pdl decorator.
from pdl.pdl import pdl
@pdl
def chain_of_thought(scope):
"""
lastOf:
- "Question: ${ question }\n"
- "Answer: Let's think step by step. "
- model: ollama_chat/granite3.3:2b
parameters:
stop:
- "<|endoftext|>"
- "Question:"
include_stop_sequence: false
"""
return
def main():
result = chain_of_thought(
scope={"model": "ollama_chat/granite3.2:2b",
"question": "How to write Hello World in OCaml?\n"}
)
print(result)
if __name__ == "__main__":
main()
In this example, the function chain_pf_thought is a string representing a PDL program. The free variables in the string are values passed in the dictionary scope given on argument.
What's Changed
- tests: update expected result by @mandel in #1158
- First class aggregators by @mandel in #706
- refactor: react pattern in prompt library by @mandel in #1162
- PDL Python decorator by @vazirim in #1166
- fix: type error location by @mandel in #1169
- refactor: interpreter by @mandel in #1170
- fix: return the value not the future when a closure is called fro jin… by @mandel in #1208
- feat: the scope of the
contentfield is local by @mandel in #1225 - feat: replay an execution by @mandel in #1211
- refactor: performance optimizations by @mandel in #1228
- feat: add
event_loopto the interpreter config by @mandel in #1235 - feat: do not reload library when importing multiple time a file by @mandel in #1243
- feat:
structuredDecodingfield on themodelblock by @mandel in #1250 - docs: update type checking and structured decoding in the tutorial by @mandel in #1254
- feat: improve error messages by @mandel in #1259
- fix: imported files can use stdlib by @mandel in #1264
- fix: improve error messages by @mandel in #1276
- fix: avoid catching
KeyboardInterruptby @mandel in #1298 - fix: bug in ipython code block by @mandel in #1314
- refactor: use TypedDict for exec program output by @mandel in #1322
- feat: do not dump location tables in the trace by @mandel in #1326
- feat: collect global statistics on LLM usage by @mandel in #1328
- feat: add
llm_usageto theexec_*config by @mandel in #1331
Full Changelog: v0.8.0...v0.9.0