Skip to content

Commit 34d6887

Browse files
committed
fix: apply maxTokens on function calling parameters
1 parent 1ff1f13 commit 34d6887

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

src/evaluator/LlamaChat/LlamaChat.ts

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,11 +2178,15 @@ class GenerateResponseState<const Functions extends ChatModelFunctions | undefin
21782178
!this.disengageInitiallyEngagedFunctionMode.hasInProgressStops
21792179
)
21802180
break;
2181+
2182+
const stopRes = this.handleAbortTrigger("model") ?? this.handleMaxTokensTrigger("model");
2183+
if (stopRes != null)
2184+
return stopRes;
21812185
}
21822186

2183-
const abortRes = this.handleAbortTrigger("model");
2184-
if (abortRes != null)
2185-
return abortRes;
2187+
const stopRes = this.handleAbortTrigger("model") ?? this.handleMaxTokensTrigger("model");
2188+
if (stopRes != null)
2189+
return stopRes;
21862190

21872191
if (this.disengageInitiallyEngagedFunctionMode.hasTriggeredStops) {
21882192
const lastTokensForDetokenizer = this.streamRegulator.getLastQueuedChunkTokens();
@@ -2290,11 +2294,15 @@ class GenerateResponseState<const Functions extends ChatModelFunctions | undefin
22902294

22912295
if (functionNameGenerationDoneDetector.hasTriggeredStops)
22922296
break;
2297+
2298+
const stopRes = this.handleAbortTrigger("model") ?? this.handleMaxTokensTrigger("model");
2299+
if (stopRes != null)
2300+
return stopRes;
22932301
}
22942302

2295-
const abortRes = this.handleAbortTrigger("model");
2296-
if (abortRes != null)
2297-
return abortRes;
2303+
const stopRes = this.handleAbortTrigger("model") ?? this.handleMaxTokensTrigger("model");
2304+
if (stopRes != null)
2305+
return stopRes;
22982306

22992307
const functionCallNameText = this.llamaChat.model.detokenize(this.currentFunctionCallCurrentPartTokens);
23002308
const functionName = functionNameGrammar.parseFunctionName(functionCallNameText);
@@ -2375,11 +2383,15 @@ class GenerateResponseState<const Functions extends ChatModelFunctions | undefin
23752383

23762384
if (functionParamsGenerationDoneDetector.hasTriggeredStops)
23772385
break;
2386+
2387+
const stopRes = this.handleAbortTrigger("model") ?? this.handleMaxTokensTrigger("model");
2388+
if (stopRes != null)
2389+
return stopRes;
23782390
}
23792391

2380-
const abortRes = this.handleAbortTrigger("model");
2381-
if (abortRes != null)
2382-
return abortRes;
2392+
const stopRes = this.handleAbortTrigger("model") ?? this.handleMaxTokensTrigger("model");
2393+
if (stopRes != null)
2394+
return stopRes;
23832395

23842396
const functionCallParamsText =
23852397
this.llamaChat.model.detokenize(this.currentFunctionCallCurrentPartTokens, false, lastPartTokens);
@@ -2452,11 +2464,15 @@ class GenerateResponseState<const Functions extends ChatModelFunctions | undefin
24522464

24532465
if (sectionSuffixDetector.hasTriggeredStops || !sectionSuffixDetector.hasInProgressStops)
24542466
break;
2467+
2468+
const stopRes = this.handleAbortTrigger("model") ?? this.handleMaxTokensTrigger("model");
2469+
if (stopRes != null)
2470+
return stopRes;
24552471
}
24562472

2457-
const abortRes = this.handleAbortTrigger("model");
2458-
if (abortRes != null)
2459-
return abortRes;
2473+
const stopRes = this.handleAbortTrigger("model") ?? this.handleMaxTokensTrigger("model");
2474+
if (stopRes != null)
2475+
return stopRes;
24602476

24612477
if (sectionSuffixDetector.hasTriggeredStops) {
24622478
this.functionEvaluationMode = false;

0 commit comments

Comments
 (0)