Skip to content

Version 0.9.3

Latest

Choose a tag to compare

@mandel mandel released this 26 Feb 20:20
· 325 commits to main since this release
v0.9.3
a160a73

New Features

The main new features are:

  • Add the variables pdl_usage and pdl_scope to the PDL scope
  • Add a scope field to the code blocks
  • Add a parameters field to Jinja code blocks

New special variable

The pdl_usage variable contains the statistics accumulated by the calls the the models. Here is a simple examples showing the fields of the pdl_usage variable.

text:
- Hello
- model: ollama/granite4:micro
- |
  Usage Statistics:
  - Model calls: ${ pdl_usage.model_calls }
  - Prompt tokens: ${ pdl_usage.prompt_tokens }
  - Completion tokens: ${ pdl_usage.completion_tokens }
  - Total tokens: ${ pdl_usage.prompt_tokens + pdl_usage.completion_tokens }

The pdl_scope variable allows to do reflexion on the variables in scope at the current execution point. The following examples list the available variables:

defs:
  greeting: Hello
  name: World
text:
- |
  ${ pdl_scope["greeting"]}, ${ pdl_scope["name"] }!
  Available variables in scope:
- for:
    key: ${ pdl_scope.keys() }
  repeat:
    text: |
      - ${ key }

The scope field in code blocks

The user can now specify which variables are available the the scope of the code executed in a code Python and Jinja code block (by default all of the variables in pdl_scope are available). Here is an example where the variable x and y are in scope for the code block, but not the variable z:

defs:
  z: 0
lang: python
scope:
  x: 10
  y: 20
code: |
  result = x + y

Jinja code block parameters

The user can now configure Jinja template behavior by passing parameters to the Jinja Template constructor. Here is an example that configures Jinja's whitespace handling:

defs:
  items:
    data:
    - apple
    - banana
    - cherry
lang: jinja
parameters:
  trim_blocks: true
  lstrip_blocks: true
code: |
  Shopping List:
  {% for item in items %}
    - {{ item }}
  {% endfor %}
  
  Total items: {{ items | length }}

Non-backward compatible changes

This release introduce some changes that are not compatible with previous versions of PDL:

  • the syntax of the signatures generated by .signature on functions has changed
  • the re-evaluation of rule of aggregator declarations, functions have changed

What's Changed

  • Fix in MessageBlock by @vazirim in #1410
  • fix: close event loop cleanly by @mandel in #1415
  • tests: update tests results by @mandel in #1438
  • docs: Add missing comments and docstrings to pdl_ast.py by @mandel in #1440
  • refactor: replace Union and Optional with | None syntax by @mandel in #1441
  • change to assistant message post-processing by @vazirim in #1442
  • Prevent AggregatorBlock from being cached in replay by @mandel in #1449
  • Add usage to scope by @gbdrt in #1448
  • Change MessageBlock.tool_calls type to OptionalExpressionList by @mandel in #1447
  • fix: replay of blocks raising exceptions by @mandel in #1451
  • Fix: Add FunctionBlock to replay check in process_block_body_with_replay by @mandel in #1464
  • feat: implement scope field handling for CodeBlock by @mandel in #1479
  • feat: add pdl_scope to the scope by @mandel in #1480
  • feat: Use LiteLLM syntax for tool call signature by @mandel in #1477
  • tests: switch examples to granite 4 by @mandel in #1475
  • feat: add a parameters field to Jinja code blocks by @mandel in #1485
  • feat: add a get_tool_calls function in stdlib by @mandel in #1484
  • docs: fix tutorial by @mandel in #1496
  • fix: FileAggregator resource leak by @mandel in #1497

Full Changelog: v0.9.2...v0.9.3