Skip to content

Commit

Permalink
Merge pull request #19 from YeetCode-devs/staging/prathamdby
Browse files Browse the repository at this point in the history
  • Loading branch information
prathamdby authored Mar 26, 2024
2 parents c4df604 + 62d66b7 commit 6fac62e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 57 deletions.
8 changes: 5 additions & 3 deletions modules/ask.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
5 changes: 3 additions & 2 deletions src/Bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
7 changes: 3 additions & 4 deletions tests/test_bing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Copyright (c) 2024, YeetCode Developers <[email protected]>

from g4f.client import Client
from g4f.models import default
from g4f.models import gpt_4
from g4f.Provider import Bing


Expand All @@ -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):
Expand Down
48 changes: 0 additions & 48 deletions tests/test_freechatgpt.py

This file was deleted.

0 comments on commit 6fac62e

Please sign in to comment.