Skip to content

Commit d2d52c6

Browse files
use retry_max only
Signed-off-by: hirokuni-kitahara <[email protected]>
1 parent 3926a8a commit d2d52c6

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
@@ -379,7 +379,7 @@
379379
"items": {
380380
"anyOf": [
381381
{
382-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
382+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
383383
},
384384
{
385385
"type": "string"
@@ -1232,7 +1232,7 @@
12321232
"call": {
12331233
"anyOf": [
12341234
{
1235-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
1235+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
12361236
},
12371237
{},
12381238
{
@@ -1245,7 +1245,7 @@
12451245
"args": {
12461246
"anyOf": [
12471247
{
1248-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
1248+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
12491249
},
12501250
{},
12511251
{
@@ -1805,7 +1805,7 @@
18051805
"value": {
18061806
"anyOf": [
18071807
{
1808-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
1808+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
18091809
},
18101810
{
18111811
"items": {},
@@ -2168,7 +2168,7 @@
21682168
"data": {
21692169
"anyOf": [
21702170
{
2171-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
2171+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
21722172
},
21732173
{},
21742174
{
@@ -4116,7 +4116,7 @@
41164116
"model": {
41174117
"anyOf": [
41184118
{
4119-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
4119+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
41204120
},
41214121
{},
41224122
{
@@ -4261,7 +4261,7 @@
42614261
"backend": {
42624262
"anyOf": [
42634263
{
4264-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
4264+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
42654265
},
42664266
{
42674267
"type": "string"
@@ -4276,7 +4276,7 @@
42764276
"processor": {
42774277
"anyOf": [
42784278
{
4279-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
4279+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
42804280
},
42814281
{
42824282
"type": "string"
@@ -4292,7 +4292,7 @@
42924292
"parameters": {
42934293
"anyOf": [
42944294
{
4295-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
4295+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
42964296
},
42974297
{
42984298
"type": "object"
@@ -4660,7 +4660,7 @@
46604660
"if": {
46614661
"anyOf": [
46624662
{
4663-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
4663+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
46644664
},
46654665
{
46664666
"type": "boolean"
@@ -6582,7 +6582,7 @@
65826582
"model": {
65836583
"anyOf": [
65846584
{
6585-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
6585+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
65866586
},
65876587
{
65886588
"type": "string"
@@ -6729,7 +6729,7 @@
67296729
"$ref": "#/$defs/LitellmParameters"
67306730
},
67316731
{
6732-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
6732+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
67336733
},
67346734
{
67356735
"type": "object"
@@ -7150,7 +7150,7 @@
71507150
"title": "LitellmParameters",
71517151
"type": "object"
71527152
},
7153-
"LocalizedExpression_TypeVar_": {
7153+
"LocalizedExpression__ExpressionTypeT_": {
71547154
"additionalProperties": false,
71557155
"properties": {
71567156
"pdl__expr": {
@@ -7528,7 +7528,7 @@
75287528
"match": {
75297529
"anyOf": [
75307530
{
7531-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
7531+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
75327532
},
75337533
{},
75347534
{
@@ -7594,7 +7594,7 @@
75947594
"if": {
75957595
"anyOf": [
75967596
{
7597-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
7597+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
75987598
},
75997599
{
76007600
"type": "boolean"
@@ -9550,7 +9550,7 @@
95509550
"read": {
95519551
"anyOf": [
95529552
{
9553-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
9553+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
95549554
},
95559555
{
95569556
"type": "string"
@@ -9986,7 +9986,7 @@
99869986
"additionalProperties": {
99879987
"anyOf": [
99889988
{
9989-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
9989+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
99909990
},
99919991
{
99929992
"items": {},
@@ -10010,7 +10010,7 @@
1001010010
"while": {
1001110011
"anyOf": [
1001210012
{
10013-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
10013+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
1001410014
},
1001510015
{
1001610016
"type": "boolean"
@@ -10110,7 +10110,7 @@
1011010110
"until": {
1011110111
"anyOf": [
1011210112
{
10113-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
10113+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
1011410114
},
1011510115
{
1011610116
"type": "boolean"
@@ -10126,7 +10126,7 @@
1012610126
"max_iterations": {
1012710127
"anyOf": [
1012810128
{
10129-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
10129+
"$ref": "#/$defs/LocalizedExpression__ExpressionTypeT_"
1013010130
},
1013110131
{
1013210132
"type": "integer"
@@ -10164,12 +10164,6 @@
1016410164
"description": "Define how to combine the result of each iteration.\n ",
1016510165
"title": "Join"
1016610166
},
10167-
"retry_on_error": {
10168-
"default": false,
10169-
"description": "Indicate if this block should be retried when an error occurs.\n ",
10170-
"title": "Retry On Error",
10171-
"type": "boolean"
10172-
},
1017310167
"retry_max": {
1017410168
"anyOf": [
1017510169
{
@@ -10180,6 +10174,7 @@
1018010174
}
1018110175
],
1018210176
"default": 0,
10177+
"description": "Maximum number of retry on errors in the loop.\n ",
1018310178
"title": "Retry Max"
1018410179
},
1018510180
"pdl__trace": {

src/pdl/pdl_ast.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -748,11 +748,8 @@ class RepeatBlock(StructuredBlock):
748748
join: JoinType = JoinText()
749749
"""Define how to combine the result of each iteration.
750750
"""
751-
retry_on_error: bool = False
752-
"""Indicate if this block should be retried when an error occurs.
753-
"""
754-
retry_max: int = 3
755-
"""Maximum number of retry.
751+
retry_max: Optional[int] = 0
752+
"""Maximum number of retry on errors in the loop.
756753
"""
757754
# Field for internal use
758755
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
@@ -783,13 +783,24 @@ def process_block_body(
783783
manual_stop = True
784784
iter_trace.append(exc.pdl__trace)
785785
trace = block.model_copy(update={"pdl__trace": iter_trace})
786-
if block.retry_on_error and retry_count < block.retry_max and not manual_stop:
786+
if (
787+
block.retry_max
788+
and block.retry_max > 0
789+
and retry_count < block.retry_max
790+
and not manual_stop
791+
):
787792
retry_count += 1
788793
error = f"Retry on error is triggered in a repeat block. Error detail: {repr(exc)} "
789794
print(f"\n\033[0;31m{error}\033[0m\n")
790-
if background and background.data and background.data[-1]["content"].endswith(error):
795+
if (
796+
background
797+
and background.data
798+
and background.data[-1]["content"].endswith(error)
799+
):
791800
error = "The previous error occurs multiple times."
792-
background = lazy_messages_concat(background, [{"role": "assistant", "content": error}])
801+
background = lazy_messages_concat(
802+
background, [{"role": "assistant", "content": error}]
803+
)
793804
else:
794805
raise PDLRuntimeError(
795806
exc.message,

0 commit comments

Comments
 (0)