Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ tracing-subscriber.workspace = true
notify.workspace = true
minijinja = { version = "2.15.1", features = ["builtins", "json"] }
minijinja-contrib = { version = "2.15.1", features = ["pycompat"] }
llama-cpp-2 = "=0.1.132"
llama-cpp-2 = "=0.1.133"

[dev-dependencies]
tempfile = { workspace = true, features = [] }
Expand Down
16 changes: 11 additions & 5 deletions crates/core/src/provider/gguf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ use anyhow::{Context, Result, anyhow};
use async_trait::async_trait;
use futures::stream::BoxStream;
use llama_cpp_2::token::LlamaToken;
use llama_cpp_2::{LogOptions, send_logs_to_tracing};
use llama_cpp_2::{LogOptions, TokenToStringError, send_logs_to_tracing};
use llama_cpp_2::{
context::params::LlamaContextParams,
llama_backend::LlamaBackend,
llama_batch::LlamaBatch,
model::Special,
model::{AddBos, LlamaModel, params::LlamaModelParams},
sampling::LlamaSampler,
};
Expand Down Expand Up @@ -293,9 +292,16 @@ impl CompletionModel for GgufBaseModel {
}

// Get token bytes and decode
let token_bytes = model
.token_to_bytes(token, Special::Tokenize)
.map_err(|e| anyhow!("Token conversion failed: {e}"))?;
let token_bytes = match model.token_to_piece_bytes(token, 8, true, None) {
Err(TokenToStringError::InsufficientBufferSpace(required)) => {
let required = (-required)
.try_into()
.expect("Error buffer size is positive");
model.token_to_piece_bytes(token, required, true, None)
}
res => res,
}
.map_err(|e| anyhow!("Token conversion failed: {e}"))?;

let mut last_chunk = String::with_capacity(32);
let _ = decoder.decode_to_string(&token_bytes, &mut last_chunk, false);
Expand Down