API Reference
This page documents the PDL members that likely to be used to run PDL programs from Python.
Program
PDL programs are represented by the Pydantic data structure defined in this file.
Classes:
Name | Description |
---|---|
PdlLocationType |
Internal data structure to keep track of the source location information. |
LocalizedExpression |
Internal data structure for expressions with location information. |
Pattern |
Common fields for structured patterns. |
OrPattern |
Match any of the patterns. |
ArrayPattern |
Match an array. |
ObjectPattern |
Match an object. |
AnyPattern |
Match any value. |
PdlType |
Common fields for PDL types. |
OptionalPdlType |
Optional type. |
JsonSchemaTypePdlType |
Json Schema with a type field. |
EnumPdlType |
Json Schema with an |
ObjectPdlType |
Object type. |
Parser |
Common fields for all parsers ( |
PdlParser |
Use a PDL program as a parser specification (experimental). |
RegexParser |
A regular expression parser. |
ContributeTarget |
Values allowed in the |
ContributeValue |
Contribution of a specific value instead of the default one. |
ExpectationType |
Single expectation definition. |
PdlTiming |
Internal data structure to record timing information in the trace. |
PdlUsage |
Internal data structure to record token consumption usage information. |
Block |
Common fields for all PDL blocks. |
FunctionBlock |
Function declaration. |
CallBlock |
Calling a function. |
LitellmParameters |
Parameters passed to LiteLLM. More details at https://docs.litellm.ai/docs/completion/input. |
ModelBlock |
Common fields for the |
LitellmModelBlock |
Call an LLM through the LiteLLM API. |
GraniteioProcessor |
|
GraniteioModelBlock |
Call an LLM through the granite-io API. |
CodeBlock |
Execute a piece of code. |
ArgsBlock |
Execute a command line, which will spawn a subprocess with the given argument vector. Note: if you need a shell script execution, you must wrap your command line in /bin/sh or some shell of your choosing. |
GetBlock |
Get the value of a variable. |
DataBlock |
Arbitrary value, equivalent to JSON. |
TextBlock |
Create the concatenation of the stringify version of the result of each block of the list of blocks. |
LastOfBlock |
Return the value of the last block if the list of blocks. |
ArrayBlock |
Return the array of values computed by each block of the list of blocks. |
ObjectBlock |
Return the object where the value of each field is defined by a block. If the body of the object is an array, the resulting object is the union of the objects computed by each element of the array. |
MessageBlock |
Create a message. |
IfBlock |
Conditional control structure. |
MatchCase |
Case of a match. |
MatchBlock |
Match control structure. |
JoinConfig |
Configure how loop iterations should be combined. |
JoinText |
Join loop iterations as a string. |
JoinArray |
Join loop iterations as an array. |
JoinObject |
Join loop iterations as an object. |
JoinLastOf |
Join loop iterations as the value of the last iteration. |
JoinReduce |
Join loop iterations as the value of the last iteration. |
RepeatBlock |
Repeat the execution of a block sequentially. |
MapBlock |
Independent executions of a block. |
ReadBlock |
Read from a file or standard input. |
IncludeBlock |
Include a PDL file. |
ImportBlock |
Import a PDL file. |
AggregatorConfig |
Common fields for all aggregator configurations. |
FileAggregatorConfig |
|
AggregatorBlock |
Create a new aggregator that can be use in the |
ErrorBlock |
Block representing an error generated at runtime. |
EmptyBlock |
Block without an action. It can contain definitions. |
Program |
Prompt Declaration Language program (PDL) |
Functions:
Name | Description |
---|---|
get_default_model_parameters |
Model-specific defaults to apply |
get_sampling_defaults |
Model-specific defaults to apply if we are sampling. |
Attributes:
Name | Type | Description |
---|---|---|
OptionalStr |
Optional string. |
|
OptionalInt |
Optional integer. |
|
OptionalBool |
Optional Boolean. |
|
OptionalBoolOrStr |
Optional boolean or string. |
|
OptionalAny |
Optional value of any type. |
|
OptionalBlockType |
Optional block. |
|
ScopeType |
Type of the execution environment. |
|
ModelInput |
Type of the input of an LLM call. |
|
OptionalModelInput |
Optional value of type ModelInput. |
|
OptionalPdlLocationType |
Optional location type. |
|
ExpressionType |
TypeAlias
|
Expressions are represented Jinja as strings in between |
ExpressionStr |
Expression evaluating into a string. |
|
OptionalExpressionStr |
Optional expression evaluating into a string. |
|
ExpressionInt |
Expression evaluating into an int. |
|
OptionalExpressionInt |
Optional expression evaluating into an int. |
|
ExpressionBool |
Expression evaluating into a bool. |
|
OptionalExpressionBool |
Optional expression evaluating into a bool. |
|
PatternType |
Patterns allowed to match values in a |
|
BasePdlType |
TypeAlias
|
Base types. |
PdlTypeType |
Types. |
|
ParserType |
Different parsers. |
|
OptionalParserType |
Optional parser. |
|
RoleType |
TypeAlias
|
Role name. |
ContributeElement |
Type of the contribute field. |
|
ExpectationsType |
Type of expectations field |
|
OptionalPdlTiming |
Optional execution time information. |
|
OptionalPdlUsage |
Optional usage of statistics of an LLM call. |
|
JoinType |
Different ways to join loop iterations. |
|
AdvancedBlockType |
TypeAlias
|
Different types of structured blocks. |
BlockType |
All kinds of blocks. |
|
BlockOrBlocksType |
TypeAlias
|
Block or list of blocks. |
OptionalStr = TypeAliasType('OptionalStr', Optional[str])
module-attribute
Optional string.
OptionalInt = TypeAliasType('OptionalInt', Optional[int])
module-attribute
Optional integer.
OptionalBool = TypeAliasType('OptionalBool', Optional[bool])
module-attribute
Optional Boolean.
OptionalBoolOrStr = TypeAliasType('OptionalBoolOrStr', Optional[Union[bool, str]])
module-attribute
Optional boolean or string.
OptionalAny = TypeAliasType('OptionalAny', Optional[Any])
module-attribute
Optional value of any type.
OptionalBlockType = TypeAliasType('OptionalBlockType', Optional['BlockType'])
module-attribute
Optional block.
ScopeType = TypeAliasType('ScopeType', PdlDict[str, Any])
module-attribute
Type of the execution environment.
ModelInput = TypeAliasType('ModelInput', Sequence[Mapping[str, Any]])
module-attribute
Type of the input of an LLM call.
OptionalModelInput = TypeAliasType('OptionalModelInput', Optional[ModelInput])
module-attribute
Optional value of type ModelInput.
OptionalPdlLocationType = TypeAliasType('OptionalPdlLocationType', Optional[PdlLocationType])
module-attribute
Optional location type.
ExpressionType: TypeAlias = LocalizedExpression[ExpressionTypeT] | ExpressionTypeT | str
module-attribute
Expressions are represented Jinja as strings in between ${
and }
.
ExpressionStr = TypeAliasType('ExpressionStr', ExpressionType[str])
module-attribute
Expression evaluating into a string.
OptionalExpressionStr = TypeAliasType('OptionalExpressionStr', Optional[ExpressionStr])
module-attribute
Optional expression evaluating into a string.
ExpressionInt = TypeAliasType('ExpressionInt', ExpressionType[int])
module-attribute
Expression evaluating into an int.
OptionalExpressionInt = TypeAliasType('OptionalExpressionInt', Optional[ExpressionInt])
module-attribute
Optional expression evaluating into an int.
ExpressionBool = TypeAliasType('ExpressionBool', ExpressionType[bool])
module-attribute
Expression evaluating into a bool.
OptionalExpressionBool = TypeAliasType('OptionalExpressionBool', Optional[ExpressionBool])
module-attribute
Optional expression evaluating into a bool.
PatternType = TypeAliasType('PatternType', Union[None, bool, int, float, str, OrPattern, ArrayPattern, ObjectPattern, AnyPattern])
module-attribute
Patterns allowed to match values in a case
clause.
BasePdlType: TypeAlias = Literal['null', 'boolean', 'string', 'number', 'integer', 'array', 'object', 'bool', 'str', 'float', 'int', 'list', 'obj']
module-attribute
Base types.
PdlTypeType = TypeAliasType('PdlTypeType', Annotated["Union[None, BasePdlType, EnumPdlType, list['PdlTypeType'], OptionalPdlType, JsonSchemaTypePdlType, ObjectPdlType, dict[str, 'PdlTypeType']]", Field(union_mode='left_to_right')])
module-attribute
Types.
ParserType = TypeAliasType('ParserType', Union[Literal['json', 'jsonl', 'yaml'], PdlParser, RegexParser])
module-attribute
Different parsers.
OptionalParserType = TypeAliasType('OptionalParserType', Optional[ParserType])
module-attribute
Optional parser.
RoleType: TypeAlias = OptionalStr
module-attribute
Role name.
ContributeElement = TypeAliasType('ContributeElement', Union[ContributeTarget, str, dict[str, ContributeValue]])
module-attribute
Type of the contribute field.
ExpectationsType = TypeAliasType('ExpectationsType', Sequence[ExpectationType])
module-attribute
Type of expectations field
OptionalPdlTiming = TypeAliasType('OptionalPdlTiming', Optional[PdlTiming])
module-attribute
Optional execution time information.
OptionalPdlUsage = TypeAliasType('OptionalPdlUsage', Optional[PdlUsage])
module-attribute
Optional usage of statistics of an LLM call.
JoinType = TypeAliasType('JoinType', Union[JoinText, JoinArray, JoinObject, JoinLastOf, JoinReduce])
module-attribute
Different ways to join loop iterations.
AdvancedBlockType: TypeAlias = FunctionBlock | CallBlock | LitellmModelBlock | GraniteioModelBlock | CodeBlock | ArgsBlock | GetBlock | DataBlock | IfBlock | MatchBlock | RepeatBlock | MapBlock | TextBlock | LastOfBlock | ArrayBlock | ObjectBlock | MessageBlock | ReadBlock | IncludeBlock | ImportBlock | AggregatorBlock | ErrorBlock | EmptyBlock
module-attribute
Different types of structured blocks.
BlockType = TypeAliasType('BlockType', Union[None, bool, int, float, str, AdvancedBlockType])
module-attribute
All kinds of blocks.
BlockOrBlocksType: TypeAlias = BlockType | list[BlockType]
module-attribute
Block or list of blocks.
PdlLocationType
Bases: BaseModel
Internal data structure to keep track of the source location information.
Source code in src/pdl/pdl_ast.py
91 92 93 94 95 96 97 |
|
LocalizedExpression
Bases: BaseModel
, Generic[LocalizedExpressionT]
Internal data structure for expressions with location information.
Source code in src/pdl/pdl_ast.py
112 113 114 115 116 117 118 119 120 121 122 123 |
|
Pattern
Bases: BaseModel
Common fields for structured patterns.
Attributes:
Name | Type | Description |
---|---|---|
def_ |
OptionalStr
|
Name of the variable used to store the value matched by the pattern. |
Source code in src/pdl/pdl_ast.py
151 152 153 154 155 156 157 |
|
def_: OptionalStr = Field(default=None, alias='def')
class-attribute
instance-attribute
Name of the variable used to store the value matched by the pattern.
OrPattern
Bases: Pattern
Match any of the patterns.
Attributes:
Name | Type | Description |
---|---|---|
anyOf |
list[PatternType]
|
List of possible patterns. |
Source code in src/pdl/pdl_ast.py
160 161 162 163 164 |
|
anyOf: list[PatternType]
instance-attribute
List of possible patterns.
ArrayPattern
Bases: Pattern
Match an array.
Attributes:
Name | Type | Description |
---|---|---|
array |
list[PatternType]
|
Shape of the array to match. |
Source code in src/pdl/pdl_ast.py
167 168 169 170 171 |
|
array: list[PatternType]
instance-attribute
Shape of the array to match.
ObjectPattern
Bases: Pattern
Match an object.
Attributes:
Name | Type | Description |
---|---|---|
object |
dict[str, PatternType]
|
Shape of the object to match. |
Source code in src/pdl/pdl_ast.py
174 175 176 177 178 |
|
object: dict[str, PatternType]
instance-attribute
Shape of the object to match.
AnyPattern
Bases: Pattern
Match any value.
Source code in src/pdl/pdl_ast.py
181 182 183 184 |
|
PdlType
Bases: BaseModel
Common fields for PDL types.
Source code in src/pdl/pdl_ast.py
215 216 217 218 |
|
OptionalPdlType
Bases: PdlType
Optional type.
Attributes:
Name | Type | Description |
---|---|---|
optional |
PdlTypeType
|
|
Source code in src/pdl/pdl_ast.py
221 222 223 224 225 |
|
optional: PdlTypeType
instance-attribute
JsonSchemaTypePdlType
Bases: PdlType
Json Schema with a type field.
Attributes:
Name | Type | Description |
---|---|---|
type |
str | list[str]
|
Data type that a schema should expect. |
Source code in src/pdl/pdl_ast.py
228 229 230 231 232 233 234 |
|
type: str | list[str]
instance-attribute
Data type that a schema should expect.
EnumPdlType
Bases: PdlType
Json Schema with an enum
field.
Attributes:
Name | Type | Description |
---|---|---|
enum |
list[Any]
|
List of allowed values in the type. |
Source code in src/pdl/pdl_ast.py
237 238 239 240 241 242 243 |
|
enum: list[Any]
instance-attribute
List of allowed values in the type.
ObjectPdlType
Bases: PdlType
Object type.
Attributes:
Name | Type | Description |
---|---|---|
object |
dict[str, PdlTypeType]
|
Fields of the objects with their types. |
Source code in src/pdl/pdl_ast.py
246 247 248 249 250 |
|
object: dict[str, PdlTypeType]
instance-attribute
Fields of the objects with their types.
Parser
Bases: BaseModel
Common fields for all parsers (parser
field).
Attributes:
Name | Type | Description |
---|---|---|
description |
OptionalStr
|
Documentation associated to the parser. |
spec |
PdlTypeType
|
Expected type of the parsed value. |
Source code in src/pdl/pdl_ast.py
272 273 274 275 276 277 278 279 280 281 |
|
description: OptionalStr = None
class-attribute
instance-attribute
Documentation associated to the parser.
spec: PdlTypeType = None
class-attribute
instance-attribute
Expected type of the parsed value.
PdlParser
Bases: Parser
Use a PDL program as a parser specification (experimental).
Attributes:
Name | Type | Description |
---|---|---|
pdl |
BlockType
|
PDL program describing the shape of the expected value. |
Source code in src/pdl/pdl_ast.py
284 285 286 287 288 |
|
pdl: BlockType
instance-attribute
PDL program describing the shape of the expected value.
RegexParser
Bases: Parser
A regular expression parser.
Attributes:
Name | Type | Description |
---|---|---|
regex |
str
|
Regular expression to parse the value. |
mode |
Annotated[Literal['search', 'match', 'fullmatch', 'split', 'findall'], BeforeValidator(_ensure_lower)]
|
Function used to parse to value (https://docs.python.org/3/library/re.html). |
Source code in src/pdl/pdl_ast.py
291 292 293 294 295 296 297 298 299 300 |
|
regex: str
instance-attribute
Regular expression to parse the value.
mode: Annotated[Literal['search', 'match', 'fullmatch', 'split', 'findall'], BeforeValidator(_ensure_lower)] = 'fullmatch'
class-attribute
instance-attribute
Function used to parse to value (https://docs.python.org/3/library/re.html).
ContributeTarget
Bases: StrEnum
Values allowed in the contribute
field.
Source code in src/pdl/pdl_ast.py
314 315 316 317 318 319 320 |
|
ContributeValue
Bases: BaseModel
Contribution of a specific value instead of the default one.
Attributes:
Name | Type | Description |
---|---|---|
value |
ExpressionType[Any]
|
Value to contribute. |
Source code in src/pdl/pdl_ast.py
323 324 325 326 327 328 329 |
|
value: ExpressionType[Any]
instance-attribute
Value to contribute.
ExpectationType
Bases: BaseModel
Single expectation definition.
Attributes:
Name | Type | Description |
---|---|---|
expect |
ExpressionType
|
English description of the expectation |
feedback |
Optional[ExpressionType[FunctionBlock]]
|
Feedback function for the expectation |
Source code in src/pdl/pdl_ast.py
338 339 340 341 342 343 344 345 346 347 |
|
expect: ExpressionType
instance-attribute
English description of the expectation
feedback: Optional[ExpressionType[FunctionBlock]] = None
class-attribute
instance-attribute
Feedback function for the expectation
PdlTiming
Bases: BaseModel
Internal data structure to record timing information in the trace.
Attributes:
Name | Type | Description |
---|---|---|
start_nanos |
OptionalInt
|
Time at which block execution began. |
end_nanos |
OptionalInt
|
Time at which block execution ended. |
first_use_nanos |
OptionalInt
|
Time at which the value of the block was needed for the first time. |
timezone |
OptionalStr
|
Timezone of start_nanos and end_nanos. |
Source code in src/pdl/pdl_ast.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
|
start_nanos: OptionalInt = 0
class-attribute
instance-attribute
Time at which block execution began.
end_nanos: OptionalInt = 0
class-attribute
instance-attribute
Time at which block execution ended.
first_use_nanos: OptionalInt = 0
class-attribute
instance-attribute
Time at which the value of the block was needed for the first time.
timezone: OptionalStr = ''
class-attribute
instance-attribute
Timezone of start_nanos and end_nanos.
PdlUsage
Bases: BaseModel
Internal data structure to record token consumption usage information.
Attributes:
Name | Type | Description |
---|---|---|
completion_tokens |
OptionalInt
|
Completion tokens consumed |
prompt_tokens |
OptionalInt
|
Prompt tokens consumed |
Source code in src/pdl/pdl_ast.py
376 377 378 379 380 381 382 383 384 |
|
completion_tokens: OptionalInt = 0
class-attribute
instance-attribute
Completion tokens consumed
prompt_tokens: OptionalInt = 0
class-attribute
instance-attribute
Prompt tokens consumed
Block
Bases: BaseModel
Common fields for all PDL blocks.
Attributes:
Name | Type | Description |
---|---|---|
description |
OptionalStr
|
Documentation associated to the block. |
spec |
PdlTypeType
|
Type specification of the result of the block. |
defs |
dict[str, BlockType]
|
Set of definitions executed before the execution of the block. |
def_ |
OptionalStr
|
Name of the variable used to store the result of the execution of the block. |
contribute |
Sequence[ContributeElement]
|
Indicate if the block contributes to the result and background context. |
parser |
Annotated[OptionalParserType, BeforeValidator(_ensure_lower)]
|
Parser to use to construct a value out of a string result. |
fallback |
OptionalBlockType
|
Block to execute in case of error. |
retry |
OptionalInt
|
The maximum number of times to retry when an error occurs within a block. |
trace_error_on_retry |
OptionalBoolOrStr
|
Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials. |
expectations |
ExpectationsType
|
Specify any expectations that the result of the block must satisfy. |
role |
RoleType
|
Role associated to the block and sub-blocks. |
pdl__context |
OptionalModelInput
|
Current context. |
pdl__id |
OptionalStr
|
Unique identifier for this block. |
pdl__result |
OptionalAny
|
Result of the execution of the block. |
pdl__timing |
OptionalPdlTiming
|
Execution timing information. |
Source code in src/pdl/pdl_ast.py
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
|
description: OptionalStr = None
class-attribute
instance-attribute
Documentation associated to the block.
spec: PdlTypeType = None
class-attribute
instance-attribute
Type specification of the result of the block.
defs: dict[str, BlockType] = {}
class-attribute
instance-attribute
Set of definitions executed before the execution of the block.
def_: OptionalStr = Field(default=None, alias='def')
class-attribute
instance-attribute
Name of the variable used to store the result of the execution of the block.
contribute: Sequence[ContributeElement] = [ContributeTarget.RESULT, ContributeTarget.CONTEXT]
class-attribute
instance-attribute
Indicate if the block contributes to the result and background context.
parser: Annotated[OptionalParserType, BeforeValidator(_ensure_lower)] = None
class-attribute
instance-attribute
Parser to use to construct a value out of a string result.
fallback: OptionalBlockType = None
class-attribute
instance-attribute
Block to execute in case of error.
retry: OptionalInt = None
class-attribute
instance-attribute
The maximum number of times to retry when an error occurs within a block.
trace_error_on_retry: OptionalBoolOrStr = None
class-attribute
instance-attribute
Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.
expectations: ExpectationsType = []
class-attribute
instance-attribute
Specify any expectations that the result of the block must satisfy.
role: RoleType = None
class-attribute
instance-attribute
Role associated to the block and sub-blocks.
Typical roles are system
, user
, and assistant
,
but there may be other roles such as available_tools
.
pdl__context: OptionalModelInput = []
class-attribute
instance-attribute
Current context.
pdl__id: OptionalStr = ''
class-attribute
instance-attribute
Unique identifier for this block.
pdl__result: OptionalAny = None
class-attribute
instance-attribute
Result of the execution of the block.
pdl__timing: OptionalPdlTiming = None
class-attribute
instance-attribute
Execution timing information.
FunctionBlock
Bases: LeafBlock
Function declaration.
Attributes:
Name | Type | Description |
---|---|---|
function |
Optional[dict[str, PdlTypeType]]
|
Functions parameters with their types. |
return_ |
BlockType
|
Body of the function. |
signature |
Optional[Json]
|
Function signature computed from the function definition. |
Source code in src/pdl/pdl_ast.py
468 469 470 471 472 473 474 475 476 477 478 479 480 |
|
function: Optional[dict[str, PdlTypeType]]
instance-attribute
Functions parameters with their types.
return_: BlockType = Field(..., alias='return')
class-attribute
instance-attribute
Body of the function.
signature: Optional[Json] = None
class-attribute
instance-attribute
Function signature computed from the function definition.
CallBlock
Bases: LeafBlock
Calling a function.
Attributes:
Name | Type | Description |
---|---|---|
call |
ExpressionType[FunctionBlock]
|
Function to call. |
args |
ExpressionType
|
Arguments of the function with their values. |
Source code in src/pdl/pdl_ast.py
483 484 485 486 487 488 489 490 491 492 493 494 |
|
call: ExpressionType[FunctionBlock]
instance-attribute
Function to call.
args: ExpressionType = {}
class-attribute
instance-attribute
Arguments of the function with their values.
LitellmParameters
Bases: BaseModel
Parameters passed to LiteLLM. More details at https://docs.litellm.ai/docs/completion/input.
Note that not all models and platforms accept all parameters.
Attributes:
Name | Type | Description |
---|---|---|
timeout |
Optional[Union[float, str]] | str
|
Timeout in seconds for completion requests (Defaults to 600 seconds). |
temperature |
Optional[float] | str
|
The temperature parameter for controlling the randomness of the output (default is 1.0). |
top_p |
Optional[float] | str
|
The top-p parameter for nucleus sampling (default is 1.0). |
n |
Optional[int] | str
|
The number of completions to generate (default is 1). |
stop |
Optional[str | list[str]] | str
|
Up to 4 sequences where the LLM API will stop generating further tokens. |
max_tokens |
Optional[int] | str
|
The maximum number of tokens in the generated completion (default is infinity). |
presence_penalty |
Optional[float] | str
|
It is used to penalize new tokens based on their existence in the text so far. |
frequency_penalty |
Optional[float] | str
|
It is used to penalize new tokens based on their frequency in the text so far. |
logit_bias |
Optional[dict] | str
|
Used to modify the probability of specific tokens appearing in the completion. |
user |
Optional[str] | str
|
A unique identifier representing your end-user. This can help the LLM provider to monitor and detect abuse. |
logprobs |
Optional[bool] | str
|
Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the content of message |
top_logprobs |
Optional[int] | str
|
top_logprobs (int, optional): An integer between 0 and 5 specifying the number of most likely tokens to return at each token position, each with an associated log probability. logprobs must be set to true if this parameter is used. |
extra_headers |
Optional[dict] | str
|
Additional headers to include in the request. |
functions |
Optional[list] | str
|
A list of functions to apply to the conversation messages (default is an empty list) |
function_call |
Optional[str] | str
|
The name of the function to call within the conversation (default is an empty string) |
base_url |
Optional[str] | str
|
Base URL for the API (default is None). |
api_version |
Optional[str] | str
|
API version (default is None). |
api_key |
Optional[str] | str
|
API key (default is None). |
model_list |
Optional[list] | str
|
List of api base, version, keys. |
mock_response |
Optional[str] | str
|
If provided, return a mock completion response for testing or debugging purposes (default is None). |
custom_llm_provider |
Optional[str] | str
|
Used for Non-OpenAI LLMs, Example usage for bedrock, set model="amazon.titan-tg1-large" and custom_llm_provider="bedrock" |
max_retries |
Optional[int] | str
|
The number of retries to attempt (default is 0). |
Source code in src/pdl/pdl_ast.py
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 |
|
timeout: Optional[Union[float, str]] | str = None
class-attribute
instance-attribute
Timeout in seconds for completion requests (Defaults to 600 seconds).
temperature: Optional[float] | str = None
class-attribute
instance-attribute
The temperature parameter for controlling the randomness of the output (default is 1.0).
top_p: Optional[float] | str = None
class-attribute
instance-attribute
The top-p parameter for nucleus sampling (default is 1.0).
n: Optional[int] | str = None
class-attribute
instance-attribute
The number of completions to generate (default is 1).
stop: Optional[str | list[str]] | str = None
class-attribute
instance-attribute
Up to 4 sequences where the LLM API will stop generating further tokens.
max_tokens: Optional[int] | str = None
class-attribute
instance-attribute
The maximum number of tokens in the generated completion (default is infinity).
presence_penalty: Optional[float] | str = None
class-attribute
instance-attribute
It is used to penalize new tokens based on their existence in the text so far.
frequency_penalty: Optional[float] | str = None
class-attribute
instance-attribute
It is used to penalize new tokens based on their frequency in the text so far.
logit_bias: Optional[dict] | str = None
class-attribute
instance-attribute
Used to modify the probability of specific tokens appearing in the completion.
user: Optional[str] | str = None
class-attribute
instance-attribute
A unique identifier representing your end-user. This can help the LLM provider to monitor and detect abuse.
logprobs: Optional[bool] | str = None
class-attribute
instance-attribute
Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the content of message
top_logprobs: Optional[int] | str = None
class-attribute
instance-attribute
top_logprobs (int, optional): An integer between 0 and 5 specifying the number of most likely tokens to return at each token position, each with an associated log probability. logprobs must be set to true if this parameter is used.
extra_headers: Optional[dict] | str = None
class-attribute
instance-attribute
Additional headers to include in the request.
functions: Optional[list] | str = None
class-attribute
instance-attribute
A list of functions to apply to the conversation messages (default is an empty list)
function_call: Optional[str] | str = None
class-attribute
instance-attribute
The name of the function to call within the conversation (default is an empty string)
base_url: Optional[str] | str = environ.get('OPENAI_BASE_URL')
class-attribute
instance-attribute
Base URL for the API (default is None).
api_version: Optional[str] | str = None
class-attribute
instance-attribute
API version (default is None).
api_key: Optional[str] | str = None
class-attribute
instance-attribute
API key (default is None).
model_list: Optional[list] | str = None
class-attribute
instance-attribute
List of api base, version, keys.
mock_response: Optional[str] | str = None
class-attribute
instance-attribute
If provided, return a mock completion response for testing or debugging purposes (default is None).
custom_llm_provider: Optional[str] | str = None
class-attribute
instance-attribute
Used for Non-OpenAI LLMs, Example usage for bedrock, set model="amazon.titan-tg1-large" and custom_llm_provider="bedrock"
max_retries: Optional[int] | str = None
class-attribute
instance-attribute
The number of retries to attempt (default is 0).
ModelBlock
Bases: LeafBlock
Common fields for the model
blocks.
Attributes:
Name | Type | Description |
---|---|---|
input |
BlockType
|
Messages to send to the model. |
modelResponse |
OptionalStr
|
Variable where to store the raw response of the model. |
pdl__usage |
OptionalPdlUsage
|
Tokens consumed during model call |
Source code in src/pdl/pdl_ast.py
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 |
|
input: BlockType = '${ pdl_context }'
class-attribute
instance-attribute
Messages to send to the model.
modelResponse: OptionalStr = None
class-attribute
instance-attribute
Variable where to store the raw response of the model.
pdl__usage: OptionalPdlUsage = None
class-attribute
instance-attribute
Tokens consumed during model call
LitellmModelBlock
Bases: ModelBlock
Call an LLM through the LiteLLM API.
Example:
model: ollama/granite-code:8b
parameters:
stop: ['!']
Attributes:
Name | Type | Description |
---|---|---|
platform |
Literal[LITELLM]
|
Optional field to ensure that the block is using LiteLLM. |
model |
ExpressionStr
|
Name of the model following the LiteLLM convention. |
parameters |
Optional[LitellmParameters | ExpressionType[dict]]
|
Parameters to send to the model. |
structuredDecoding |
OptionalBool
|
Perform structured decoding if possible (i.e., |
Source code in src/pdl/pdl_ast.py
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 |
|
platform: Literal[ModelPlatform.LITELLM] = ModelPlatform.LITELLM
class-attribute
instance-attribute
Optional field to ensure that the block is using LiteLLM.
model: ExpressionStr
instance-attribute
Name of the model following the LiteLLM convention.
parameters: Optional[LitellmParameters | ExpressionType[dict]] = None
class-attribute
instance-attribute
Parameters to send to the model.
structuredDecoding: OptionalBool = True
class-attribute
instance-attribute
Perform structured decoding if possible (i.e., parser
and spec
are provided and the inference platform supports it).
GraniteioProcessor
Bases: BaseModel
Attributes:
Name | Type | Description |
---|---|---|
type |
OptionalExpressionStr
|
Type of IO processor. |
model |
OptionalExpressionStr
|
Model name used by the backend. |
backend |
ExpressionType[str | dict[str, Any] | object]
|
Backend object or name and configuration. |
Source code in src/pdl/pdl_ast.py
635 636 637 638 639 640 641 642 643 644 |
|
type: OptionalExpressionStr = None
class-attribute
instance-attribute
Type of IO processor.
model: OptionalExpressionStr = None
class-attribute
instance-attribute
Model name used by the backend.
backend: ExpressionType[str | dict[str, Any] | object]
instance-attribute
Backend object or name and configuration.
GraniteioModelBlock
Bases: ModelBlock
Call an LLM through the granite-io API.
Attributes:
Name | Type | Description |
---|---|---|
platform |
Literal[GRANITEIO]
|
Optional field to ensure that the block is using granite-io. |
processor |
GraniteioProcessor | ExpressionType[object]
|
IO Processor configuration or object. |
parameters |
Optional[ExpressionType[dict[str, Any]]]
|
Parameters sent to the model. |
Source code in src/pdl/pdl_ast.py
647 648 649 650 651 652 653 654 655 656 657 658 |
|
platform: Literal[ModelPlatform.GRANITEIO] = ModelPlatform.GRANITEIO
class-attribute
instance-attribute
Optional field to ensure that the block is using granite-io.
processor: GraniteioProcessor | ExpressionType[object]
instance-attribute
IO Processor configuration or object.
parameters: Optional[ExpressionType[dict[str, Any]]] = None
class-attribute
instance-attribute
Parameters sent to the model.
CodeBlock
Bases: BaseCodeBlock
Execute a piece of code.
Example:
lang: python
code: |
import random
# (In PDL, set `result` to the output you wish for your code block.)
result = random.randint(1, 20)
Attributes:
Name | Type | Description |
---|---|---|
lang |
Annotated[Literal['python', 'command', 'jinja', 'pdl', 'ipython'], BeforeValidator(_ensure_lower)]
|
Programming language of the code. |
code |
BlockType
|
Code to execute. |
Source code in src/pdl/pdl_ast.py
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 |
|
lang: Annotated[Literal['python', 'command', 'jinja', 'pdl', 'ipython'], BeforeValidator(_ensure_lower)]
instance-attribute
Programming language of the code.
code: BlockType
instance-attribute
Code to execute.
ArgsBlock
Bases: BaseCodeBlock
Execute a command line, which will spawn a subprocess with the given argument vector. Note: if you need a shell script execution, you must wrap your command line in /bin/sh or some shell of your choosing.
Example:
args:
- /bin/sh
- "-c"
- "if [[ $x = 1 ]]; then echo y; else echo n; fi"
Attributes:
Name | Type | Description |
---|---|---|
args |
list[ExpressionStr]
|
The argument vector to spawn. |
Source code in src/pdl/pdl_ast.py
690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 |
|
args: list[ExpressionStr]
instance-attribute
The argument vector to spawn.
GetBlock
Bases: LeafBlock
Get the value of a variable.
The GetBlock is deprecated. Use DataBlock instead.
Attributes:
Name | Type | Description |
---|---|---|
get |
str
|
Name of the variable to access. |
Source code in src/pdl/pdl_ast.py
709 710 711 712 713 714 715 716 717 718 |
|
get: str
instance-attribute
Name of the variable to access.
DataBlock
Bases: LeafBlock
Arbitrary value, equivalent to JSON.
Example. As part of a defs
section, set numbers
to the list [1, 2, 3, 4]
:
defs:
numbers:
data: [1, 2, 3, 4]
Example. Evaluate ${ TEST.answer }
in
Jinja, passing
the result to a regex parser with capture groups. Set
EXTRACTED_GROUND_TRUTH
to an object with attribute answer
,
a string, containing the value of the capture group.
- data: ${ TEST.answer }
parser:
regex: "(.|\n)*#### (?P<answer>([0-9])*)\n*"
spec:
answer: string
def: EXTRACTED_GROUND_TRUTH
Attributes:
Name | Type | Description |
---|---|---|
data |
ExpressionType[Any]
|
Value defined. |
raw |
bool
|
Do not evaluate expressions inside strings. |
Source code in src/pdl/pdl_ast.py
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 |
|
data: ExpressionType[Any]
instance-attribute
Value defined.
raw: bool = False
class-attribute
instance-attribute
Do not evaluate expressions inside strings.
TextBlock
Bases: StructuredBlock
Create the concatenation of the stringify version of the result of each block of the list of blocks.
Attributes:
Name | Type | Description |
---|---|---|
text |
BlockOrBlocksType
|
Body of the text. |
Source code in src/pdl/pdl_ast.py
754 755 756 757 758 759 760 |
|
text: BlockOrBlocksType
instance-attribute
Body of the text.
LastOfBlock
Bases: StructuredBlock
Return the value of the last block if the list of blocks.
Attributes:
Name | Type | Description |
---|---|---|
lastOf |
list[BlockType]
|
Sequence of blocks to execute. |
Source code in src/pdl/pdl_ast.py
763 764 765 766 767 768 |
|
lastOf: list[BlockType]
instance-attribute
Sequence of blocks to execute.
ArrayBlock
Bases: StructuredBlock
Return the array of values computed by each block of the list of blocks.
Attributes:
Name | Type | Description |
---|---|---|
array |
list[BlockType]
|
Elements of the array. |
Source code in src/pdl/pdl_ast.py
771 772 773 774 775 776 |
|
array: list[BlockType]
instance-attribute
Elements of the array.
ObjectBlock
Bases: StructuredBlock
Return the object where the value of each field is defined by a block. If the body of the object is an array, the resulting object is the union of the objects computed by each element of the array.
Source code in src/pdl/pdl_ast.py
779 780 781 782 783 |
|
MessageBlock
Bases: LeafBlock
Create a message.
Attributes:
Name | Type | Description |
---|---|---|
content |
BlockType
|
Content of the message. |
name |
OptionalExpressionStr
|
For example, the name of the tool that was invoked, for which this message is the tool response. |
tool_call_id |
OptionalExpressionStr
|
The id of the tool invocation for which this message is the tool response. |
Source code in src/pdl/pdl_ast.py
786 787 788 789 790 791 792 793 794 795 |
|
content: BlockType
instance-attribute
Content of the message.
name: OptionalExpressionStr = None
class-attribute
instance-attribute
For example, the name of the tool that was invoked, for which this message is the tool response.
tool_call_id: OptionalExpressionStr = None
class-attribute
instance-attribute
The id of the tool invocation for which this message is the tool response.
IfBlock
Bases: StructuredBlock
Conditional control structure.
Example:
defs:
answer:
read:
message: "Enter a number? "
if: ${ (answer | int) == 42 }
then: You won!
Attributes:
Name | Type | Description |
---|---|---|
condition |
ExpressionBool
|
Condition. |
then |
BlockType
|
Branch to execute if the condition is true. |
else_ |
OptionalBlockType
|
Branch to execute if the condition is false. |
Source code in src/pdl/pdl_ast.py
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 |
|
condition: ExpressionBool = Field(alias='if')
class-attribute
instance-attribute
Condition.
then: BlockType
instance-attribute
Branch to execute if the condition is true.
else_: OptionalBlockType = Field(default=None, alias='else')
class-attribute
instance-attribute
Branch to execute if the condition is false.
MatchCase
Bases: BaseModel
Case of a match.
Attributes:
Name | Type | Description |
---|---|---|
case |
Optional[PatternType]
|
Value to match. |
if_ |
OptionalExpressionBool
|
Boolean condition to satisfy. |
then |
BlockType
|
Branch to execute if the value is matched and the condition is satisfied. |
Source code in src/pdl/pdl_ast.py
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 |
|
case: Optional[PatternType] = None
class-attribute
instance-attribute
Value to match.
if_: OptionalExpressionBool = Field(default=None, alias='if')
class-attribute
instance-attribute
Boolean condition to satisfy.
then: BlockType
instance-attribute
Branch to execute if the value is matched and the condition is satisfied.
MatchBlock
Bases: StructuredBlock
Match control structure.
Example: ```PDL defs: answer: read: message: "Enter a number? " match: ${ (answer | int) } with: - case: 42 then: You won! - case: any: def: x if: ${ x > 42 } then: Too high - then: Too low
Attributes:
Name | Type | Description |
---|---|---|
match_ |
ExpressionType[Any]
|
Matched expression. |
with_ |
list[MatchCase]
|
List of cases to match. |
Source code in src/pdl/pdl_ast.py
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 |
|
match_: ExpressionType[Any] = Field(alias='match')
class-attribute
instance-attribute
Matched expression.
with_: list[MatchCase] = Field(alias='with')
class-attribute
instance-attribute
List of cases to match.
JoinConfig
Bases: BaseModel
Configure how loop iterations should be combined.
Source code in src/pdl/pdl_ast.py
874 875 876 877 878 879 |
|
JoinText
Bases: JoinConfig
Join loop iterations as a string.
Attributes:
Name | Type | Description |
---|---|---|
as_ |
Literal['text']
|
String concatenation of the result of each iteration. |
with_ |
str
|
String used to concatenate each iteration of the loop. |
Source code in src/pdl/pdl_ast.py
882 883 884 885 886 887 888 889 890 891 |
|
as_: Literal['text'] = Field(alias='as', default='text')
class-attribute
instance-attribute
String concatenation of the result of each iteration.
with_: str = Field(alias='with', default='')
class-attribute
instance-attribute
String used to concatenate each iteration of the loop.
JoinArray
Bases: JoinConfig
Join loop iterations as an array.
Attributes:
Name | Type | Description |
---|---|---|
as_ |
Literal['array']
|
Return the result of each iteration as an array. |
Source code in src/pdl/pdl_ast.py
894 895 896 897 898 899 |
|
as_: Literal['array'] = Field(alias='as')
class-attribute
instance-attribute
Return the result of each iteration as an array.
JoinObject
Bases: JoinConfig
Join loop iterations as an object.
Attributes:
Name | Type | Description |
---|---|---|
as_ |
Literal['object']
|
Return the union of the objects created at each iteration. |
Source code in src/pdl/pdl_ast.py
902 903 904 905 906 907 |
|
as_: Literal['object'] = Field(alias='as')
class-attribute
instance-attribute
Return the union of the objects created at each iteration.
JoinLastOf
Bases: JoinConfig
Join loop iterations as the value of the last iteration.
Attributes:
Name | Type | Description |
---|---|---|
as_ |
Literal['lastOf']
|
Return the result of the last iteration. |
Source code in src/pdl/pdl_ast.py
910 911 912 913 914 915 |
|
as_: Literal['lastOf'] = Field(alias='as')
class-attribute
instance-attribute
Return the result of the last iteration.
JoinReduce
Bases: JoinConfig
Join loop iterations as the value of the last iteration.
Attributes:
Name | Type | Description |
---|---|---|
reduce |
ExpressionType[Callable]
|
Function used to combine the results. |
Source code in src/pdl/pdl_ast.py
918 919 920 921 922 923 924 |
|
reduce: ExpressionType[Callable]
instance-attribute
Function used to combine the results.
RepeatBlock
Bases: StructuredBlock
Repeat the execution of a block sequentially.
The scope and pdl_context
are accumulated in between iterations.
For loop example:
for:
number: [1, 2, 3, 4]
name: ["Bob", "Carol", "David", "Ernest"]
repeat:
"${ name }'s number is ${ number }\n"
While loop:
defs:
i: 0
while: ${i < 5}
repeat:
defs:
i: ${ i + 1}
data: ${ i }
join:
as: array
Attributes:
Name | Type | Description |
---|---|---|
for_ |
Optional[dict[str, ExpressionType[list]]]
|
Arrays to iterate over. |
index |
OptionalStr
|
Name of the variable containing the loop iteration. |
while_ |
ExpressionBool
|
Condition to stay at the beginning of the loop. |
repeat |
BlockType
|
Body of the loop. |
until |
ExpressionBool
|
Condition to exit at the end of the loop. |
maxIterations |
OptionalExpressionInt
|
Maximal number of iterations to perform. |
join |
JoinType
|
Define how to combine the result of each iteration. |
Source code in src/pdl/pdl_ast.py
933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 |
|
for_: Optional[dict[str, ExpressionType[list]]] = Field(default=None, alias='for')
class-attribute
instance-attribute
Arrays to iterate over.
index: OptionalStr = None
class-attribute
instance-attribute
Name of the variable containing the loop iteration.
while_: ExpressionBool = Field(default=True, alias='while')
class-attribute
instance-attribute
Condition to stay at the beginning of the loop.
repeat: BlockType
instance-attribute
Body of the loop.
until: ExpressionBool = False
class-attribute
instance-attribute
Condition to exit at the end of the loop.
maxIterations: OptionalExpressionInt = None
class-attribute
instance-attribute
Maximal number of iterations to perform.
join: JoinType = JoinText()
class-attribute
instance-attribute
Define how to combine the result of each iteration.
MapBlock
Bases: StructuredBlock
Independent executions of a block.
Repeat the execution of a block starting from the initial scope
and pdl_context
.
For loop example:
for:
number: [1, 2, 3, 4]
name: ["Bob", "Carol", "David", "Ernest"]
map:
"${ name }'s number is ${ number }\n"
Bounded loop:
index: i
maxIterations: 5
map:
${ i }
join:
as: array
Attributes:
Name | Type | Description |
---|---|---|
for_ |
Optional[dict[str, ExpressionType[list]]]
|
Arrays to iterate over. |
index |
OptionalStr
|
Name of the variable containing the loop iteration. |
map |
BlockType
|
Body of the iterator. |
maxIterations |
OptionalExpressionInt
|
Maximal number of iterations to perform. |
join |
JoinType
|
Define how to combine the result of each iteration. |
maxWorkers |
OptionalInt
|
Maximal number of workers to execute the map in parallel. Is it is set to |
Source code in src/pdl/pdl_ast.py
987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 |
|
for_: Optional[dict[str, ExpressionType[list]]] = Field(default=None, alias='for')
class-attribute
instance-attribute
Arrays to iterate over.
index: OptionalStr = None
class-attribute
instance-attribute
Name of the variable containing the loop iteration.
map: BlockType
instance-attribute
Body of the iterator.
maxIterations: OptionalExpressionInt = None
class-attribute
instance-attribute
Maximal number of iterations to perform.
join: JoinType = JoinText()
class-attribute
instance-attribute
Define how to combine the result of each iteration.
maxWorkers: OptionalInt = None
class-attribute
instance-attribute
Maximal number of workers to execute the map in parallel. Is it is set to 0
, the execution is sequential otherwise it is given as argument to the ThreadPoolExecutor
.
ReadBlock
Bases: LeafBlock
Read from a file or standard input.
Example. Read from the standard input with a prompt starting with >
.
read:
message: "> "
Example. Read the file ./data.yaml
in the same directory of the PDL file containing the block and parse it into YAML.
read: ./data.yaml
parser: yaml
Attributes:
Name | Type | Description |
---|---|---|
read |
OptionalExpressionStr
|
Name of the file to read. If |
message |
OptionalStr
|
Message to prompt the user to enter a value. |
multiline |
bool
|
Indicate if one or multiple lines should be read. |
Source code in src/pdl/pdl_ast.py
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 |
|
read: OptionalExpressionStr
instance-attribute
Name of the file to read. If None
, read the standard input.
message: OptionalStr = None
class-attribute
instance-attribute
Message to prompt the user to enter a value.
multiline: bool = False
class-attribute
instance-attribute
Indicate if one or multiple lines should be read.
IncludeBlock
Bases: StructuredBlock
Include a PDL file.
Attributes:
Name | Type | Description |
---|---|---|
include |
str
|
Name of the file to include. |
Source code in src/pdl/pdl_ast.py
1064 1065 1066 1067 1068 1069 1070 1071 1072 |
|
include: str
instance-attribute
Name of the file to include.
ImportBlock
Bases: LeafBlock
Import a PDL file.
Attributes:
Name | Type | Description |
---|---|---|
import_ |
str
|
Name of the file to import. |
Source code in src/pdl/pdl_ast.py
1075 1076 1077 1078 1079 1080 1081 1082 1083 |
|
import_: str = Field(alias='import')
class-attribute
instance-attribute
Name of the file to import.
AggregatorConfig
Bases: BaseModel
Common fields for all aggregator configurations.
Attributes:
Name | Type | Description |
---|---|---|
description |
Optional[str]
|
Documentation associated to the aggregator config. |
Source code in src/pdl/pdl_ast.py
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 |
|
description: Optional[str] = None
class-attribute
instance-attribute
Documentation associated to the aggregator config.
FileAggregatorConfig
Bases: AggregatorConfig
Attributes:
Name | Type | Description |
---|---|---|
file |
ExpressionType[str]
|
Name of the file to which contribute. |
mode |
ExpressionType[str]
|
File opening mode. |
encoding |
ExpressionType[Optional[str]]
|
File encoding. |
prefix |
ExpressionType[str]
|
Prefix to the contributed value. |
suffix |
ExpressionType[str]
|
Suffix to the contributed value. |
flush |
ExpressionType[bool]
|
Whether to forcibly flush the stream. |
Source code in src/pdl/pdl_ast.py
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 |
|
file: ExpressionType[str]
instance-attribute
Name of the file to which contribute.
mode: ExpressionType[str] = 'w'
class-attribute
instance-attribute
File opening mode.
encoding: ExpressionType[Optional[str]] = 'utf-8'
class-attribute
instance-attribute
File encoding.
prefix: ExpressionType[str] = ''
class-attribute
instance-attribute
Prefix to the contributed value.
suffix: ExpressionType[str] = '\n'
class-attribute
instance-attribute
Suffix to the contributed value.
flush: ExpressionType[bool] = False
class-attribute
instance-attribute
Whether to forcibly flush the stream.
AggregatorBlock
Bases: LeafBlock
Create a new aggregator that can be use in the contribute
field.
Source code in src/pdl/pdl_ast.py
1118 1119 1120 1121 1122 |
|
ErrorBlock
Bases: LeafBlock
Block representing an error generated at runtime.
Attributes:
Name | Type | Description |
---|---|---|
msg |
str
|
Error message. |
program |
BlockType
|
Block that raised the error. |
Source code in src/pdl/pdl_ast.py
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 |
|
msg: str
instance-attribute
Error message.
program: BlockType
instance-attribute
Block that raised the error.
EmptyBlock
Bases: LeafBlock
Block without an action. It can contain definitions.
Source code in src/pdl/pdl_ast.py
1137 1138 1139 1140 |
|
Program
Bases: RootModel
Prompt Declaration Language program (PDL)
Attributes:
Name | Type | Description |
---|---|---|
root |
BlockType
|
Entry point to parse a PDL program using Pydantic. |
Source code in src/pdl/pdl_ast.py
1180 1181 1182 1183 1184 1185 1186 1187 |
|
root: BlockType
instance-attribute
Entry point to parse a PDL program using Pydantic.
get_default_model_parameters() -> list[dict[str, Any]]
Model-specific defaults to apply
Source code in src/pdl/pdl_ast.py
1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 |
|
get_sampling_defaults() -> list[dict[str, Any]]
Model-specific defaults to apply if we are sampling.
Source code in src/pdl/pdl_ast.py
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 |
|
Interpreter
Classes:
Name | Description |
---|---|
InterpreterConfig |
Configuration parameters of the PDL interpreter. |
Functions:
Name | Description |
---|---|
exec_program |
Execute a PDL program given as a value of type |
exec_dict |
Execute a PDL program given as a dictionary. |
exec_str |
Execute a PDL program given as YAML string. |
exec_file |
Execute a PDL program given as YAML file. |
InterpreterConfig
Bases: TypedDict
Configuration parameters of the PDL interpreter.
Attributes:
Name | Type | Description |
---|---|---|
yield_result |
bool
|
Print incrementally result of the execution. |
yield_background |
bool
|
Print the program background messages during the execution. |
batch |
int
|
Model inference mode: |
role |
RoleType
|
Default role. |
cwd |
Path
|
Path considered as the current working directory for file reading. |
replay |
dict[str, Any]
|
Execute the program reusing some already computed values. |
event_loop |
AbstractEventLoop
|
Event loop to schedule LLM calls. |
Source code in src/pdl/pdl.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
yield_result: bool
instance-attribute
Print incrementally result of the execution.
yield_background: bool
instance-attribute
Print the program background messages during the execution.
batch: int
instance-attribute
Model inference mode: - 0: streaming - 1: non-streaming
role: RoleType
instance-attribute
Default role.
cwd: Path
instance-attribute
Path considered as the current working directory for file reading.
replay: dict[str, Any]
instance-attribute
Execute the program reusing some already computed values.
event_loop: AbstractEventLoop
instance-attribute
Event loop to schedule LLM calls.
exec_program(prog: Program, config: Optional[InterpreterConfig] = None, scope: Optional[ScopeType | dict[str, Any]] = None, loc: Optional[PdlLocationType] = None, output: Literal['result', 'all'] = 'result') -> Any
Execute a PDL program given as a value of type pdl.pdl_ast.Program
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prog
|
Program
|
Program to execute. |
required |
config
|
Optional[InterpreterConfig]
|
Interpreter configuration. Defaults to None. |
None
|
scope
|
Optional[ScopeType | dict[str, Any]]
|
Environment defining the initial variables in scope to execute the program. Defaults to None. |
None
|
loc
|
Optional[PdlLocationType]
|
Source code location mapping. Defaults to None. |
None
|
output
|
Literal['result', 'all']
|
Configure the output of the returned value of this function. Defaults to |
'result'
|
Returns:
Type | Description |
---|---|
Any
|
Return the final result if |
Source code in src/pdl/pdl.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
exec_dict(prog: dict[str, Any], config: Optional[InterpreterConfig] = None, scope: Optional[ScopeType | dict[str, Any]] = None, loc: Optional[PdlLocationType] = None, output: Literal['result', 'all'] = 'result') -> Any
Execute a PDL program given as a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prog
|
dict[str, Any]
|
Program to execute. |
required |
config
|
Optional[InterpreterConfig]
|
Interpreter configuration. Defaults to None. |
None
|
scope
|
Optional[ScopeType | dict[str, Any]]
|
Environment defining the initial variables in scope to execute the program. Defaults to None. |
None
|
loc
|
Optional[PdlLocationType]
|
Source code location mapping. Defaults to None. |
None
|
output
|
Literal['result', 'all']
|
Configure the output of the returned value of this function. Defaults to |
'result'
|
Returns:
Type | Description |
---|---|
Any
|
Return the final result. |
Source code in src/pdl/pdl.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
exec_str(prog: str, config: Optional[InterpreterConfig] = None, scope: Optional[ScopeType | dict[str, Any]] = None, output: Literal['result', 'all'] = 'result') -> Any
Execute a PDL program given as YAML string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prog
|
str
|
Program to execute. |
required |
config
|
Optional[InterpreterConfig]
|
Interpreter configuration. Defaults to None. |
None
|
scope
|
Optional[ScopeType | dict[str, Any]]
|
Environment defining the initial variables in scope to execute the program. Defaults to None. |
None
|
output
|
Literal['result', 'all']
|
Configure the output of the returned value of this function. Defaults to |
'result'
|
Returns:
Type | Description |
---|---|
Any
|
Return the final result. |
Source code in src/pdl/pdl.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
exec_file(prog: str | Path, config: Optional[InterpreterConfig] = None, scope: Optional[ScopeType | dict[str, Any]] = None, output: Literal['result', 'all'] = 'result') -> Any
Execute a PDL program given as YAML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prog
|
str | Path
|
Program to execute. |
required |
config
|
Optional[InterpreterConfig]
|
Interpreter configuration. Defaults to None. |
None
|
scope
|
Optional[ScopeType | dict[str, Any]]
|
Environment defining the initial variables in scope to execute the program. Defaults to None. |
None
|
output
|
Literal['result', 'all']
|
Configure the output of the returned value of this function. Defaults to |
'result'
|
Returns:
Type | Description |
---|---|
Any
|
Return the final result. |
Source code in src/pdl/pdl.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
|