PDL for Mac

The latest version of PDL for Mac is 0.9.3, released . Declarative language for creating reliable, composable LLM prompts.

What's new in PDL 0.9.3

New Features

The main new features are:

  • Add the variables pdlusage and pdlscope to the PDL scope
  • Add a scope field to the code blocks
  • Add a parameters field to Jinja code blocks

New special variable

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

Show 21 more

text: - Hello - model: ollama/granite4:micro - | Usage Statistics: - Model calls: ${ pdlusage.modelcalls } - Prompt tokens: ${ pdlusage.prompttokens } - Completion tokens: ${ pdlusage.completiontokens } - Total tokens: ${ pdlusage.prompttokens + pdlusage.completiontokens }

The pdlscope 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: - | ${ pdlscope["greeting"]}, ${ pdlscope["name"] }! Available variables in scope: - for: key: ${ pdlscope.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 pdlscope 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: trimblocks: true lstripblocks: 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
  • fix: close event loop cleanly
  • tests: update tests results
  • docs: Add missing comments and docstrings to pdlast.py
  • refactor: replace Union and Optional with | None syntax
  • change to assistant message post-processing
  • Prevent AggregatorBlock from being cached in replay
  • Add usage to scope
  • Change MessageBlock.toolcalls type to OptionalExpressionList
  • fix: replay of blocks raising exceptions
  • Fix: Add FunctionBlock to replay check in processblockbodywithreplay
  • feat: implement scope field handling for CodeBlock
  • feat: add pdlscope to the scope
  • feat: Use LiteLLM syntax for tool call signature
  • tests: switch examples to granite 4
  • feat: add a parameters field to Jinja code blocks
  • feat: add a gettoolcalls function in stdlib
  • docs: fix tutorial
  • fix: FileAggregator resource leak

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

Source: github.com

How to update PDL on your Mac

PDL version history

  1. 0.9.3
  2. 0.9.2

    New Features

    The main new feature is:

    • sequence block that corresponds the a general version of text, lastOfm and array.

    The sequence block expect a list a PDL blocks that and executed in sequence and whose results are combine following the provided join specification. For example, an array can be created as follow:

    sequence: - Hello - model: ollama/granite4 join: as: array

    What's Changed

    • chore: fix typos
    • feat: add stdlib.boolconfidence function
    • Stdlib llmasjudge changes to accept parameters
    • tests: CI do not test with Python 3.13 to reduce load
    • feat: new sequence block
    • Fix for eventloop in AutoPDL optimizer

    New Contributors

    • @afuetterer made their first contribution in #1363

    Full Changelog: v0.9.1...v0.9.2

    Source: github.com

  3. 0.9.1

    New Features

    The main new feature is:

    • support CSV format in the parser field.

    What's Changed

    • fix: stringify as json when contributing to a string
    • Support for parsing csv

    Full Changelog: v0.9.0...v0.9.1

    Source: github.com

  4. 0.9.0

    New Features

    The main new features are:

    • contribute to a file or standard input and error
    • @pdl Python 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: ollamachat/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: ollamachat/granite3.3:2b modelResponse: rawresponse contribute: - result - context - stderr: value: ${rawresponse}

    @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 chainofthought(scope): """ lastOf: - "Question: ${ question }\n" - "Answer: Let's think step by step. " - model: ollamachat/granite3.3:2b parameters: stop: - "" - "Question:" includestopsequence: false """ return def main(): result = chainofthought( scope={"model": "ollamachat/granite3.2:2b", "question": "How to write Hello World in OCaml?\n"} ) print(result) if name == "main": main()

    In this example, the function chainpfthought 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
    • First class aggregators
    • refactor: react pattern in prompt library
    • PDL Python decorator
    • fix: type error location
    • refactor: interpreter
    • fix: return the value not the future when a closure is called fro jin…
    • feat: the scope of the content field is local
    • feat: replay an execution
    • refactor: performance optimizations
    • feat: add eventloop to the interpreter config
    • feat: do not reload library when importing multiple time a file
    • feat: structuredDecoding field on the model block
    • docs: update type checking and structured decoding in the tutorial
    • feat: improve error messages
    • fix: imported files can use stdlib
    • fix: improve error messages
    • fix: avoid catching KeyboardInterrupt
    • fix: bug in ipython code block
    • refactor: use TypedDict for exec program output
    • feat: do not dump location tables in the trace
    • feat: collect global statistics on LLM usage
    • feat: add llmusage to the exec config

    Full Changelog: v0.8.0...v0.9.0

    Source: github.com

  5. 0.8.0

    New Features

    The main changes in this release are:

    • AutoPDL: automatic optimization of PDL programs
    • Calling PDL functions from Jinja and Python
    • Map/reduce block

    AutoPDL: automatic optimization of PDL programs

    Given a PDL program with some free variables, a search space for these free variable, a loss function, and a training set, you can optimize the PDL program using the pdl-optimize command. This allows to optimize any part of a PDL program such as the textual prompts, the few-shots examples, or the prompting patterns. This work is based on the paper AutoPDL: Automatic Prompt Optimization for LLM Agents. A new section of the manual is describing how to use the optimizer.

    Calling PDL functions from Jinja and Python

    It is now possible to call a function defined in PDL inside a Jinja expression or a Python code block. Here is an example where the function translate is called in the Jinja expression ${ translate("Hello", language="French") }:

    description: Calling a PDL function from Jinja defs: translate: function: sentence: string language: string return: lastOf: - | Translate the sentence '${ sentence }' to ${ language }. Only give the result of the translation. - model: ollamachat/granite3.2:2b text: | The way to say hello in French is ${ translate("Hello", language="French") }.

    Map/reduce block

    Similar to the repeat loops, PDL now offers a map block. The difference with the repeat block is that the context is not accumulated between iterations, each iteration is executed with the same context. Here is an example of map block:

    lastOf: - "Hello, " - for: name: [Alice, Bob, Charlie] map: lastOf: - my name is ${ name } - model: ollama/granite3.2:2b join: as: array

    What's Changed

    • chore: Configure Renovate
    • Dataset preprocessing scripts for AutoPDL
    • fix: avoid side effects in PdlContext
    • tests: update react example
    • tests: update calc example to use .signature
    • fix: output streaming in case of fallback
    • feat: make PDL functions callable as Python and jinja functions
    • feat: allow unnamed arguments when calling a PDL function in Jinja
    • feat: map/reduce
    • refactor: refactor AST to generate simpler JSON Schema
    • Fix for exception in optimizer
    • docs: update tutorial
    • Requirements implementation
    • fix: update AST in the UI
    • fix: ensure that PazyApply.result returns a non-lazy value
    • feat: parallel map reduce
    • Fix for llm message post-processing
    • AutoPDL Simplification
    • tests: map-based gsm8k
    • optimizer CLI and doc

    Full Changelog: v0.7.1...v0.8.0

    Source: github.com

  6. 0.7.1

    What's Changed

    • refactor: make the event loop thread part of the interpreter state
    • fix: contribute directly a value to the context

    Full Changelog: v0.7.0...v0.7.1

    Source: github.com

  7. 0.7.0

    New Features

    The main new features are the following and are detailed bellow:

    • new retry attribute to any block,
    • new index field to introduce a loop index in repeat blocks
    • new syntax for types with suport for JSON Schema,
    • extract the signature of a function f with f.signature,
    • loop and sequences with independent contexts,
    • support for granite-io processors created in Python.

    The retry field

    Any block can now have a retry field indicating how many times a block should be executed if it encounters a runtime error. For example, a model call can be retried 5 times as follows:

    model: replicate/ibm-granite/granite-3.3-8b-instruct input: How to program "Hello World!"? retry: 5

    The loop index field

    A common pattern in PDL programs is to introduce a variable to index the loop iterations. For example, a loop that turns a list of strings into a list of object with a field name and id would be written as follows:

    defs: id: -1 for: name: [ "Alice", "Nicolas", "Rosa", "Remi" ] repeat: defs: id: ${ id + 1} data: name: ${name} id: ${id} join: as: array

    With the new index field that introduced a variable name as loop index, this code can now be simplified as follows:

    for: name: [ "Alice", "Nicolas", "Rosa", "Remi" ] index: id repeat: data: name: ${name} id: ${id} join: as: array

    New type syntax

    We extended the type syntax to be able to write directly some JSON Schema as block specification. To do so, the type must contain the type or enum field. For example, we can write a model block that checks that the output starts with the letter "A" as follows:

    model: ollama/granite3.3:2b input: Generate a word that starts with the letter "A". Just output the single word. spec: type: string pattern: "^[Aa]"

    To make the syntax more uniform, we are using the JSON Schema syntax for the base type. So for example, we are using number instead of float for floating point numbers. We discuss the breaking changes below.

    Extract function signature

    In order to make the use of PDL functions as tools by LLMs easier, we provide the ability to extract the signature of a function f by executing f.signature. Here is an example:

    defs: calc: description: Calculator function function: expr: type: string description: Arithmetic expression to calculate return: lang: python code: result = ${ expr } text: ${ calc.signature }

    The output is:

    {"type": "function", "name": "calc", "description": "Calculator function", "parameters": {"type": "object", "properties": {"expr": {"type": "string", "description": "Arithmetic expression to calculate"}}, "required": ["expr"], "additionalProperties": false}}

    An example of tool use is given in search.pdl.

    Independent contexts

    Blocks containing lists of blocks (text, array, object, and lastOf) as well as loops can now be annotated with context: independent. It means that each sub-block is executed in an independent copy of the context. Therefore, if we execute the following program, both model calls are executed with the same input containing the message Hello:

    lastOf: - Hello - context: independent array: - model: ollama/granite3.2:2b - model: ollama/granite3.3:2b

    Support for granite-io processors objects

    In addition to the ability to call granite-io processors using the lookup mechanism using backend and processors names, it is possible now to use granite-io processors or backends created in Python. Here is an example:

    defs: ioproc: lang: python code: | from graniteio import makebackend, makeioprocessor modelname = "granite3.2:2b" backend = makebackend("openai", { "modelname": modelname }) result = makeioprocessor(modelname, backend=backend) processor: ${ ioproc } input: Write an Hello World program in Python.

    Breaking Changes

    This version of PDL is coming with a large number of breaking changes:

    • types syntax,
    • granite-io syntax,
    • rename maxiterations into maxIterations,
    • trace format.

    Source: github.com

  8. 0.6.2

    What's Changed

    • Fix rag example by fully qualifying import
    • Change to sys.path for python code block
    • granite-io hallucination demo example and notebook
    • Add contrib. prompt library
    • Fixed the bug where pdl.version was not set
    • feat: add a parsedict function to pdlparser
    • feat: specify PDL types in the AST
    • chore(deps): Update granite-io requirement from =0.2 to >=0.2,<0.5
    • chore(deps): Update faiss-cpu requirement from ~=1.10.0 to >=1.10,<1.12
    • Fix for extra fields in messages sent to LLMs

    Full Changelog: v0.6.1...v0.6.2

    Source: github.com

Details

Latest version
0.9.3
Released
Last checked
Website
ibm.github.io
Homebrew cask
pdl