From 9f7a85571ae80d3b6ddbd3e1bae407b9f1e3448a Mon Sep 17 00:00:00 2001 From: Andrei Betlen Date: Fri, 3 May 2024 19:07:50 -0400 Subject: [PATCH] fix: Use memmove to copy str_value kv_override. Closes #1417 --- llama_cpp/llama.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/llama_cpp/llama.py b/llama_cpp/llama.py index f927f0c..17576a6 100644 --- a/llama_cpp/llama.py +++ b/llama_cpp/llama.py @@ -262,7 +262,12 @@ class Llama: raise ValueError(f"Value for {k} is too long: {v}") v_bytes = v_bytes.ljust(128, b"\0") self._kv_overrides_array[i].tag = llama_cpp.LLAMA_KV_OVERRIDE_TYPE_STR - self._kv_overrides_array[i].value.str_value[:128] = v_bytes + # copy min(v_bytes, 128) to str_value + ctypes.memmove( + self._kv_overrides_array[i].value.str_value, + v_bytes, + min(len(v_bytes), 128), + ) else: raise ValueError(f"Unknown value type for {k}: {v}")