diff --git a/modules/ask.py b/modules/ask.py index 3c40533..107c2c1 100644 --- a/modules/ask.py +++ b/modules/ask.py @@ -21,7 +21,7 @@ import random from g4f.client import Client as g4fClient -from g4f.models import default +from g4f.models import gpt_4 from g4f.Provider import Bing, FreeChatgpt, RetryProvider, You from g4f.stubs import ChatCompletion from pyrogram import filters @@ -81,7 +81,7 @@ async def generate_response(user_prompts: list[dict[str, str]]) -> str: None, client.chat.completions.create, resultant_prompt, - default, + gpt_4, ) return response.choices[0].message.content except Exception as e: @@ -111,5 +111,7 @@ async def cmd_ask(app: Client, message: Message): previous_prompts.reverse() previous_prompts.append({"role": "user", "content": message.text}) + to_edit = await message.reply("Generating response...", reply_to_message_id=message.id) + response: str = await generate_response(previous_prompts) - await message.reply(response) + await to_edit.edit_text(response) diff --git a/src/Bot.py b/src/Bot.py index 812c259..36d510d 100644 --- a/src/Bot.py +++ b/src/Bot.py @@ -44,8 +44,9 @@ def main() -> None: default_event_loop_policy = asyncio.get_event_loop_policy() import g4f # Trigger g4f event loop policy set # noqa: F401 # pylint: disable=unused-import # isort:skip - if isinstance(asyncio.get_event_loop_policy(), asyncio.WindowsSelectorEventLoopPolicy): - asyncio.set_event_loop_policy(default_event_loop_policy) + if hasattr(asyncio, "WindowsSelectorEventLoopPolicy"): + if isinstance(asyncio.get_event_loop_policy(), asyncio.WindowsSelectorEventLoopPolicy): + asyncio.set_event_loop_policy(default_event_loop_policy) loaded_modules = load_modules(app) app.run() diff --git a/tests/test_bing.py b/tests/test_bing.py index 62e5026..161e983 100644 --- a/tests/test_bing.py +++ b/tests/test_bing.py @@ -15,7 +15,7 @@ # Copyright (c) 2024, YeetCode Developers from g4f.client import Client -from g4f.models import default +from g4f.models import gpt_4 from g4f.Provider import Bing @@ -24,17 +24,16 @@ def generate_response() -> str: try: response = client.chat.completions.create( - model=default, + model=gpt_4, messages=[ {"role": "user", "content": "Say hi, with your response starting with START and ending with END"} ], ) + return response.choices[0].message.content except: print("ERROR: Could not create a prompt!") raise - return response.choices[0].message.content - class TestOutput: def test_output(self): diff --git a/tests/test_freechatgpt.py b/tests/test_freechatgpt.py deleted file mode 100644 index b4ea2d9..0000000 --- a/tests/test_freechatgpt.py +++ /dev/null @@ -1,48 +0,0 @@ -# SPDX-License-Identifier: GPL-3.0-only -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, version 3 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Copyright (c) 2024, YeetCode Developers - -from g4f.client import Client -from g4f.models import default -from g4f.Provider import FreeChatgpt - - -def generate_response() -> str: - client = Client(provider=FreeChatgpt) - - try: - response = client.chat.completions.create( - model=default, - messages=[ - {"role": "user", "content": "Say hi, with your response starting with START and ending with END"} - ], - ) - except: - print("ERROR: Could not create a prompt!") - raise - - return response.choices[0].message.content - - -class TestOutput: - def test_output(self): - response = generate_response() - - if len(response) > 0: - print("✅ FreeChatgpt is up!") - else: - print("❌ FreeChatgpt is down...") - - assert response.startswith("START") and response.endswith("END")