Skip to content

Commit f5ec065

Browse files
committed
Optimize multi-user multi-thread search logic.
1 parent e4ef199 commit f5ec065

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

utils/chatgpt2api.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def __init__(
335335
}
336336
self.function_calls_counter = {}
337337
self.function_call_max_loop = 3
338-
self.encode_web_text_list = []
338+
# self.encode_web_text_list = []
339339

340340
if self.get_token_count("default") > self.max_tokens:
341341
raise t.ActionRefuseError("System prompt is too long")
@@ -621,11 +621,16 @@ def ask_stream(
621621
break
622622
tiktoken.get_encoding("cl100k_base")
623623
encoding = tiktoken.encoding_for_model(config.GPT_ENGINE)
624-
if self.encode_web_text_list == []:
625-
self.encode_web_text_list = encoding.encode(" ".join(get_url_text_list(prompt)))
626-
print("search len", len(self.encode_web_text_list))
627-
function_response = encoding.decode(self.encode_web_text_list[:function_call_max_tokens])
628-
self.encode_web_text_list = self.encode_web_text_list[function_call_max_tokens:]
624+
625+
encode_web_text_list = encoding.encode(" ".join(get_url_text_list(prompt)))
626+
print("search len", len(encode_web_text_list))
627+
function_response = encoding.decode(encode_web_text_list[:function_call_max_tokens])
628+
# if self.encode_web_text_list == []:
629+
# self.encode_web_text_list = encoding.encode(" ".join(get_url_text_list(prompt)))
630+
# print("search len", len(self.encode_web_text_list))
631+
# function_response = encoding.decode(self.encode_web_text_list[:function_call_max_tokens])
632+
# self.encode_web_text_list = self.encode_web_text_list[function_call_max_tokens:]
633+
629634
# function_response = eval(function_call_name)(prompt, function_call_max_tokens)
630635
function_response = (
631636
"Here is the Search results, inside <Search_results></Search_results> XML tags:"
@@ -654,7 +659,7 @@ def ask_stream(
654659
self.add_to_conversation(full_response, response_role, convo_id=convo_id)
655660
self.function_calls_counter = {}
656661
# self.clear_function_call(convo_id=convo_id)
657-
self.encode_web_text_list = []
662+
# self.encode_web_text_list = []
658663
# total_tokens = self.get_token_count(convo_id)
659664

660665
async def ask_stream_async(

0 commit comments

Comments
 (0)