diff --git a/bot.py b/bot.py index 42b955cd..3c6f0bc2 100644 --- a/bot.py +++ b/bot.py @@ -121,6 +121,7 @@ async def getChatGPT(update, context, title, robot, message, use_search=config.S result = f"`🤖️ {config.GPT_ENGINE}`\n\n" import gpt4free tmpresult = await gpt4free.get_async_response(text, config.GPT_ENGINE) + tmpresult = gpt4free.bing(tmpresult) result = result + tmpresult await context.bot.edit_message_text(chat_id=update.message.chat_id, message_id=messageid, text=escape(result), parse_mode='MarkdownV2', disable_web_page_preview=True) lastresult = result @@ -384,7 +385,6 @@ async def button_press(update, context): ) elif "gpt4free" in data: config.USE_G4F = not config.USE_G4F - print(config.USE_G4F) if config.USE_G4F == False: first_buttons[3][0] = InlineKeyboardButton("gpt4free已关闭", callback_data="gpt4free") else: diff --git a/gpt4free.py b/gpt4free.py index 26d6c733..9b8d280e 100644 --- a/gpt4free.py +++ b/gpt4free.py @@ -1,4 +1,5 @@ import g4f +import re async def get_async_response(message, model="gpt-3.5-turbo"): response = await g4f.ChatCompletion.create_async( model=model, @@ -28,18 +29,18 @@ def get_response(message, model="gpt-3.5-turbo"): # def handle_response(response): # yield response +def bing(response): + response = re.sub(r"\[\^\d+\^\]", "", response) + if len(response.split("\n\n")) >= 2: + result = "\n\n".join(response.split("\n\n")[1:]) + return result + else: + return response + if __name__ == "__main__": import asyncio message = r""" -在多线程编程场景下,为了避免There is no current event loop in thread错误,怎么使用回调函数返回这个函数的结果: -def get_response(message, model="gpt-3.5-turbo"): - response = g4f.ChatCompletion.create( - model=model, - messages=[{"role": "user", "content": message}], - stream=True, - ) - for message in response: - yield message + """ # result = asyncio.run(get_response(message, "gpt-4")) @@ -48,4 +49,5 @@ def get_response(message, model="gpt-3.5-turbo"): # for result in get_response(message, handle_response): # print(result, flush=True, end='') for result in get_response(message, "gpt-4"): - print(result, flush=True, end='') \ No newline at end of file + # for result in get_response(message, "claude-v2"): + print(bing(result), flush=True, end='') \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index de424f2e..999b24fa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,4 +16,4 @@ unstructured[pdf] duckduckgo-search==3.8.5 langchain==0.0.271 oauth2client==3.0.0 -g4f==0.1.5.6 \ No newline at end of file +g4f==0.1.5.7 \ No newline at end of file