[object Object]

← back to Exo

prefix matching logic

96969e35405981caffd79deebd33600fec29520e · 2024-08-02 11:28:48 +0100 · Alex Cheema

Files touched

Diff

commit 96969e35405981caffd79deebd33600fec29520e
Author: Alex Cheema <alexcheema123@gmail.com>
Date:   Fri Aug 2 11:28:48 2024 +0100

    prefix matching logic
---
 exo/api/chatgpt_api.py | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/exo/api/chatgpt_api.py b/exo/api/chatgpt_api.py
index cc4f1a15..87390b7f 100644
--- a/exo/api/chatgpt_api.py
+++ b/exo/api/chatgpt_api.py
@@ -307,14 +307,13 @@ class ChatGPTAPI:
     prompt, image_str = build_prompt(tokenizer, chat_request.messages)
     request_id = None
     match = self.prompts.find_longest_prefix(prompt)
-    if match:
+    if match and len(prompt) > len(match[1].prompt):
         if DEBUG >= 2:
           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))
-        if len(match[1].prompt) < len(prompt):
-          # remove the matching prefix from the prompt
-          prompt = prompt[len(match[1].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))

← 7c092327 trigger circleci  ·  back to Exo  ·  replace tests badge with circleci f4b0f1ca →