“cURL error 6: Could not resolve host: api.openai.com (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://api.openai.com/v1/chat/completions”
I do curl with PHP. The problem is not that the site is slow - it only takes the API a very long time to finish. So, if you are not using the stream feature, you have to wait until the end. That can result even in server timeouts. In that case, increase your time limits in the php.ini and the timeout in your Apache server settings.
Something like this could help:
// Start streaming response
curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($curl, $chunk) {
echo $chunk; // output received data to client
return strlen($chunk); // return length of received data
});
I think many often people confuse network delays and data center congestion, etc with API performance.
For example, I am 12 time zones away from the US and call the OpenAI completion API, and here are the results when I time the call:
text-davinci-003
Test 1: Completions.get_reply Time: 1.247792 secs
Test 2: Completions.get_reply Time: 5.038783 secs
Test 3: Completions.get_reply Time: 1.289555 secs
Test 4: Completions.get_reply Time: 2.205132 secs
Kindly keep in mind that I am testing OpenAI APIs from the opposite side of the world than the US.
Also, if I repeat for other models, the results are similar. It’s mostly network traffic issues, not model issues, from my experience.
Having said that, lately I have noticed that text-davinci-002 is about 0.5 seconds faster than text-davinci-003 (for the same prompt), but did not test extensively.
I used text-davinci-003 before and the average response was 0.5-0.8s. But because of the price it is high.
I have to use the gpt-3.5-turbo-0301 or gpt-3.5-turbo model to reduce the cost but it has the problem of slow processing time.
Test 1, Completion API Time: 1.529 seconds
Test 2. Completion API Time: 2.504 seconds
Test 3. Completion API Time: 1.557 seconds
Test 4. Completion API Time: 1.513 seconds
Test 5. Completion API Time: 1.505 seconds
import openai
openai.api_key = "sk-..."
completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "Tell the world about the ChatGPT API in the style of a pirate."}]
)
print(completion)