@@ -54,9 +54,13 @@ llmSynthesize0[ prompt: $$llmPrompt, evaluator_Association, attempt_ ] := Enclos
54
54
task = llmSynthesizeSubmit [ prompt , evaluator , callback ];
55
55
If [ FailureQ @ task , throwFailureToChatOutput @ task ];
56
56
TaskWait @ ConfirmMatch [ task , _ TaskObject , "Task" ];
57
- If [ MatchQ [ result , Failure [ "InvalidResponse" , _ ] ] && attempt <= 3 ,
57
+
58
+ If [ MatchQ [ result , Failure [ "InvalidResponse" , _ ] ]
59
+ ,
60
+ If [ attempt > 3 , throwFailureToChatOutput @ result ];
58
61
Pause [ Exp @ attempt / E ];
59
- llmSynthesize0 [ prompt , evaluator , attempt + 1 ],
62
+ llmSynthesize0 [ prompt , evaluator , attempt + 1 ]
63
+ ,
60
64
result
61
65
]
62
66
],
@@ -108,7 +112,7 @@ llmSynthesizeSubmit[ prompt0: $$llmPrompt, evaluator0_Association, callback_ ] :
108
112
FailureQ @ strings ,
109
113
callback [ strings , #1 ],
110
114
True ,
111
- callback [ Failure [ "InvalidResponse" , < | "Data" -> data | > ] , #1 ]
115
+ callback [ makeInvalidResponseFailure @ data , #1 ]
112
116
]
113
117
]
114
118
]
@@ -132,13 +136,39 @@ llmSynthesizeSubmit[ prompt0: $$llmPrompt, evaluator0_Association, callback_ ] :
132
136
133
137
llmSynthesizeSubmit // endDefinition ;
134
138
139
+ (* ::**************************************************************************************************************:: *)
140
+ (* ::Subsubsection::Closed:: *)
141
+ (*makeInvalidResponseFailure*)
142
+ makeInvalidResponseFailure // beginDefinition ;
143
+
144
+ makeInvalidResponseFailure [ data_ List ] /; MemberQ [ data , KeyValuePattern [ "StatusCode" -> 504 ] ] := Failure [
145
+ "InvalidResponse" ,
146
+ < |
147
+ "Message" -> "The server is currently unavailable (504 Gateway Time-out). Please try again later." ,
148
+ "Data" -> data
149
+ |>
150
+ ];
151
+
152
+ makeInvalidResponseFailure [ data_ List ] := Failure [
153
+ "InvalidResponse" ,
154
+ < |
155
+ "Message" -> "The server returned an invalid response. Please try again later." ,
156
+ "Data" -> data
157
+ |>
158
+ ];
159
+
160
+ makeInvalidResponseFailure // endDefinition ;
161
+
135
162
(* ::**************************************************************************************************************:: *)
136
163
(* ::Subsubsection::Closed:: *)
137
164
(*truncatePrompt*)
138
165
truncatePrompt // beginDefinition ;
139
166
140
- truncatePrompt [ string_ String , evaluator_ ] := stringTrimMiddle [ string , modelContextLimit @ evaluator ];
141
- truncatePrompt [ { strings___ String }, evaluator_ ] := truncatePrompt [ StringJoin @ strings , evaluator ];
167
+ truncatePrompt [ string_ String , evaluator_ ] :=
168
+ stringTrimMiddle [ string , modelContextLimit @ evaluator ];
169
+
170
+ truncatePrompt [ { strings___ String }, evaluator_ ] :=
171
+ truncatePrompt [ StringJoin @ strings , evaluator ];
142
172
143
173
truncatePrompt [ prompts : { ($$string |$$graphics ).. }, evaluator_ ] := Enclose [
144
174
Module [ { stringCount , images , imageCount , budget , imageBudget , resized , imageTokens , stringBudget },
0 commit comments