From b732ea268dca6b89aea165b53ee3626124b0052f Mon Sep 17 00:00:00 2001 From: Ziyi Zhang Date: Thu, 11 Jan 2024 23:06:17 +1100 Subject: [PATCH] Fix last_content_without_template Fix last_content_without_template when the template looks like "Tell me a joke about {subject} with less than 50 words." where len(field_name_arr) < len(literal_text_arr). --- gptcache/processor/pre.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gptcache/processor/pre.py b/gptcache/processor/pre.py index 59db670c..7028c430 100644 --- a/gptcache/processor/pre.py +++ b/gptcache/processor/pre.py @@ -60,7 +60,7 @@ def _get_pattern_value(pattern_str: str, value_str: str): pattern_values = {} last_end = 0 - for i, literal_text in enumerate(literal_text_arr): + for i, (literal_text, field_name) in enumerate(zip(literal_text_arr, field_name_arr)): start = value_str.find(literal_text, last_end) if i == len(literal_text_arr) - 1: end = len(value_str) @@ -69,7 +69,7 @@ def _get_pattern_value(pattern_str: str, value_str: str): if start == -1 or end == -1: break start += len(literal_text) - pattern_values[field_name_arr[i]] = value_str[start:end] + pattern_values[field_name] = value_str[start:end] last_end = end return pattern_values