Skip to content

Commit

Permalink
fix: more cases of unknown characters in generation streaming (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
giladgd authored Aug 9, 2024
1 parent 097b3ec commit ecaef63
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/evaluator/LlamaChat/LlamaChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2217,6 +2217,9 @@ class GenerateResponseState<const Functions extends ChatModelFunctions | undefin
public waitOnPartialCharactersOrWhiteSpaceTokens() {
if (this.currentText.endsWith(UNKNOWN_UNICODE_CHAR) || (
(this.grammar?.trimWhitespaceSuffix || this.trimWhitespaceSuffix) && this.currentText?.trim() === ""
) || (
this.currentText === "" && this.locksToReleaseOnValidGeneration.length > 0 &&
!this.llamaChat.model.isSpecialToken(this.currentToken)
)) {
if (this.currentQueuedTokenRelease != null)
this.locksToReleaseOnValidGeneration.push(this.currentQueuedTokenRelease.createTextIndexLock(0));
Expand Down
2 changes: 2 additions & 0 deletions src/evaluator/LlamaCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,8 @@ export class LlamaCompletion {

if (text.endsWith(UNKNOWN_UNICODE_CHAR) || (
(grammar?.trimWhitespaceSuffix || trimWhitespaceSuffix) && text.trim() === ""
) || (
text === "" && locksToReleaseOnValidGeneration.length > 0 && !model.isSpecialToken(token)
)) {
locksToReleaseOnValidGeneration.push(queuedTokenRelease.createTextIndexLock(0));
} else {
Expand Down

0 comments on commit ecaef63

Please sign in to comment.