Skip to content

Commit 538b28d

Browse files
use retry_max only
Signed-off-by: hirokuni-kitahara <[email protected]>
1 parent 85a5df2 commit 538b28d

File tree

4 files changed

+39
-34
lines changed

4 files changed

+39
-34
lines changed

src/pdl/pdl-schema.json

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@
378378
"items": {
379379
"anyOf": [
380380
{
381-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
381+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
382382
},
383383
{
384384
"type": "string"
@@ -1228,7 +1228,7 @@
12281228
"call": {
12291229
"anyOf": [
12301230
{
1231-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
1231+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
12321232
},
12331233
{},
12341234
{
@@ -1241,7 +1241,7 @@
12411241
"args": {
12421242
"anyOf": [
12431243
{
1244-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
1244+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
12451245
},
12461246
{},
12471247
{
@@ -1799,7 +1799,7 @@
17991799
"value": {
18001800
"anyOf": [
18011801
{
1802-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
1802+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
18031803
},
18041804
{
18051805
"items": {},
@@ -2161,7 +2161,7 @@
21612161
"data": {
21622162
"anyOf": [
21632163
{
2164-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
2164+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
21652165
},
21662166
{},
21672167
{
@@ -4103,7 +4103,7 @@
41034103
"model": {
41044104
"anyOf": [
41054105
{
4106-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
4106+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
41074107
},
41084108
{},
41094109
{
@@ -4248,7 +4248,7 @@
42484248
"backend": {
42494249
"anyOf": [
42504250
{
4251-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
4251+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
42524252
},
42534253
{
42544254
"type": "string"
@@ -4264,7 +4264,7 @@
42644264
"processor": {
42654265
"anyOf": [
42664266
{
4267-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
4267+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
42684268
},
42694269
{
42704270
"type": "string"
@@ -4280,7 +4280,7 @@
42804280
"parameters": {
42814281
"anyOf": [
42824282
{
4283-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
4283+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
42844284
},
42854285
{
42864286
"additionalProperties": true,
@@ -4648,7 +4648,7 @@
46484648
"if": {
46494649
"anyOf": [
46504650
{
4651-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
4651+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
46524652
},
46534653
{
46544654
"type": "boolean"
@@ -6563,7 +6563,7 @@
65636563
"model": {
65646564
"anyOf": [
65656565
{
6566-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
6566+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
65676567
},
65686568
{
65696569
"type": "string"
@@ -6710,7 +6710,7 @@
67106710
"$ref": "#/$defs/LitellmParameters"
67116711
},
67126712
{
6713-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
6713+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
67146714
},
67156715
{
67166716
"additionalProperties": true,
@@ -7136,7 +7136,7 @@
71367136
"title": "LitellmParameters",
71377137
"type": "object"
71387138
},
7139-
"LocalizedExpression_TypeVar_": {
7139+
"LocalizedExpression__ExpressionTypeT_": {
71407140
"additionalProperties": false,
71417141
"properties": {
71427142
"pdl__expr": {
@@ -7513,7 +7513,7 @@
75137513
"match": {
75147514
"anyOf": [
75157515
{
7516-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
7516+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
75177517
},
75187518
{},
75197519
{
@@ -7579,7 +7579,7 @@
75797579
"if": {
75807580
"anyOf": [
75817581
{
7582-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
7582+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
75837583
},
75847584
{
75857585
"type": "boolean"
@@ -9564,7 +9564,7 @@
95649564
"read": {
95659565
"anyOf": [
95669566
{
9567-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
9567+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
95689568
},
95699569
{
95709570
"type": "string"
@@ -10000,7 +10000,7 @@
1000010000
"additionalProperties": {
1000110001
"anyOf": [
1000210002
{
10003-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
10003+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
1000410004
},
1000510005
{
1000610006
"items": {},
@@ -10024,7 +10024,7 @@
1002410024
"while": {
1002510025
"anyOf": [
1002610026
{
10027-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
10027+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
1002810028
},
1002910029
{
1003010030
"type": "boolean"
@@ -10123,7 +10123,7 @@
1012310123
"until": {
1012410124
"anyOf": [
1012510125
{
10126-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
10126+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
1012710127
},
1012810128
{
1012910129
"type": "boolean"
@@ -10139,7 +10139,7 @@
1013910139
"max_iterations": {
1014010140
"anyOf": [
1014110141
{
10142-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
10142+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
1014310143
},
1014410144
{
1014510145
"type": "integer"
@@ -10177,12 +10177,6 @@
1017710177
"description": "Define how to combine the result of each iteration.\n ",
1017810178
"title": "Join"
1017910179
},
10180-
"retry_on_error": {
10181-
"default": false,
10182-
"description": "Indicate if this block should be retried when an error occurs.\n ",
10183-
"title": "Retry On Error",
10184-
"type": "boolean"
10185-
},
1018610180
"retry_max": {
1018710181
"anyOf": [
1018810182
{
@@ -10193,6 +10187,7 @@
1019310187
}
1019410188
],
1019510189
"default": 0,
10190+
"description": "Maximum number of retry on errors in the loop.\n ",
1019610191
"title": "Retry Max"
1019710192
},
1019810193
"pdl__trace": {

src/pdl/pdl_ast.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -752,11 +752,8 @@ class RepeatBlock(StructuredBlock):
752752
join: JoinType = JoinText()
753753
"""Define how to combine the result of each iteration.
754754
"""
755-
retry_on_error: bool = False
756-
"""Indicate if this block should be retried when an error occurs.
757-
"""
758-
retry_max: int = 3
759-
"""Maximum number of retry.
755+
retry_max: Optional[int] = 0
756+
"""Maximum number of retry on errors in the loop.
760757
"""
761758
# Field for internal use
762759
pdl__trace: Optional[list["BlockType"]] = None

src/pdl/pdl_dumper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ def block_to_dict( # noqa: C901
218218
block.max_iterations, json_compatible
219219
)
220220
d["join"] = join_to_dict(block.join)
221+
if block.retry_max is not None:
222+
d["retry_max"] = expr_to_dict(block.retry_max, json_compatible)
221223
if block.pdl__trace is not None:
222224
d["pdl__trace"] = [
223225
block_to_dict(b, json_compatible) for b in block.pdl__trace

src/pdl/pdl_interpreter.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -795,13 +795,24 @@ def process_block_body(
795795
manual_stop = True
796796
iter_trace.append(exc.pdl__trace)
797797
trace = block.model_copy(update={"pdl__trace": iter_trace})
798-
if block.retry_on_error and retry_count < block.retry_max and not manual_stop:
798+
if (
799+
block.retry_max
800+
and block.retry_max > 0
801+
and retry_count < block.retry_max
802+
and not manual_stop
803+
):
799804
retry_count += 1
800805
error = f"Retry on error is triggered in a repeat block. Error detail: {repr(exc)} "
801806
print(f"\n\033[0;31m{error}\033[0m\n")
802-
if background and background.data and background.data[-1]["content"].endswith(error):
807+
if (
808+
background
809+
and background.data
810+
and background.data[-1]["content"].endswith(error)
811+
):
803812
error = "The previous error occurs multiple times."
804-
background = lazy_messages_concat(background, [{"role": "assistant", "content": error}])
813+
background = lazy_messages_concat(
814+
background, [{"role": "assistant", "content": error}]
815+
)
805816
else:
806817
raise PDLRuntimeError(
807818
exc.message,

0 commit comments

Comments
 (0)