From 8d1303d6e4a792787f7fd45173f51c1428a13d20 Mon Sep 17 00:00:00 2001 From: Meng Zhang Date: Thu, 30 Nov 2023 17:01:52 +0800 Subject: [PATCH] fix: properly recycle request id (#920) --- crates/llama-cpp-bindings/src/llama.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/llama-cpp-bindings/src/llama.rs b/crates/llama-cpp-bindings/src/llama.rs index ae2e035..15db135 100644 --- a/crates/llama-cpp-bindings/src/llama.rs +++ b/crates/llama-cpp-bindings/src/llama.rs @@ -38,7 +38,10 @@ impl LlamaServiceImpl { fn alloc_request_id(&mut self) -> u32 { let ret = self.next_request_id; - self.next_request_id += 1; + + // 1048576 (2^20) should be large enough to avoid any collision. + // FIXME(meng): figure out a better way. + self.next_request_id = (self.next_request_id + 1) % 1048576; ret }