I have a problem with the fact that when one of the users chatting with the AI, then the bot is not available for others and works with delays. Not only communicate with this, but the commands do not work
def gpt_talk(msg):
response = openai.Completion.create(
model="text-davinci-003",
prompt=msg,
temperature=0.9,
max_tokens=1000,
top_p=1,
frequency_penalty=0.0,
presence_penalty=0.6,
)
return response['choices'][0]['text']
@dp.message_handler() # Catches all messages except commands
async def chatting(message: types.Message):
usr_model = db.get_model(message.from_user.id)[0] # The selected AI model of the user
if usr_model == 1:
text = gpt_talk(msg)
elif usr_model == 2:
text = gpt_prog(msg)
await message.answer(text)
I tried to make an asynchronous queue (I hadn't worked with this before), but it ended up disastrously, throwing exceptions.
Perhaps there is already a similar solution? Should I go deep into asyncio in python? I will be grateful for any answer.
source https://stackoverflow.com/questions/75355391/async-problem-in-aiogram-bot-openai-api
Comments
Post a Comment