Hi,
Just creating a small thread for everyone to share any tips and tricks they would like to
let met start off:
Async Batch Processing
import asyncio
from openai import AsyncOpenAI
aclient = AsyncOpenAI()
async def process_prompt(prompt):
response = await aclient.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": prompt}],
)
return response.choices[0].message.content
async def main():
prompts = ["Explain quantum entanglement", "Summarize WW2", "Define monad"]
tasks = [process_prompt(prompt) for prompt in prompts]
results = await asyncio.gather(*tasks)
print(results)
asyncio.run(main())
Thank you