чтобы все слайды обрабатывались одновременно.
это код из основной функции async:
Код: Выделить всё
for prompt in prompted_slides_text:
task = asyncio.create_task(api_manager.generate_answer(prompt))
tasks.append(task)
results = await asyncio.gather(*tasks)
Код: Выделить всё
@staticmethod
async def generate_answer(prompt):
"""
Send a prompt to OpenAI API and get the answer.
:param prompt: the prompt to send.
:return: the answer.
"""
completion = await openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": prompt}]
)
return completion.choices[0].message.content
объект OpenAIObject нельзя использовать в выражении ожидания
и я не знаю, как дождаться ответа в функции генерации_ответа.
Буду признателен за любую помощь!
Подробнее здесь: https://stackoverflow.com/questions/763 ... -api-calls