Skip to content

Commit 69fdddb

Browse files
use retry_max only
Signed-off-by: hirokuni-kitahara <[email protected]>
1 parent f62a252 commit 69fdddb

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
@@ -380,7 +380,7 @@
380380
"items": {
381381
"anyOf": [
382382
{
383-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
383+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
384384
},
385385
{
386386
"type": "string"
@@ -1235,7 +1235,7 @@
12351235
"call": {
12361236
"anyOf": [
12371237
{
1238-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
1238+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
12391239
},
12401240
{},
12411241
{
@@ -1248,7 +1248,7 @@
12481248
"args": {
12491249
"anyOf": [
12501250
{
1251-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
1251+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
12521252
},
12531253
{},
12541254
{
@@ -1809,7 +1809,7 @@
18091809
"value": {
18101810
"anyOf": [
18111811
{
1812-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
1812+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
18131813
},
18141814
{
18151815
"items": {},
@@ -2173,7 +2173,7 @@
21732173
"data": {
21742174
"anyOf": [
21752175
{
2176-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
2176+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
21772177
},
21782178
{},
21792179
{
@@ -4127,7 +4127,7 @@
41274127
"model": {
41284128
"anyOf": [
41294129
{
4130-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
4130+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
41314131
},
41324132
{},
41334133
{
@@ -4273,7 +4273,7 @@
42734273
"backend": {
42744274
"anyOf": [
42754275
{
4276-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
4276+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
42774277
},
42784278
{
42794279
"type": "string"
@@ -4289,7 +4289,7 @@
42894289
"processor": {
42904290
"anyOf": [
42914291
{
4292-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
4292+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
42934293
},
42944294
{
42954295
"type": "string"
@@ -4305,7 +4305,7 @@
43054305
"parameters": {
43064306
"anyOf": [
43074307
{
4308-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
4308+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
43094309
},
43104310
{
43114311
"additionalProperties": true,
@@ -4675,7 +4675,7 @@
46754675
"if": {
46764676
"anyOf": [
46774677
{
4678-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
4678+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
46794679
},
46804680
{
46814681
"type": "boolean"
@@ -6601,7 +6601,7 @@
66016601
"model": {
66026602
"anyOf": [
66036603
{
6604-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
6604+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
66056605
},
66066606
{
66076607
"type": "string"
@@ -6749,7 +6749,7 @@
67496749
"$ref": "#/$defs/LitellmParameters"
67506750
},
67516751
{
6752-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
6752+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
67536753
},
67546754
{
67556755
"additionalProperties": true,
@@ -7175,7 +7175,7 @@
71757175
"title": "LitellmParameters",
71767176
"type": "object"
71777177
},
7178-
"LocalizedExpression_TypeVar_": {
7178+
"LocalizedExpression__ExpressionTypeT_": {
71797179
"additionalProperties": false,
71807180
"properties": {
71817181
"pdl__expr": {
@@ -7554,7 +7554,7 @@
75547554
"match": {
75557555
"anyOf": [
75567556
{
7557-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
7557+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
75587558
},
75597559
{},
75607560
{
@@ -7620,7 +7620,7 @@
76207620
"if": {
76217621
"anyOf": [
76227622
{
7623-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
7623+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
76247624
},
76257625
{
76267626
"type": "boolean"
@@ -9612,7 +9612,7 @@
96129612
"read": {
96139613
"anyOf": [
96149614
{
9615-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
9615+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
96169616
},
96179617
{
96189618
"type": "string"
@@ -10050,7 +10050,7 @@
1005010050
"additionalProperties": {
1005110051
"anyOf": [
1005210052
{
10053-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
10053+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
1005410054
},
1005510055
{
1005610056
"items": {},
@@ -10074,7 +10074,7 @@
1007410074
"while": {
1007510075
"anyOf": [
1007610076
{
10077-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
10077+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
1007810078
},
1007910079
{
1008010080
"type": "boolean"
@@ -10174,7 +10174,7 @@
1017410174
"until": {
1017510175
"anyOf": [
1017610176
{
10177-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
10177+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
1017810178
},
1017910179
{
1018010180
"type": "boolean"
@@ -10190,7 +10190,7 @@
1019010190
"max_iterations": {
1019110191
"anyOf": [
1019210192
{
10193-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
10193+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
1019410194
},
1019510195
{
1019610196
"type": "integer"
@@ -10228,12 +10228,6 @@
1022810228
"description": "Define how to combine the result of each iteration.\n ",
1022910229
"title": "Join"
1023010230
},
10231-
"retry_on_error": {
10232-
"default": false,
10233-
"description": "Indicate if this block should be retried when an error occurs.\n ",
10234-
"title": "Retry On Error",
10235-
"type": "boolean"
10236-
},
1023710231
"retry_max": {
1023810232
"anyOf": [
1023910233
{
@@ -10244,6 +10238,7 @@
1024410238
}
1024510239
],
1024610240
"default": 0,
10241+
"description": "Maximum number of retry on errors in the loop.\n ",
1024710242
"title": "Retry Max"
1024810243
},
1024910244
"pdl__trace": {

src/pdl/pdl_ast.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -747,11 +747,8 @@ class RepeatBlock(StructuredBlock):
747747
join: JoinType = JoinText()
748748
"""Define how to combine the result of each iteration.
749749
"""
750-
retry_on_error: bool = False
751-
"""Indicate if this block should be retried when an error occurs.
752-
"""
753-
retry_max: int = 3
754-
"""Maximum number of retry.
750+
retry_max: Optional[int] = 0
751+
"""Maximum number of retry on errors in the loop.
755752
"""
756753
# Field for internal use
757754
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
@@ -790,13 +790,24 @@ def process_block_body(
790790
manual_stop = True
791791
iter_trace.append(exc.pdl__trace)
792792
trace = block.model_copy(update={"pdl__trace": iter_trace})
793-
if block.retry_on_error and retry_count < block.retry_max and not manual_stop:
793+
if (
794+
block.retry_max
795+
and block.retry_max > 0
796+
and retry_count < block.retry_max
797+
and not manual_stop
798+
):
794799
retry_count += 1
795800
error = f"Retry on error is triggered in a repeat block. Error detail: {repr(exc)} "
796801
print(f"\n\033[0;31m{error}\033[0m\n")
797-
if background and background.data and background.data[-1]["content"].endswith(error):
802+
if (
803+
background
804+
and background.data
805+
and background.data[-1]["content"].endswith(error)
806+
):
798807
error = "The previous error occurs multiple times."
799-
background = lazy_messages_concat(background, [{"role": "assistant", "content": error}])
808+
background = lazy_messages_concat(
809+
background, [{"role": "assistant", "content": error}]
810+
)
800811
else:
801812
raise PDLRuntimeError(
802813
exc.message,

0 commit comments

Comments
 (0)