You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: NLP chat inference with streaming and tool-call parsing - #1025
Implements ChatEngine for GGUF model chat inference via llama.cpp with streaming token generation
Adds StreamingToolCallParser for detecting Mistral-format [TOOL_CALLS] sentinels in streamed output
Includes GPU scheduling via tokio::sync::Mutex to prevent Metal command-buffer collisions
Fixes compilation errors: updated apply_chat_template call to use LlamaChatMessage + LlamaChatTemplate API (llama-cpp-2 v0.1.132), resolved borrow checker conflicts by splitting struct field borrows, and corrected a partial-sentinel test assertion
Test plan
cargo check -p nodespace-nlp-engine — zero errors, zero warnings
cargo test -p nodespace-nlp-engine — 41 unit tests + 11 integration tests all pass
The unsafe impl Send + Sync on ChatLlamaState follows the same pattern as the existing embedding service. The safety invariants are documented: the context is stored alongside the model, drop order is guaranteed, and access is serialized through Mutex. This is as safe as the existing pattern allows. If the embedding service pattern is ever revised, this should be updated in parallel.
[Improvement] uuid_v4_simple produces non-unique IDs under concurrent load
The function uses SystemTime::now().as_nanos() formatted as hex. Under the inference lock only one generation runs at a time, so within a single generation the IDs will be unique (nanosecond resolution). But if two separate ChatEngine instances generate simultaneously, IDs could collide. Since NodeSpace uses a single engine instance, this is fine in practice.
[Improvement] has_partial_sentinel_suffix has O(n*m) complexity
File: packages/nlp-engine/src/chat/parser.rs (around line 230)
The function checks every prefix length of both sentinels against the buffer suffix. For the current sentinel lengths (12 and 6 chars), this is ~18 iterations per token -- negligible. But if sentinels were ever longer or more numerous, this could become a hotspot. Current implementation is fine.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ChatEnginefor GGUF model chat inference via llama.cpp with streaming token generationStreamingToolCallParserfor detecting Mistral-format[TOOL_CALLS]sentinels in streamed outputtokio::sync::Mutexto prevent Metal command-buffer collisionsapply_chat_templatecall to useLlamaChatMessage+LlamaChatTemplateAPI (llama-cpp-2 v0.1.132), resolved borrow checker conflicts by splitting struct field borrows, and corrected a partial-sentinel test assertionTest plan
cargo check -p nodespace-nlp-engine— zero errors, zero warningscargo test -p nodespace-nlp-engine— 41 unit tests + 11 integration tests all passCloses #999