Skip to content

Commit

Permalink
Finish the batch if the sender is disconnected.
Browse files Browse the repository at this point in the history
  • Loading branch information
cryscan committed Sep 26, 2023
1 parent b62cb4e commit 14e853f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ pub fn run(runtime: Arc<Mutex<Option<Runtime>>>, tokenizer: Tokenizer, receiver:
output_tokens.into_iter(),
input_tokens.into_iter(),
)) {
let mut fin = false;
let mut done = false;

if let Payload::Busy(context) = payload {
let prefix = std::mem::take(&mut context.prefix);
Expand Down Expand Up @@ -484,18 +484,20 @@ pub fn run(runtime: Arc<Mutex<Option<Runtime>>>, tokenizer: Tokenizer, receiver:
let mut finish = |reason| {
let _ = context.sender.send(Token::Stop(reason, count_tokens()));
let _ = context.sender.send(Token::Done);
fin = true;
done = true;
};

if context.stop.iter().any(|stop| model_text.contains(stop)) {
if context.sender.is_disconnected() {
done = true;
} else if context.stop.iter().any(|stop| model_text.contains(stop)) {
finish(FinishReason::Stop);
} else if context.model_tokens.len() >= context.max_tokens {
finish(FinishReason::Length);
}
}
}

if fin {
if done {
payload.finalize();
}
}
Expand Down

0 comments on commit 14e853f

Please sign in to comment.