@@ -34,7 +34,11 @@ llmSynthesize[ prompt: $$llmPrompt ] :=
34
34
llmSynthesize [ prompt , < | |> ];
35
35
36
36
llmSynthesize [ prompt : $$llmPrompt , evaluator_ Association ] := Enclose [
37
- ConfirmMatch [ llmSynthesize0 [ prompt , evaluator , 1 ], Except [ "" , _ String ], "Result" ],
37
+ ConfirmMatch [
38
+ llmSynthesize0 [ prompt , evaluator , 1 ],
39
+ If [ MatchQ [ Flatten @ { evaluator [ "StopTokens" ] }, { __ String } ], _ String , Except [ "" , _ String ] ],
40
+ "Result"
41
+ ],
38
42
throwInternalFailure
39
43
];
40
44
@@ -70,19 +74,25 @@ llmSynthesizeSubmit[ prompt: $$llmPrompt, callback_ ] :=
70
74
llmSynthesizeSubmit [ prompt , < | |> , callback ];
71
75
72
76
llmSynthesizeSubmit [ prompt0 : $$llmPrompt , evaluator0_ Association , callback_ ] := Enclose [
73
- Module [ { evaluator , prompt , messages , config , chunks , handlers , keys },
77
+ Module [ { evaluator , prompt , messages , config , chunks , allowEmpty , handlers , keys , auth },
74
78
75
- evaluator = ConfirmBy [
76
- < | $defaultLLMSynthesizeEvaluator , DeleteCases [ evaluator0 , Automatic | _ Missing ] |> ,
77
- AssociationQ ,
78
- "Evaluator"
79
+ evaluator = Replace [
80
+ ConfirmBy [
81
+ < | $defaultLLMSynthesizeEvaluator , DeleteCases [ evaluator0 , Automatic | _ Missing ] |> ,
82
+ AssociationQ ,
83
+ "Evaluator"
84
+ ],
85
+ Verbatim [ Verbatim ][ value_ ] :> value ,
86
+ { 1 }
79
87
];
80
88
81
89
prompt = ConfirmMatch [ truncatePrompt [ prompt0 , evaluator ], $$llmPrompt , "Prompt" ];
82
90
messages = { < | "Role" -> "User" , "Content" -> prompt |> };
83
91
config = LLMConfiguration @ evaluator ;
84
92
chunks = Internal ` Bag [ ];
85
93
94
+ allowEmpty = MatchQ [ Flatten @ { evaluator [ "StopTokens" ] }, { __ String } ];
95
+
86
96
handlers = < |
87
97
"BodyChunkReceived" -> Function [
88
98
Internal ` StuffBag [ chunks , # ]
@@ -93,7 +103,7 @@ llmSynthesizeSubmit[ prompt0: $$llmPrompt, evaluator0_Association, callback_ ] :
93
103
$lastSynthesizeSubmitLog = data ;
94
104
strings = extractBodyChunks @ data ;
95
105
Which [
96
- MatchQ [ strings , { __ String } ],
106
+ MatchQ [ strings , { __ String } ] || ( allowEmpty && strings === { }) ,
97
107
With [ { s = StringJoin @ strings }, callback [ s , #1 ] ],
98
108
FailureQ @ strings ,
99
109
callback [ strings , #1 ],
@@ -106,10 +116,12 @@ llmSynthesizeSubmit[ prompt0: $$llmPrompt, evaluator0_Association, callback_ ] :
106
116
107
117
keys = { "BodyChunk" , "BodyChunkProcessed" , "StatusCode" , "EventName" };
108
118
119
+ auth = Lookup [ evaluator , "Authentication" , $llmSynthesizeAuthentication ];
120
+
109
121
setServiceCaller @ LLMServices ` ChatSubmit [
110
122
messages ,
111
123
config ,
112
- Authentication -> $llmSynthesizeAuthentication ,
124
+ Authentication -> auth ,
113
125
HandlerFunctions -> handlers ,
114
126
HandlerFunctionsKeys -> keys ,
115
127
"TestConnection" -> False
0 commit comments