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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

### Fixed

- fix(ml): rubato 1.0.1 API upgrade and StreamChunk wrapping for candle provider (#1858) — updated `candle_whisper.rs` resample function for rubato 1.0.1 (SincFixedIn removed, replaced with Async::new_sinc); wrapped ChatStream output in StreamChunk::Content pattern in candle_provider; added audioadapter-buffers dependency (gated on candle feature)

### Performance

- perf(memory): add `expires_at` to `idx_response_cache_semantic` composite index (migration 038) — `get_semantic()` now filters expired rows within the index scan instead of post-filtering on the heap (#2030)
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ ratatui = "0.30"
regex = "1.12"
reqwest = { version = "0.13", default-features = false }
rmcp = "1.2"
audioadapter-buffers = "2.0"
rubato = "1.0"
schemars = "1.2"
scrape-core = "0.2"
Expand Down
3 changes: 2 additions & 1 deletion crates/zeph-llm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ readme = "README.md"
default = ["schema"]
schema = ["dep:schemars"]
stt = ["reqwest/multipart"]
candle = ["dep:candle-core", "dep:candle-nn", "dep:candle-transformers", "dep:hf-hub", "dep:tokenizers", "dep:symphonia", "dep:rubato"]
candle = ["dep:audioadapter-buffers", "dep:candle-core", "dep:candle-nn", "dep:candle-transformers", "dep:hf-hub", "dep:tokenizers", "dep:symphonia", "dep:rubato"]
cuda = ["candle", "candle-core/cuda", "candle-nn/cuda", "candle-transformers/cuda"]
metal = ["candle", "candle-core/metal", "candle-nn/metal", "candle-transformers/metal"]

[dependencies]
async-stream.workspace = true
audioadapter-buffers = { workspace = true, optional = true }
base64.workspace = true
candle-core = { workspace = true, optional = true }
candle-nn = { workspace = true, optional = true }
Expand Down
5 changes: 3 additions & 2 deletions crates/zeph-llm/src/candle_provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use self::embed::EmbedModel;
use self::generate::{GenerationConfig, GenerationOutput, generate_tokens};
use self::loader::{LoadedModel, ModelSource, load_chat_model};
use self::template::ChatTemplate;
use crate::provider::{ChatStream, LlmProvider, Message};
use crate::provider::{ChatStream, LlmProvider, Message, StreamChunk};

use candle_transformers::models::quantized_llama::ModelWeights;

Expand Down Expand Up @@ -146,7 +146,8 @@ impl LlmProvider for CandleProvider {
while !text.is_char_boundary(end) {
end -= 1;
}
if tx.blocking_send(Ok(text[start..end].to_string())).is_err() {
let chunk = StreamChunk::Content(text[start..end].to_string());
if tx.blocking_send(Ok(chunk)).is_err() {
break;
}
start = end;
Expand Down
15 changes: 10 additions & 5 deletions crates/zeph-llm/src/candle_whisper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ fn decode_audio(bytes: &[u8]) -> Result<Vec<f32>, LlmError> {

fn resample(input: &[f32], from_rate: u32, to_rate: u32) -> Result<Vec<f32>, LlmError> {
use rubato::{
Resampler, SincFixedIn, SincInterpolationParameters, SincInterpolationType, WindowFunction,
Async, FixedAsync, Resampler, SincInterpolationParameters, SincInterpolationType,
WindowFunction,
};

let params = SincInterpolationParameters {
Expand All @@ -330,14 +331,18 @@ fn resample(input: &[f32], from_rate: u32, to_rate: u32) -> Result<Vec<f32>, Llm
};

let ratio = f64::from(to_rate) / f64::from(from_rate);
let mut resampler = SincFixedIn::<f32>::new(ratio, 2.0, params, input.len(), 1)
.map_err(|e| LlmError::TranscriptionFailed(format!("resampler init: {e}")))?;
let mut resampler =
Async::<f32>::new_sinc(ratio, 2.0, &params, input.len(), 1, FixedAsync::Input)
.map_err(|e| LlmError::TranscriptionFailed(format!("resampler init: {e}")))?;

let input_adapter = audioadapter_buffers::direct::InterleavedSlice::new(input, 1, input.len())
.map_err(|e| LlmError::TranscriptionFailed(format!("input buffer: {e}")))?;

let output = resampler
.process(&[input], None)
.process(&input_adapter, 0, None)
.map_err(|e| LlmError::TranscriptionFailed(format!("resample: {e}")))?;

Ok(output.into_iter().next().unwrap_or_default())
Ok(output.take_data())
}

#[cfg(test)]
Expand Down
Loading