Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ZG4RBU committed Jan 21, 2024
1 parent c4fddc5 commit 2226790
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
38 changes: 30 additions & 8 deletions jiraiya/responses/response_quiz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand All @@ -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]
Expand Down Expand Up @@ -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))
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}")
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ discord
selenium
undetected_chromedriver
googletranslate
g4f
g4f
dotenv

0 comments on commit 2226790

Please sign in to comment.