Skip to content

Commit ecaef63

Browse files
authored
fix: more cases of unknown characters in generation streaming (#295)
1 parent 097b3ec commit ecaef63

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/evaluator/LlamaChat/LlamaChat.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,6 +2217,9 @@ class GenerateResponseState<const Functions extends ChatModelFunctions | undefin
22172217
public waitOnPartialCharactersOrWhiteSpaceTokens() {
22182218
if (this.currentText.endsWith(UNKNOWN_UNICODE_CHAR) || (
22192219
(this.grammar?.trimWhitespaceSuffix || this.trimWhitespaceSuffix) && this.currentText?.trim() === ""
2220+
) || (
2221+
this.currentText === "" && this.locksToReleaseOnValidGeneration.length > 0 &&
2222+
!this.llamaChat.model.isSpecialToken(this.currentToken)
22202223
)) {
22212224
if (this.currentQueuedTokenRelease != null)
22222225
this.locksToReleaseOnValidGeneration.push(this.currentQueuedTokenRelease.createTextIndexLock(0));

src/evaluator/LlamaCompletion.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,8 @@ export class LlamaCompletion {
664664

665665
if (text.endsWith(UNKNOWN_UNICODE_CHAR) || (
666666
(grammar?.trimWhitespaceSuffix || trimWhitespaceSuffix) && text.trim() === ""
667+
) || (
668+
text === "" && locksToReleaseOnValidGeneration.length > 0 && !model.isSpecialToken(token)
667669
)) {
668670
locksToReleaseOnValidGeneration.push(queuedTokenRelease.createTextIndexLock(0));
669671
} else {

0 commit comments

Comments
 (0)