#Discord Bot Async Function Help

4 messages · Page 1 of 1 (latest)

zenith spear
#

I am writing a discord bot that uses the ChatGPT API, how do I write the ChatCompletion() function asynchronously? Right now it blocks the rest of the code from executing when a prompt takes a while to execute.

The function is currently an async function that gets awaited when ran, but the actual API call to the ChatCompletion.create() method is blocking.

Any assistance would be greatly appreciated, and I can share my code offline to a member of the support staff.

tribal quiver
# zenith spear I am writing a discord bot that uses the ChatGPT API, how do I write the ChatCom...

hey mate, it is quite some time since you wrote, but i am having nearly the same proplem right now.
as stated on the github repository you can make any function async by appending a "a" in front of the function (ChatCompletion.acreate() in this case)
the prblem i am facing right now is that i seem to not be able to retrieve the actual message that is generated this way... did you come across a solution for this? or someone else?

hollow grotto
#

The Discord API expects a somewhat instant response. You need to defer it to prevent it from "timing out" and returning with an error.