diff --git a/pdl-live-react/src/pdl_ast.d.ts b/pdl-live-react/src/pdl_ast.d.ts index ae9a0a4a4..cee63e818 100644 --- a/pdl-live-react/src/pdl_ast.d.ts +++ b/pdl-live-react/src/pdl_ast.d.ts @@ -259,6 +259,16 @@ export type Fallback = | ErrorBlock | EmptyBlock | null +/** + * The maximum number of times to retry when an error occurs within a block. + * + */ +export type Retry = number | null +/** + * Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials. + * + */ +export type TraceErrorOnRetry = boolean | string | null /** * Role associated to the block and sub-blocks. * Typical roles are `system`, `user`, and `assistant`, @@ -338,6 +348,16 @@ export type Fallback1 = | ErrorBlock | EmptyBlock | null +/** + * The maximum number of times to retry when an error occurs within a block. + * + */ +export type Retry1 = number | null +/** + * Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials. + * + */ +export type TraceErrorOnRetry1 = boolean | string | null /** * Role associated to the block and sub-blocks. * Typical roles are `system`, `user`, and `assistant`, @@ -448,6 +468,16 @@ export type Fallback2 = | ErrorBlock | EmptyBlock | null +/** + * The maximum number of times to retry when an error occurs within a block. + * + */ +export type Retry2 = number | null +/** + * Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials. + * + */ +export type TraceErrorOnRetry2 = boolean | string | null /** * Role associated to the block and sub-blocks. * Typical roles are `system`, `user`, and `assistant`, @@ -554,6 +584,16 @@ export type Fallback3 = | ErrorBlock | EmptyBlock | null +/** + * The maximum number of times to retry when an error occurs within a block. + * + */ +export type Retry3 = number | null +/** + * Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials. + * + */ +export type TraceErrorOnRetry3 = boolean | string | null /** * Role associated to the block and sub-blocks. * Typical roles are `system`, `user`, and `assistant`, @@ -661,6 +701,16 @@ export type Fallback4 = | ErrorBlock | EmptyBlock | null +/** + * The maximum number of times to retry when an error occurs within a block. + * + */ +export type Retry4 = number | null +/** + * Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials. + * + */ +export type TraceErrorOnRetry4 = boolean | string | null /** * Role associated to the block and sub-blocks. * Typical roles are `system`, `user`, and `assistant`, @@ -751,6 +801,16 @@ export type Fallback5 = | ErrorBlock | EmptyBlock | null +/** + * The maximum number of times to retry when an error occurs within a block. + * + */ +export type Retry5 = number | null +/** + * Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials. + * + */ +export type TraceErrorOnRetry5 = boolean | string | null /** * Role associated to the block and sub-blocks. * Typical roles are `system`, `user`, and `assistant`, @@ -863,6 +923,16 @@ export type Fallback6 = | ErrorBlock | EmptyBlock | null +/** + * The maximum number of times to retry when an error occurs within a block. + * + */ +export type Retry6 = number | null +/** + * Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials. + * + */ +export type TraceErrorOnRetry6 = boolean | string | null /** * Role associated to the block and sub-blocks. * Typical roles are `system`, `user`, and `assistant`, @@ -995,6 +1065,16 @@ export type Fallback7 = | ErrorBlock | EmptyBlock | null +/** + * The maximum number of times to retry when an error occurs within a block. + * + */ +export type Retry7 = number | null +/** + * Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials. + * + */ +export type TraceErrorOnRetry7 = boolean | string | null /** * Role associated to the block and sub-blocks. * Typical roles are `system`, `user`, and `assistant`, @@ -1101,6 +1181,16 @@ export type Fallback8 = | ErrorBlock | EmptyBlock | null +/** + * The maximum number of times to retry when an error occurs within a block. + * + */ +export type Retry8 = number | null +/** + * Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials. + * + */ +export type TraceErrorOnRetry8 = boolean | string | null /** * Role associated to the block and sub-blocks. * Typical roles are `system`, `user`, and `assistant`, @@ -1207,6 +1297,16 @@ export type Fallback9 = | ErrorBlock | EmptyBlock | null +/** + * The maximum number of times to retry when an error occurs within a block. + * + */ +export type Retry9 = number | null +/** + * Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials. + * + */ +export type TraceErrorOnRetry9 = boolean | string | null /** * Role associated to the block and sub-blocks. * Typical roles are `system`, `user`, and `assistant`, @@ -1340,6 +1440,16 @@ export type Fallback10 = | ErrorBlock | EmptyBlock | null +/** + * The maximum number of times to retry when an error occurs within a block. + * + */ +export type Retry10 = number | null +/** + * Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials. + * + */ +export type TraceErrorOnRetry10 = boolean | string | null /** * Role associated to the block and sub-blocks. * Typical roles are `system`, `user`, and `assistant`, @@ -1527,6 +1637,16 @@ export type Fallback11 = | ErrorBlock | EmptyBlock | null +/** + * The maximum number of times to retry when an error occurs within a block. + * + */ +export type Retry11 = number | null +/** + * Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials. + * + */ +export type TraceErrorOnRetry11 = boolean | string | null /** * Role associated to the block and sub-blocks. * Typical roles are `system`, `user`, and `assistant`, @@ -1672,6 +1792,16 @@ export type Fallback12 = | ErrorBlock | EmptyBlock | null +/** + * The maximum number of times to retry when an error occurs within a block. + * + */ +export type Retry12 = number | null +/** + * Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials. + * + */ +export type TraceErrorOnRetry12 = boolean | string | null /** * Role associated to the block and sub-blocks. * Typical roles are `system`, `user`, and `assistant`, @@ -1814,6 +1944,16 @@ export type Fallback13 = | ErrorBlock | EmptyBlock | null +/** + * The maximum number of times to retry when an error occurs within a block. + * + */ +export type Retry13 = number | null +/** + * Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials. + * + */ +export type TraceErrorOnRetry13 = boolean | string | null /** * Role associated to the block and sub-blocks. * Typical roles are `system`, `user`, and `assistant`, @@ -1893,6 +2033,16 @@ export type Fallback14 = | ErrorBlock | EmptyBlock | null +/** + * The maximum number of times to retry when an error occurs within a block. + * + */ +export type Retry14 = number | null +/** + * Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials. + * + */ +export type TraceErrorOnRetry14 = boolean | string | null /** * Role associated to the block and sub-blocks. * Typical roles are `system`, `user`, and `assistant`, @@ -1972,6 +2122,16 @@ export type Fallback15 = | ErrorBlock | EmptyBlock | null +/** + * The maximum number of times to retry when an error occurs within a block. + * + */ +export type Retry15 = number | null +/** + * Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials. + * + */ +export type TraceErrorOnRetry15 = boolean | string | null /** * Role associated to the block and sub-blocks. * Typical roles are `system`, `user`, and `assistant`, @@ -2053,6 +2213,16 @@ export type Fallback16 = | ErrorBlock | EmptyBlock | null +/** + * The maximum number of times to retry when an error occurs within a block. + * + */ +export type Retry16 = number | null +/** + * Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials. + * + */ +export type TraceErrorOnRetry16 = boolean | string | null /** * Role associated to the block and sub-blocks. * Typical roles are `system`, `user`, and `assistant`, @@ -2163,6 +2333,16 @@ export type Fallback17 = | ErrorBlock | EmptyBlock | null +/** + * The maximum number of times to retry when an error occurs within a block. + * + */ +export type Retry17 = number | null +/** + * Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials. + * + */ +export type TraceErrorOnRetry17 = boolean | string | null /** * Role associated to the block and sub-blocks. * Typical roles are `system`, `user`, and `assistant`, @@ -2311,6 +2491,16 @@ export type Fallback18 = | ErrorBlock | EmptyBlock | null +/** + * The maximum number of times to retry when an error occurs within a block. + * + */ +export type Retry18 = number | null +/** + * Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials. + * + */ +export type TraceErrorOnRetry18 = boolean | string | null /** * Role associated to the block and sub-blocks. * Typical roles are `system`, `user`, and `assistant`, @@ -2495,6 +2685,16 @@ export type Fallback19 = | ErrorBlock | EmptyBlock | null +/** + * The maximum number of times to retry when an error occurs within a block. + * + */ +export type Retry19 = number | null +/** + * Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials. + * + */ +export type TraceErrorOnRetry19 = boolean | string | null /** * Role associated to the block and sub-blocks. * Typical roles are `system`, `user`, and `assistant`, @@ -2596,6 +2796,16 @@ export type Fallback20 = | ErrorBlock | EmptyBlock | null +/** + * The maximum number of times to retry when an error occurs within a block. + * + */ +export type Retry20 = number | null +/** + * Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials. + * + */ +export type TraceErrorOnRetry20 = boolean | string | null /** * Role associated to the block and sub-blocks. * Typical roles are `system`, `user`, and `assistant`, @@ -2697,6 +2907,8 @@ export interface FunctionBlock { contribute?: Contribute20 parser?: Parser20 fallback?: Fallback20 + retry?: Retry20 + trace_error_on_retry?: TraceErrorOnRetry20 role?: Role20 pdl__context?: PdlContext20 pdl__id?: PdlId20 @@ -2832,6 +3044,8 @@ export interface CallBlock { contribute?: Contribute19 parser?: Parser19 fallback?: Fallback19 + retry?: Retry19 + trace_error_on_retry?: TraceErrorOnRetry19 role?: Role19 pdl__context?: PdlContext19 pdl__id?: PdlId19 @@ -2898,6 +3112,8 @@ export interface LitellmModelBlock { contribute?: Contribute18 parser?: Parser18 fallback?: Fallback18 + retry?: Retry18 + trace_error_on_retry?: TraceErrorOnRetry18 role?: Role18 pdl__context?: PdlContext18 pdl__id?: PdlId18 @@ -2965,6 +3181,8 @@ export interface GraniteioModelBlock { contribute?: Contribute17 parser?: Parser17 fallback?: Fallback17 + retry?: Retry17 + trace_error_on_retry?: TraceErrorOnRetry17 role?: Role17 pdl__context?: PdlContext17 pdl__id?: PdlId17 @@ -3043,6 +3261,8 @@ export interface CodeBlock { contribute?: Contribute16 parser?: Parser16 fallback?: Fallback16 + retry?: Retry16 + trace_error_on_retry?: TraceErrorOnRetry16 role?: Role16 pdl__context?: PdlContext16 pdl__id?: PdlId16 @@ -3109,6 +3329,8 @@ export interface ArgsBlock { contribute?: Contribute15 parser?: Parser15 fallback?: Fallback15 + retry?: Retry15 + trace_error_on_retry?: TraceErrorOnRetry15 role?: Role15 pdl__context?: PdlContext15 pdl__id?: PdlId15 @@ -3169,6 +3391,8 @@ export interface GetBlock { contribute?: Contribute14 parser?: Parser14 fallback?: Fallback14 + retry?: Retry14 + trace_error_on_retry?: TraceErrorOnRetry14 role?: Role14 pdl__context?: PdlContext14 pdl__id?: PdlId14 @@ -3247,6 +3471,8 @@ export interface DataBlock { contribute?: Contribute13 parser?: Parser13 fallback?: Fallback13 + retry?: Retry13 + trace_error_on_retry?: TraceErrorOnRetry13 role?: Role13 pdl__context?: PdlContext13 pdl__id?: PdlId13 @@ -3315,6 +3541,8 @@ export interface IfBlock { contribute?: Contribute12 parser?: Parser12 fallback?: Fallback12 + retry?: Retry12 + trace_error_on_retry?: TraceErrorOnRetry12 role?: Role12 pdl__context?: PdlContext12 pdl__id?: PdlId12 @@ -3393,6 +3621,8 @@ export interface MatchBlock { contribute?: Contribute11 parser?: Parser11 fallback?: Fallback11 + retry?: Retry11 + trace_error_on_retry?: TraceErrorOnRetry11 role?: Role11 pdl__context?: PdlContext11 pdl__id?: PdlId11 @@ -3461,6 +3691,8 @@ export interface RepeatBlock { contribute?: Contribute10 parser?: Parser10 fallback?: Fallback10 + retry?: Retry10 + trace_error_on_retry?: TraceErrorOnRetry10 role?: Role10 pdl__context?: PdlContext10 pdl__id?: PdlId10 @@ -3525,6 +3757,8 @@ export interface TextBlock { contribute?: Contribute9 parser?: Parser9 fallback?: Fallback9 + retry?: Retry9 + trace_error_on_retry?: TraceErrorOnRetry9 role?: Role9 pdl__context?: PdlContext9 pdl__id?: PdlId9 @@ -3583,6 +3817,8 @@ export interface LastOfBlock { contribute?: Contribute8 parser?: Parser8 fallback?: Fallback8 + retry?: Retry8 + trace_error_on_retry?: TraceErrorOnRetry8 role?: Role8 pdl__context?: PdlContext8 pdl__id?: PdlId8 @@ -3641,6 +3877,8 @@ export interface ArrayBlock { contribute?: Contribute7 parser?: Parser7 fallback?: Fallback7 + retry?: Retry7 + trace_error_on_retry?: TraceErrorOnRetry7 role?: Role7 pdl__context?: PdlContext7 pdl__id?: PdlId7 @@ -3699,6 +3937,8 @@ export interface ObjectBlock { contribute?: Contribute6 parser?: Parser6 fallback?: Fallback6 + retry?: Retry6 + trace_error_on_retry?: TraceErrorOnRetry6 role?: Role6 pdl__context?: PdlContext6 pdl__id?: PdlId6 @@ -3757,6 +3997,8 @@ export interface MessageBlock { contribute?: Contribute5 parser?: Parser5 fallback?: Fallback5 + retry?: Retry5 + trace_error_on_retry?: TraceErrorOnRetry5 role?: Role5 pdl__context?: PdlContext5 pdl__id?: PdlId5 @@ -3828,6 +4070,8 @@ export interface ReadBlock { contribute?: Contribute4 parser?: Parser4 fallback?: Fallback4 + retry?: Retry4 + trace_error_on_retry?: TraceErrorOnRetry4 role?: Role4 pdl__context?: PdlContext4 pdl__id?: PdlId4 @@ -3887,6 +4131,8 @@ export interface IncludeBlock { contribute?: Contribute3 parser?: Parser3 fallback?: Fallback3 + retry?: Retry3 + trace_error_on_retry?: TraceErrorOnRetry3 role?: Role3 pdl__context?: PdlContext3 pdl__id?: PdlId3 @@ -3946,6 +4192,8 @@ export interface ImportBlock { contribute?: Contribute2 parser?: Parser2 fallback?: Fallback2 + retry?: Retry2 + trace_error_on_retry?: TraceErrorOnRetry2 role?: Role2 pdl__context?: PdlContext2 pdl__id?: PdlId2 @@ -4004,6 +4252,8 @@ export interface ErrorBlock { contribute?: Contribute1 parser?: Parser1 fallback?: Fallback1 + retry?: Retry1 + trace_error_on_retry?: TraceErrorOnRetry1 role?: Role1 pdl__context?: PdlContext1 pdl__id?: PdlId1 @@ -4062,6 +4312,8 @@ export interface EmptyBlock { contribute?: Contribute parser?: Parser fallback?: Fallback + retry?: Retry + trace_error_on_retry?: TraceErrorOnRetry role?: Role pdl__context?: PdlContext pdl__id?: PdlId diff --git a/src/pdl/pdl-schema.json b/src/pdl/pdl-schema.json index f3c9ccbd4..f2fffef55 100644 --- a/src/pdl/pdl-schema.json +++ b/src/pdl/pdl-schema.json @@ -288,6 +288,35 @@ "description": "Block to execute in case of error.\n ", "title": "Fallback" }, + "retry": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The maximum number of times to retry when an error occurs within a block.\n ", + "title": "Retry" + }, + "trace_error_on_retry": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n ", + "title": "Trace Error On Retry" + }, "role": { "anyOf": [ { @@ -665,6 +694,35 @@ "description": "Block to execute in case of error.\n ", "title": "Fallback" }, + "retry": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The maximum number of times to retry when an error occurs within a block.\n ", + "title": "Retry" + }, + "trace_error_on_retry": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n ", + "title": "Trace Error On Retry" + }, "role": { "anyOf": [ { @@ -1169,6 +1227,35 @@ "description": "Block to execute in case of error.\n ", "title": "Fallback" }, + "retry": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The maximum number of times to retry when an error occurs within a block.\n ", + "title": "Retry" + }, + "trace_error_on_retry": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n ", + "title": "Trace Error On Retry" + }, "role": { "anyOf": [ { @@ -1636,6 +1723,35 @@ "description": "Block to execute in case of error.\n ", "title": "Fallback" }, + "retry": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The maximum number of times to retry when an error occurs within a block.\n ", + "title": "Retry" + }, + "trace_error_on_retry": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n ", + "title": "Trace Error On Retry" + }, "role": { "anyOf": [ { @@ -2122,6 +2238,35 @@ "description": "Block to execute in case of error.\n ", "title": "Fallback" }, + "retry": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The maximum number of times to retry when an error occurs within a block.\n ", + "title": "Retry" + }, + "trace_error_on_retry": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n ", + "title": "Trace Error On Retry" + }, "role": { "anyOf": [ { @@ -2497,6 +2642,35 @@ "description": "Block to execute in case of error.\n ", "title": "Fallback" }, + "retry": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The maximum number of times to retry when an error occurs within a block.\n ", + "title": "Retry" + }, + "trace_error_on_retry": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n ", + "title": "Trace Error On Retry" + }, "role": { "anyOf": [ { @@ -2866,6 +3040,35 @@ "description": "Block to execute in case of error.\n ", "title": "Fallback" }, + "retry": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The maximum number of times to retry when an error occurs within a block.\n ", + "title": "Retry" + }, + "trace_error_on_retry": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n ", + "title": "Trace Error On Retry" + }, "role": { "anyOf": [ { @@ -3401,6 +3604,35 @@ "description": "Block to execute in case of error.\n ", "title": "Fallback" }, + "retry": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The maximum number of times to retry when an error occurs within a block.\n ", + "title": "Retry" + }, + "trace_error_on_retry": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n ", + "title": "Trace Error On Retry" + }, "role": { "anyOf": [ { @@ -3857,6 +4089,35 @@ "description": "Block to execute in case of error.\n ", "title": "Fallback" }, + "retry": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The maximum number of times to retry when an error occurs within a block.\n ", + "title": "Retry" + }, + "trace_error_on_retry": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n ", + "title": "Trace Error On Retry" + }, "role": { "anyOf": [ { @@ -4218,6 +4479,35 @@ "description": "Block to execute in case of error.\n ", "title": "Fallback" }, + "retry": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The maximum number of times to retry when an error occurs within a block.\n ", + "title": "Retry" + }, + "trace_error_on_retry": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n ", + "title": "Trace Error On Retry" + }, "role": { "anyOf": [ { @@ -4773,6 +5063,35 @@ "description": "Block to execute in case of error.\n ", "title": "Fallback" }, + "retry": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The maximum number of times to retry when an error occurs within a block.\n ", + "title": "Retry" + }, + "trace_error_on_retry": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n ", + "title": "Trace Error On Retry" + }, "role": { "anyOf": [ { @@ -5330,6 +5649,35 @@ "description": "Block to execute in case of error.\n ", "title": "Fallback" }, + "retry": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The maximum number of times to retry when an error occurs within a block.\n ", + "title": "Retry" + }, + "trace_error_on_retry": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n ", + "title": "Trace Error On Retry" + }, "role": { "anyOf": [ { @@ -5775,6 +6123,35 @@ "description": "Block to execute in case of error.\n ", "title": "Fallback" }, + "retry": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The maximum number of times to retry when an error occurs within a block.\n ", + "title": "Retry" + }, + "trace_error_on_retry": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n ", + "title": "Trace Error On Retry" + }, "role": { "anyOf": [ { @@ -6377,6 +6754,35 @@ "description": "Block to execute in case of error.\n ", "title": "Fallback" }, + "retry": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The maximum number of times to retry when an error occurs within a block.\n ", + "title": "Retry" + }, + "trace_error_on_retry": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n ", + "title": "Trace Error On Retry" + }, "role": { "anyOf": [ { @@ -6878,6 +7284,35 @@ "description": "Block to execute in case of error.\n ", "title": "Fallback" }, + "retry": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The maximum number of times to retry when an error occurs within a block.\n ", + "title": "Retry" + }, + "trace_error_on_retry": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n ", + "title": "Trace Error On Retry" + }, "role": { "anyOf": [ { @@ -7838,6 +8273,35 @@ "description": "Block to execute in case of error.\n ", "title": "Fallback" }, + "retry": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The maximum number of times to retry when an error occurs within a block.\n ", + "title": "Retry" + }, + "trace_error_on_retry": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n ", + "title": "Trace Error On Retry" + }, "role": { "anyOf": [ { @@ -8401,6 +8865,35 @@ "description": "Block to execute in case of error.\n ", "title": "Fallback" }, + "retry": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The maximum number of times to retry when an error occurs within a block.\n ", + "title": "Retry" + }, + "trace_error_on_retry": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n ", + "title": "Trace Error On Retry" + }, "role": { "anyOf": [ { @@ -8898,6 +9391,35 @@ "description": "Block to execute in case of error.\n ", "title": "Fallback" }, + "retry": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The maximum number of times to retry when an error occurs within a block.\n ", + "title": "Retry" + }, + "trace_error_on_retry": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n ", + "title": "Trace Error On Retry" + }, "role": { "anyOf": [ { @@ -10011,6 +10533,35 @@ "description": "Block to execute in case of error.\n ", "title": "Fallback" }, + "retry": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The maximum number of times to retry when an error occurs within a block.\n ", + "title": "Retry" + }, + "trace_error_on_retry": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n ", + "title": "Trace Error On Retry" + }, "role": { "anyOf": [ { @@ -10451,6 +11002,35 @@ "description": "Block to execute in case of error.\n ", "title": "Fallback" }, + "retry": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The maximum number of times to retry when an error occurs within a block.\n ", + "title": "Retry" + }, + "trace_error_on_retry": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n ", + "title": "Trace Error On Retry" + }, "role": { "anyOf": [ { @@ -11154,6 +11734,35 @@ "description": "Block to execute in case of error.\n ", "title": "Fallback" }, + "retry": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The maximum number of times to retry when an error occurs within a block.\n ", + "title": "Retry" + }, + "trace_error_on_retry": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n ", + "title": "Trace Error On Retry" + }, "role": { "anyOf": [ { diff --git a/src/pdl/pdl_ast.py b/src/pdl/pdl_ast.py index 6f4f81080..7b155ac5a 100644 --- a/src/pdl/pdl_ast.py +++ b/src/pdl/pdl_ast.py @@ -360,6 +360,12 @@ class Block(BaseModel): fallback: Optional["BlockType"] = None """Block to execute in case of error. """ + retry: Optional[int] = None + """The maximum number of times to retry when an error occurs within a block. + """ + trace_error_on_retry: Optional[bool] | str = None + """Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials. + """ role: RoleType = None """Role associated to the block and sub-blocks. Typical roles are `system`, `user`, and `assistant`, diff --git a/src/pdl/pdl_dumper.py b/src/pdl/pdl_dumper.py index c577ad6ff..dae3c1268 100644 --- a/src/pdl/pdl_dumper.py +++ b/src/pdl/pdl_dumper.py @@ -124,6 +124,12 @@ def block_to_dict( # noqa: C901 d["defs"] = { x: block_to_dict(b, json_compatible) for x, b in block.defs.items() } + if block.retry is not None: + d["retry"] = expr_to_dict(block.retry, json_compatible) + if block.trace_error_on_retry is not None: + d["trace_error_on_retry"] = expr_to_dict( + block.trace_error_on_retry, json_compatible + ) if isinstance(block, StructuredBlock): d["context"] = block.context diff --git a/src/pdl/pdl_interpreter.py b/src/pdl/pdl_interpreter.py index 6ea6078f1..650229ad3 100644 --- a/src/pdl/pdl_interpreter.py +++ b/src/pdl/pdl_interpreter.py @@ -10,6 +10,7 @@ # TODO: temporarily disabling warnings to mute a pydantic warning from liteLLM import warnings +from functools import partial from os import getenv warnings.filterwarnings("ignore", "Valid config keys have changed in V2") @@ -341,6 +342,34 @@ def identity(result): return identity +def set_error_to_scope_for_retry( + scope: ScopeType, error, block_id: Optional[str] = "" +) -> ScopeType: + repeating_same_error = False + pdl_context: Optional[LazyMessages] = scope.get("pdl_context") + if pdl_context is None: + return scope + if pdl_context and isinstance(pdl_context, list): + last_msg = pdl_context[-1] + last_error = last_msg["content"] + if last_error.endswith(error): + repeating_same_error = True + if repeating_same_error: + error = "The previous error occurs multiple times." + err_msg = { + "role": "assistant", + "content": error, + "defsite": block_id, + } + scope = scope | { + "pdl_context": lazy_messages_concat( + pdl_context, + PdlList([err_msg]), + ) + } + return scope + + def process_advanced_block( state: InterpreterState, scope: ScopeType, @@ -361,52 +390,85 @@ def process_advanced_block( state = state.with_yield_background( state.yield_background and context_in_contribute(block) ) - try: - result, background, new_scope, trace = process_block_body( - state, scope, block, loc - ) - result = lazy_apply(id_with_set_first_use_nanos(block.pdl__timing), result) - background = lazy_apply( - id_with_set_first_use_nanos(block.pdl__timing), background - ) - trace = trace.model_copy(update={"pdl__result": result}) - if block.parser is not None: - parser = block.parser - result = lazy_apply(lambda r: parse_result(parser, r), result) - if init_state.yield_result and ContributeTarget.RESULT: - yield_result(result, block.kind) - if block.spec is not None and not isinstance(block, FunctionBlock): - result = lazy_apply( - lambda r: result_with_type_checking( - r, block.spec, "Type errors during spec checking:", loc, trace - ), - result, + + # Bind result variables here with empty values + result: PdlLazy[Any] = PdlConst(None) + background: LazyMessages = PdlList([{}]) + new_scope: ScopeType = PdlDict({}) + trace: AdvancedBlockType = EmptyBlock() + + max_retry = block.retry if block.retry else 0 + trial_total = max_retry + 1 + for trial_idx in range(trial_total): + try: + result, background, new_scope, trace = process_block_body( + state, scope, block, loc ) - if block.fallback is not None: - result.result() - except Exception as exc: - if block.fallback is None: - raise exc from exc - ( - result, - background, - new_scope, - trace, - ) = process_block_of( - block, - "fallback", - state, - scope, - loc=loc, - ) - if block.spec is not None and not isinstance(block, FunctionBlock): - loc = append(loc, "fallback") - result = lazy_apply( - lambda r: result_with_type_checking( - r, block.spec, "Type errors during spec checking:", loc, trace - ), + result = lazy_apply(id_with_set_first_use_nanos(block.pdl__timing), result) + background = lazy_apply( + id_with_set_first_use_nanos(block.pdl__timing), background + ) + trace = trace.model_copy(update={"pdl__result": result}) + if block.parser is not None: + # Use partial to create a function with fixed arguments + parser_func = partial(parse_result, block.parser) + result = lazy_apply(parser_func, result) + if init_state.yield_result and ContributeTarget.RESULT: + yield_result(result, block.kind) + if block.spec is not None and not isinstance(block, FunctionBlock): + # Use partial to create a function with fixed arguments + checker = partial( + result_with_type_checking, + spec=block.spec, + msg="Type errors during spec checking:", + loc=loc, + trace=trace, + ) + result = lazy_apply(checker, result) + if block.fallback is not None: + result.result() + break + except Exception as exc: + err_msg = exc.args[0] + do_retry = ( + block.retry + and trial_idx + 1 < trial_total + and "Keyboard Interrupt" not in err_msg + ) + if block.fallback is None and not do_retry: + raise exc from exc + if do_retry: + error = f"An error occurred in a PDL block. Error details: {err_msg}" + print( + f"\n\033[0;31m[Retry {trial_idx+1}/{max_retry}] {error}\033[0m\n", + file=sys.stderr, + ) + if block.trace_error_on_retry: + scope = set_error_to_scope_for_retry(scope, error, block.pdl__id) + continue + ( result, + background, + new_scope, + trace, + ) = process_block_of( + block, + "fallback", + state, + scope, + loc=loc, ) + if block.spec is not None and not isinstance(block, FunctionBlock): + loc = append(loc, "fallback") + # Use partial to create a function with fixed arguments + checker = partial( + result_with_type_checking, + spec=block.spec, + msg="Type errors during spec checking:", + loc=loc, + trace=trace, + ) + result = lazy_apply(checker, result) if block.def_ is not None: var = block.def_ new_scope = new_scope | PdlDict({var: result}) diff --git a/tests/test_retry.py b/tests/test_retry.py new file mode 100644 index 000000000..9674bc197 --- /dev/null +++ b/tests/test_retry.py @@ -0,0 +1,116 @@ +import io +from contextlib import redirect_stderr, redirect_stdout + +from pdl.pdl import exec_dict + + +def repeat_retry_data(n: int): + return { + "description": "Example of retry code within a repeat block", + "repeat": { + "text": [ + "Hello, ", + { + "lang": "python", + "code": { + "text": [ + "raise ValueError('dummy exception')\n", + "result = 'World'", + ] + }, + }, + "!\n", + ], + "retry": n, + }, + "max_iterations": 2, + } + + +def repeat_retry(n: int, should_be_no_error: bool = False): + err_msg = "" + # catch stdout string + with io.StringIO() as buf, redirect_stdout(buf), redirect_stderr(buf): + try: + _ = exec_dict(repeat_retry_data(n)) + except Exception: + pass + err_msg = buf.getvalue() + + if should_be_no_error: + assert err_msg == "" + else: + assert f"[Retry 1/{n}]" in err_msg + + +def test_repeat_retry_negative(): + repeat_retry(-1, should_be_no_error=True) + + +def test_repeat_retry0(): + repeat_retry(0, should_be_no_error=True) + + +def test_repeat_retry1(): + repeat_retry(1) + + +def test_repeat_retry2(): + repeat_retry(2) + + +def test_repeat_retry3(): + repeat_retry(3) + + +def code_retry_data(n: int): + return { + "description": "Example of retry code within a code block", + "text": [ + { + "lang": "python", + "code": { + "text": [ + "raise ValueError('dummy exception')\n", + "result = 'hello, world!'", + ] + }, + }, + ], + "retry": n, + } + + +def code_retry(n: int, should_be_no_error: bool = False): + err_msg = "" + # catch stdout string + with io.StringIO() as buf, redirect_stdout(buf), redirect_stderr(buf): + try: + _ = exec_dict(code_retry_data(n)) + except Exception: + pass + err_msg = buf.getvalue() + if should_be_no_error: + assert err_msg == "" + else: + assert f"[Retry 1/{n}]" in err_msg + + +def test_code_retry_negative(): + code_retry(-1, should_be_no_error=True) + + +def test_code_retry0(): + code_retry(0, should_be_no_error=True) + + +def test_code_retry1(): + code_retry(1) + + +def test_code_retry2(): + code_retry(2) + + +def test_code_retry3(): + code_retry(3)