From f1a629f45a4f88b0edd9a0fc7daf6db3035a841b Mon Sep 17 00:00:00 2001 From: Junyan Qin <1010553892@qq.com> Date: Mon, 12 Feb 2024 15:14:56 +0000 Subject: [PATCH] fix: fix filter not work with Chinese --- free_one_api/impls/adapter/revChatGPT.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/free_one_api/impls/adapter/revChatGPT.py b/free_one_api/impls/adapter/revChatGPT.py index 7cd43bb..d150394 100644 --- a/free_one_api/impls/adapter/revChatGPT.py +++ b/free_one_api/impls/adapter/revChatGPT.py @@ -2,6 +2,7 @@ import traceback import uuid import random +import logging import revChatGPT.V1 as chatgpt @@ -161,6 +162,8 @@ async def query(self, req: request.Request) -> typing.AsyncGenerator[response.Re } }) + logging.debug(f'assistant_messages: {assistant_messages}') + random_int = random.randint(0, 1000000000) prev_text = "" @@ -172,17 +175,19 @@ async def query(self, req: request.Request) -> typing.AsyncGenerator[response.Re messages=new_messages, ): message = data["message"][len(prev_text):] - prev_text = data["message"] - conversation_id = data["conversation_id"] + + if not message: + continue # skip if: - # 1. more than two spaces contained in the message - # and 2. message in any elements of the assistant messages - # and 3. auto_ignore_duplicated is True - if message.count(" ") >= 2 and \ - any([message in msg for msg in assistant_messages]) and \ + # 1. message in any elements of the income assistant messages + # and 2. auto_ignore_duplicated is True + if any([message == msg for msg in assistant_messages]) and \ self.auto_ignore_duplicated: continue + + prev_text = data["message"] if prev_text in data["message"] else prev_text + conversation_id = data["conversation_id"] yield response.Response( id=random_int,