I am trying to get a long article written via the gpt-3.5-turbo API (Completions) using PHP. So first I ask it to generate an outline for a topic and then I loop through the outline and ask it to elaborate on each and I intend to eventually combine them all into one article. But it always stops in the middle of the loop. In my script it mostly stops between 5th to 8th iteration, and via Postman, it stops after 2nd iteration. It never returns an error. I doubt its hitting the API rate limit because the outline is only about 20-40 points long usually and each response is of about 500 tokens.
Outline array:-
Array
(
[0] => Definition of ADHD
[1] => Prevalence and impact of ADHD
[2] => Common symptoms of ADHD
[3] => Diagnostic criteria for ADHD
[4] => Inattentive type
[5] => Hyperactive-impulsive type
[6] => Combined type
[7] => Genetic factors
[8] => Environmental factors
[9] => Brain structure and function
[10] => Anxiety disorders
[11] => Mood disorders
[12] => Learning disabilities
[13] => Medications for ADHD
[14] => Behavioral therapy
[15] => Support and accommodations
[16] => Organization and time management techniques
[17] => Exercise and physical activity
[18] => Mindfulness and stress reduction techniques
[19] => Challenges faced in academic settings
[20] => Strategies for success in school and work
[21] => Symptoms and challenges in adulthood
[22] => Strategies for managing ADHD as an adult
[23] => Support groups and organizations
[24] => Resources for individuals and families
)
Yes I tried usleep(500000); but its not making a difference. I have also tried 5 second delay and that didnât work either. By the way, I also tried doing it without a loop, it still stops after a few calls.
I tried not closing the connection inside loop and it still stops after exactly 6 iterations. Just so you know, each response is of about 500-600 tokens i.e around 350 words i.e. around 2500 characters (in case that matters). Here is a screenshot.
starting multiple processes at once in parallel (you need to keep track on overall tokens so you know when to stop spawning new processes).
Each process starts a symfony command with an id of the task encapsulated in a data transfer object so I can scale up once i get a higher tpm rate to get over 1000 processes per minute (running that on an apache server), which then calls a service which then uses multiple api connectors for multiple model deployments on azure (i am using that library openai-php/client there as well. But there is a timeout in case i am using multiple requests in one service - havnât figured out why either).
This is likely do to concurrent requests. At most you can have 5 concurrent requests, so on the 6th request it simply causes an error breaking out of the loop and stopping execution.
But its a loop, so it makes one curl request at a time, so how would it be concurrent?
And also, could you please confirm if this 5 concurrent requests limit is from the side of the API or if you are guessing that its from the side of my server?
Where in the documentation does it say this? I would be blown away if OpenAI only allows 5 âconcurrent requestsâ and also NOT return any error codes as the OP has indicated.
Now, Iâm being nitpicky but I think itâs fair to say that if someone is trying to open new connections and not closing them properly that can be an issue, but concurrent/parallel requests is commonly done.
Still. I am genuinely interested in this as well because I have a chatbot using a serverless stack and donât maintain connections when a different user sends a different message.
Just to clarify: Iâm not saying this isnât true (mainly because I think you meant to say concurrent connections). I just think saying âI confirmed itâ is as meaningful as Michael Scott âdeclaring bankruptcyâ
This is a question of your script hosting situation, not a question of OpenAI.
Given that you use PHP, I expect you run this from a web page, and the web server or proxy that runs this page, probably has a timeout for how long it allows your script to run.
The âopenai-php/clientâ library suggested above is what I am trying now and if that fails too, I will try your suggestion and will let you know how it works out.