Skip to content

Commit

Permalink
update g4f version to 0.1.5.7 and gpt4free is compatible with Bing
Browse files Browse the repository at this point in the history
  • Loading branch information
yym68686 committed Oct 10, 2023
1 parent 4f0b5c1 commit 637deda
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
22 changes: 12 additions & 10 deletions gpt4free.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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"))
Expand All @@ -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='')
# for result in get_response(message, "claude-v2"):
print(bing(result), flush=True, end='')
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ unstructured[pdf]
duckduckgo-search==3.8.5
langchain==0.0.271
oauth2client==3.0.0
g4f==0.1.5.6
g4f==0.1.5.7

0 comments on commit 637deda

Please sign in to comment.