Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a411612

Browse files
committed
feat: Add support for str type kv_overrides
1 parent c9b85bf commit a411612

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

llama_cpp/llama.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def __init__(
7373
vocab_only: bool = False,
7474
use_mmap: bool = True,
7575
use_mlock: bool = False,
76-
kv_overrides: Optional[Dict[str, Union[bool, int, float]]] = None,
76+
kv_overrides: Optional[Dict[str, Union[bool, int, float, str]]] = None,
7777
# Context Params
7878
seed: int = llama_cpp.LLAMA_DEFAULT_SEED,
7979
n_ctx: int = 512,
@@ -254,6 +254,13 @@ def __init__(
254254
elif isinstance(v, float):
255255
self._kv_overrides_array[i].tag = llama_cpp.LLAMA_KV_OVERRIDE_TYPE_FLOAT
256256
self._kv_overrides_array[i].value.float_value = v
257+
elif isinstance(v, str): # type: ignore
258+
v_bytes = v.encode("utf-8")
259+
if len(v_bytes) > 128: # TODO: Make this a constant
260+
raise ValueError(f"Value for {k} is too long: {v}")
261+
v_bytes = v_bytes.ljust(128, b"\0")
262+
self._kv_overrides_array[i].tag = llama_cpp.LLAMA_KV_OVERRIDE_TYPE_STR
263+
self._kv_overrides_array[i].value.str_value[:128] = v_bytes
257264
else:
258265
raise ValueError(f"Unknown value type for {k}: {v}")
259266

0 commit comments

Comments
 (0)