Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
fix(llm): only feed prompt if not empty
Browse files Browse the repository at this point in the history
  • Loading branch information
philpax committed Jul 12, 2023
1 parent 8702593 commit 710f3c2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion crates/llm-base/src/inference_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,14 +438,16 @@ impl InferenceSession {
let parameters = request.parameters;

// Feed the initial prompt through the transformer, to update its
// context window with new data.
// context window with new data, if necessary.
if !request.prompt.is_empty() {
self.feed_prompt(
model,
parameters,
request.prompt,
output_request,
feed_prompt_callback(&mut callback),
)?;
}
stats.feed_prompt_duration = start_at.elapsed().unwrap();
stats.prompt_tokens = self.n_past;

Expand Down
8 changes: 8 additions & 0 deletions crates/llm-base/src/tokenizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ impl Prompt<'_> {
}
})
}

/// Returns whether this prompt is empty.
pub fn is_empty(&self) -> bool {
match self {
Self::Text(text) => text.is_empty(),
Self::Tokens(tokens) => tokens.is_empty(),
}
}
}
impl<'a> Default for Prompt<'a> {
fn default() -> Self {
Expand Down

0 comments on commit 710f3c2

Please sign in to comment.