From a210e61df1a32b8716841d4f26a19ceaaf40d5fa Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Thu, 4 Jul 2024 20:30:27 -0700 Subject: [PATCH 1/2] UI: Fix broken chat histories not showing (closes #6196) --- modules/chat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/chat.py b/modules/chat.py index 920c0f7b..6640776f 100644 --- a/modules/chat.py +++ b/modules/chat.py @@ -577,7 +577,7 @@ def find_all_histories_with_first_prompts(state): data = json.load(f) first_prompt = "" - if 'visible' in data and len(data['visible']) > 0: + if data and 'visible' in data and len(data['visible']) > 0: if data['internal'][0][0] == '<|BEGIN-VISIBLE-CHAT|>': if len(data['visible']) > 1: first_prompt = html.unescape(data['visible'][1][0]) From aa653e3b5af8a9a977c75cd55f4cbc843405da7e Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Fri, 5 Jul 2024 03:34:15 -0700 Subject: [PATCH 2/2] Prevent llama.cpp from being monkey patched more than once (closes #6201) --- modules/llama_cpp_python_hijack.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/llama_cpp_python_hijack.py b/modules/llama_cpp_python_hijack.py index f3f3f560..c9813708 100644 --- a/modules/llama_cpp_python_hijack.py +++ b/modules/llama_cpp_python_hijack.py @@ -100,9 +100,11 @@ def eval_with_progress(self, tokens: Sequence[int]): def monkey_patch_llama_cpp_python(lib): + if getattr(lib.Llama, '_is_patched', False): + # If the patch is already applied, do nothing + return def my_generate(self, *args, **kwargs): - if shared.args.streaming_llm: new_sequence = args[0] past_sequence = self._input_ids @@ -116,3 +118,6 @@ def monkey_patch_llama_cpp_python(lib): lib.Llama.eval = eval_with_progress lib.Llama.original_generate = lib.Llama.generate lib.Llama.generate = my_generate + + # Set the flag to indicate that the patch has been applied + lib.Llama._is_patched = True