Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a411612

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

File tree

Expand file treeCollapse file tree

1 file changed

+8
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-1
lines changed

‎llama_cpp/llama.py

Copy file name to clipboardExpand all lines: llama_cpp/llama.py
+8-1Lines changed: 8 additions & 1 deletion
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.