[object Object]

← back to Exo

only remove the matching prefix from the prompt if its length is less than the prompt

54ea5dbb5c5e75b4c13661ac4a7cd4e95032777b · 2024-08-02 11:11:16 +0100 · Alex Cheema

Files touched

Diff

commit 54ea5dbb5c5e75b4c13661ac4a7cd4e95032777b
Author: Alex Cheema <alexcheema123@gmail.com>
Date:   Fri Aug 2 11:11:16 2024 +0100

    only remove the matching prefix from the prompt if its length is less than the prompt
---
 exo/api/chatgpt_api.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/exo/api/chatgpt_api.py b/exo/api/chatgpt_api.py
index 8e7c44d0..cc4f1a15 100644
--- a/exo/api/chatgpt_api.py
+++ b/exo/api/chatgpt_api.py
@@ -309,11 +309,12 @@ class ChatGPTAPI:
     match = self.prompts.find_longest_prefix(prompt)
     if match:
         if DEBUG >= 2:
-            print(f"Prompt for request starts with previous prompt {len(match[1].prompt)} of {len(prompt)}: {match[1].prompt}")
+          print(f"Prompt for request starts with previous prompt {len(match[1].prompt)} of {len(prompt)}: {match[1].prompt}")
         request_id = match[1].request_id
         self.prompts.add(prompt, PromptSession(request_id=request_id, timestamp=int(time.time()), prompt=prompt))
-        # remove the matching prefix from the prompt
-        prompt = prompt[len(match[1].prompt):]
+        if len(match[1].prompt) < len(prompt):
+          # remove the matching prefix from the prompt
+          prompt = prompt[len(match[1].prompt):]
     else:
       request_id = str(uuid.uuid4())
       self.prompts.add(prompt, PromptSession(request_id=request_id, timestamp=int(time.time()), prompt=prompt))

← 67ad3f57 use llama 3.1 in tests  ·  back to Exo  ·  get rid of caches. circeci downloads fast enough 2a8f1ae4 →