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 22a776d

Browse filesBrowse files
committed
Add parameter for custom chat_handler to Llama class
1 parent 5091b9c commit 22a776d
Copy full SHA for 22a776d

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
@@ -752,6 +752,7 @@ def __init__(
752752
numa: bool = False,
753753
# Chat Format Params
754754
chat_format: str = "llama-2",
755+
chat_handler: Optional[llama_chat_format.LlamaChatCompletionHandler] = None,
755756
# Misc
756757
verbose: bool = True,
757758
# Extra Params
@@ -784,6 +785,7 @@ def __init__(
784785
lora_path: Path to a LoRA file to apply to the model.
785786
numa: Enable NUMA support. (NOTE: The initial value of this parameter is used for the remainder of the program as this value is set in llama_backend_init)
786787
chat_format: String specifying the chat format to use when calling create_chat_completion.
788+
chat_handler: Optional chat handler to use when calling create_chat_completion.
787789
verbose: Print verbose output to stderr.
788790
789791
Raises:
@@ -910,6 +912,7 @@ def __init__(
910912
print(llama_cpp.llama_print_system_info().decode("utf-8"), file=sys.stderr)
911913

912914
self.chat_format = chat_format
915+
self.chat_handler = chat_handler
913916

914917
self._n_vocab = self.n_vocab()
915918
self._n_ctx = self.n_ctx()
@@ -1918,7 +1921,9 @@ def create_chat_completion(
19181921
Returns:
19191922
Generated chat completion or a stream of chat completion chunks.
19201923
"""
1921-
handler = llama_chat_format.get_chat_completion_handler(self.chat_format)
1924+
handler = self.chat_handler or llama_chat_format.get_chat_completion_handler(
1925+
self.chat_format
1926+
)
19221927
return handler(
19231928
llama=self,
19241929
messages=messages,
@@ -1982,6 +1987,7 @@ def __getstate__(self):
19821987
numa=self.numa,
19831988
# Chat Format Params
19841989
chat_format=self.chat_format,
1990+
chat_handler=self.chat_handler,
19851991
# Misc
19861992
verbose=self.verbose,
19871993
)
@@ -2023,6 +2029,7 @@ def __setstate__(self, state):
20232029
numa=state["numa"],
20242030
# Chat Format Params
20252031
chat_format=state["chat_format"],
2032+
chat_handler=state["chat_handler"],
20262033
# Misc
20272034
verbose=state["verbose"],
20282035
)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.