diff --git a/request_llms/bridge_chatgpt.py b/request_llms/bridge_chatgpt.py index 618a8e2d..897e6917 100644 --- a/request_llms/bridge_chatgpt.py +++ b/request_llms/bridge_chatgpt.py @@ -50,7 +50,8 @@ def make_multimodal_input(inputs, image_paths): def reverse_base64_from_input(inputs): # 定义一个正则表达式来匹配 Base64 字符串(假设格式为 base64="") - pattern = re.compile(r'base64="([^"]+)"') + # pattern = re.compile(r'base64="([^"]+)">') + pattern = re.compile(r'

]+base64="([^"]+)">
') # 使用 findall 方法查找所有匹配的 Base64 字符串 base64_strings = pattern.findall(inputs) # 返回反转后的 Base64 字符串列表 @@ -81,6 +82,14 @@ def append_image_if_contain_base64(inputs): }) return res +def remove_image_if_contain_base64(inputs): + if not contain_base64(inputs): + return inputs + else: + pattern = re.compile(r'

<]+>
') + inputs = re.sub(pattern, '', inputs) + return inputs + def decode_chunk(chunk): # 提前读取一些信息 (用于判断异常) chunk_decoded = chunk.decode() @@ -408,10 +417,10 @@ def generate_payload(inputs:str, llm_kwargs:dict, history:list, system_prompt:st for index in range(0, 2*conversation_cnt, 2): what_i_have_asked = {} what_i_have_asked["role"] = "user" - what_i_have_asked["content"] = history[index] + what_i_have_asked["content"] = remove_image_if_contain_base64(history[index]) what_gpt_answer = {} what_gpt_answer["role"] = "assistant" - what_gpt_answer["content"] = history[index+1] + what_gpt_answer["content"] = remove_image_if_contain_base64(history[index+1]) if what_i_have_asked["content"] != "": if what_gpt_answer["content"] == "": continue if what_gpt_answer["content"] == timeout_bot_msg: continue