From c62043309e3f2ad94c89b1067bb9375b005c1f0e Mon Sep 17 00:00:00 2001 From: Mohamad Zamini <32536264+mzamini92@users.noreply.github.com> Date: Tue, 8 Aug 2023 18:16:58 -0600 Subject: [PATCH] Update tool_llama_lora_model.py In the `parse` method, you can preallocate memory for the prompt string using the `join` method. This can improve the efficiency of string concatenation --- toolbench/inference/LLM/tool_llama_lora_model.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/toolbench/inference/LLM/tool_llama_lora_model.py b/toolbench/inference/LLM/tool_llama_lora_model.py index a04b1fc..2c5df1b 100644 --- a/toolbench/inference/LLM/tool_llama_lora_model.py +++ b/toolbench/inference/LLM/tool_llama_lora_model.py @@ -93,13 +93,15 @@ def parse(self,functions,process_id,**args): self.time = time.time() conversation_history = self.conversation_history prompt = '' + prompt_parts = [] for message in conversation_history: role = roles[message['role']] content = message['content'] if role == "System" and functions != []: content = process_system_message(content, functions) - prompt += f"{role}: {content}\n" - prompt += "Assistant:\n" + prompt_parts.append(f"{role}: {content}") + prompt = '\n'.join(prompt_parts) + "\nAssistant:\n" + if functions != []: predictions = self.prediction(prompt) else: @@ -138,4 +140,4 @@ def parse(self,functions,process_id,**args): llm.change_messages(messages) output = llm.parse(functions=functions) - print(output) \ No newline at end of file + print(output)