From 2226790e286e1272e5434e663285f9b0cd5b62fc Mon Sep 17 00:00:00 2001 From: Bijo Date: Sun, 21 Jan 2024 19:24:54 +0400 Subject: [PATCH] update --- jiraiya/responses/response_quiz.py | 38 +++++++++++++++++++++++------- requirements.txt | 3 ++- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/jiraiya/responses/response_quiz.py b/jiraiya/responses/response_quiz.py index abe2f50..8526190 100644 --- a/jiraiya/responses/response_quiz.py +++ b/jiraiya/responses/response_quiz.py @@ -4,14 +4,12 @@ -async def get_quiz(anime:str, message_lang:str) -> tuple[str]: +async def generate_quiz(anime:str) -> str: """ - Generate a challenging quiz question related to the specified anime. + Generate a quiz for the specified anime. - :param anime: The name of the anime for which the quiz question is generated. - :param message_lang: The language in which the quiz question will be presented. - - :return: A tuple containing the quiz question and the correct answer index. + :param anime: The name of the anime for which the quiz is generated. + :return: A string containing the quiz. """ quiz_prompt = f""" @@ -29,10 +27,26 @@ async def get_quiz(anime:str, message_lang:str) -> tuple[str]: try: # Generate quiz using GPT model - quiz = g4f.ChatCompletion.create(model='gpt-3.5-turbo', provider=g4f.Provider.DeepAi, messages=[ + quiz = await g4f.ChatCompletion.create_async(model='gpt-3.5-turbo', provider=g4f.Provider.GptGo, messages=[ {"role": "user", "content": quiz_prompt}]) except Exception as e: print(e) + + return quiz + + +async def get_quiz(anime:str, message_lang:str) -> tuple[str]: + """ + Generate a challenging quiz question related to the specified anime. + + :param anime: The name of the anime for which the quiz question is generated. + :param message_lang: The language in which the quiz question will be presented. + + :return: A tuple containing the quiz question and the correct answer index. + """ + + # Generate quiz using GPT model + quiz = await generate_quiz(anime) # Extract quiz elements from generated response question = quiz.split("[question]", 1)[-1].split("[question]", 1)[0] @@ -63,4 +77,12 @@ async def get_quiz(anime:str, message_lang:str) -> tuple[str]: # Construct final quiz question jiraiyas_response = f"{question}\n1. {a1}\n2. {a2}\n3. {a3}\n4. {a4}" - return (jiraiyas_response, str(correct_answer)) \ No newline at end of file + return (jiraiyas_response, str(correct_answer)) + + + +if __name__ == '__main__': + + # Generate quiz for Naruto anime + quiz = asyncio.run(generate_quiz(anime="Naruto")) + print(f"quiz: {quiz}") \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index a6adb99..2beb3b9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ discord selenium undetected_chromedriver googletranslate -g4f \ No newline at end of file +g4f +dotenv \ No newline at end of file