From b197ee086ccecc3005590afee0ff70ac9b325eb9 Mon Sep 17 00:00:00 2001 From: henri123lemoine Date: Fri, 31 Mar 2023 22:10:53 -0400 Subject: [PATCH] Big fix total_tokens --- api/chat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/chat.py b/api/chat.py index be2c1a2..4b570e0 100644 --- a/api/chat.py +++ b/api/chat.py @@ -65,8 +65,8 @@ def construct_prompt(query: str, history: List[Dict[str, str]], context: List[Bl instruction_context_query_prompt = f"{instruction_context_query_prompt}\n\n{context_prompt}\n\n{question_prompt}" total_tokens += len(enc.encode(past_queries_prompt)) - total_tokens += len(enc.encode(history[-2]["content"])) # Get past user query - total_tokens += len(enc.encode(history[-1]["content"])) + total_tokens += len(enc.encode(history[-2]["content"])) if (len(history) >= 2) else 0 + total_tokens += len(enc.encode(history[-1]["content"])) if (len(history) >= 1) else 0 total_tokens += len(enc.encode(instruction_context_query_prompt)) # If the prompt is too long, truncate the last answer