Can't access gpt-4 model via python API although gpt-3.5 works
Question:
I’m able to use the gpt-3.5-turbo-0301 model to access the ChatGPT API, but not any of the gpt-4 models. Here is the code I am using to test this (it excludes my openai API key). The code runs as written, but when I replace "gpt-3.5-turbo-0301" with "gpt-4", "gpt-4-0314", or "gpt-4-32k-0314", it gives me an error "openai.error.InvalidRequestError: The model: gpt-4
does not exist". I have a ChatGPT+ subscription, am using my own API key, and can use gpt-4 successfully via OpenAI’s own interface.
It’s the same error if I use gpt-4-0314 or gpt-4-32k-0314. I’ve seen a couple articles claiming this or similar code works using ‘gpt-4’ works as the model specification, and the code I pasted below is from one of them. Does anybody know if it’s possible to access the gpt-4 model via Python + API, and if so, how do you do it?
openai_key = "sk..."
openai.api_key = openai_key
system_intel = "You are GPT-4, answer my questions as if you were an expert in the field."
prompt = "Write a blog on how to use GPT-4 with python in a jupyter notebook"
# Function that calls the GPT-4 API
def ask_GPT4(system_intel, prompt):
result = openai.ChatCompletion.create(model="gpt-3.5-turbo-0301",
messages=[{"role": "system", "content": system_intel},
{"role": "user", "content": prompt}])
print(result['choices'][0]['message']['content'])
# Call the function above
ask_GPT4(system_intel, prompt)
Answers:
Currently the GPT 4
API is restricted, Even to users with a Chat GPT + subscription.
You may need to join the Waitlist for the API.
I’ll add to Crypto‘s answer that gpt-4-32k-0314
is not accessible yet. Currently, only the 8k GPT-4 models are available:
One can list all available models as follows (run pip install openai
first):
# Author: Viet Dac Lai
import openai
import pprint
openai.organization = "org-insertorgIDhere"
openai.api_key = "sk-insertyourkeyhere"
GPT4 = 'gpt-4-0314'
MODEL_NAME = GPT4
model = openai.Model(MODEL_NAME)
def list_all_models():
model_list = openai.Model.list()['data']
model_ids = [x['id'] for x in model_list]
model_ids.sort()
pprint.pprint(model_ids)
if __name__ == '__main__':
list_all_models()
Output on 2023-03-18 if no GPT-4 access:
['ada',
'ada-code-search-code',
'ada-code-search-text',
'ada-search-document',
'ada-search-query',
'ada-similarity',
'ada:2020-05-03',
'babbage',
'babbage-code-search-code',
'babbage-code-search-text',
'babbage-search-document',
'babbage-search-query',
'babbage-similarity',
'babbage:2020-05-03',
'code-cushman-001',
'code-davinci-002',
'code-davinci-edit-001',
'code-search-ada-code-001',
'code-search-ada-text-001',
'code-search-babbage-code-001',
'code-search-babbage-text-001',
'curie',
'curie-instruct-beta',
'curie-search-document',
'curie-search-query',
'curie-similarity',
'curie:2020-05-03',
'cushman:2020-05-03',
'davinci',
'davinci-if:3.0.0',
'davinci-instruct-beta',
'davinci-instruct-beta:2.0.0',
'davinci-search-document',
'davinci-search-query',
'davinci-similarity',
'davinci:2020-05-03',
'gpt-3.5-turbo',
'gpt-3.5-turbo-0301',
'if-curie-v2',
'if-davinci-v2',
'if-davinci:3.0.0',
'text-ada-001',
'text-ada:001',
'text-babbage-001',
'text-babbage:001',
'text-curie-001',
'text-curie:001',
'text-davinci-001',
'text-davinci-002',
'text-davinci-003',
'text-davinci-edit-001',
'text-davinci-insert-001',
'text-davinci-insert-002',
'text-davinci:001',
'text-embedding-ada-002',
'text-search-ada-doc-001',
'text-search-ada-query-001',
'text-search-babbage-doc-001',
'text-search-babbage-query-001',
'text-search-curie-doc-001',
'text-search-curie-query-001',
'text-search-davinci-doc-001',
'text-search-davinci-query-001',
'text-similarity-ada-001',
'text-similarity-babbage-001',
'text-similarity-curie-001',
'text-similarity-davinci-001',
'whisper-1']
If one has access to GPT-4, the following two models will be added to the list:
'gpt-4',
'gpt-4-0314',
Note that the access to GPT-4 is tied to both the OpenAI account and the organization ID (on https://openai.com/waitlist/gpt-4-api, one of the fields is the Organization ID).
I’m able to use the gpt-3.5-turbo-0301 model to access the ChatGPT API, but not any of the gpt-4 models. Here is the code I am using to test this (it excludes my openai API key). The code runs as written, but when I replace "gpt-3.5-turbo-0301" with "gpt-4", "gpt-4-0314", or "gpt-4-32k-0314", it gives me an error "openai.error.InvalidRequestError: The model: gpt-4
does not exist". I have a ChatGPT+ subscription, am using my own API key, and can use gpt-4 successfully via OpenAI’s own interface.
It’s the same error if I use gpt-4-0314 or gpt-4-32k-0314. I’ve seen a couple articles claiming this or similar code works using ‘gpt-4’ works as the model specification, and the code I pasted below is from one of them. Does anybody know if it’s possible to access the gpt-4 model via Python + API, and if so, how do you do it?
openai_key = "sk..."
openai.api_key = openai_key
system_intel = "You are GPT-4, answer my questions as if you were an expert in the field."
prompt = "Write a blog on how to use GPT-4 with python in a jupyter notebook"
# Function that calls the GPT-4 API
def ask_GPT4(system_intel, prompt):
result = openai.ChatCompletion.create(model="gpt-3.5-turbo-0301",
messages=[{"role": "system", "content": system_intel},
{"role": "user", "content": prompt}])
print(result['choices'][0]['message']['content'])
# Call the function above
ask_GPT4(system_intel, prompt)
Currently the GPT 4
API is restricted, Even to users with a Chat GPT + subscription.
You may need to join the Waitlist for the API.
I’ll add to Crypto‘s answer that gpt-4-32k-0314
is not accessible yet. Currently, only the 8k GPT-4 models are available:
One can list all available models as follows (run pip install openai
first):
# Author: Viet Dac Lai
import openai
import pprint
openai.organization = "org-insertorgIDhere"
openai.api_key = "sk-insertyourkeyhere"
GPT4 = 'gpt-4-0314'
MODEL_NAME = GPT4
model = openai.Model(MODEL_NAME)
def list_all_models():
model_list = openai.Model.list()['data']
model_ids = [x['id'] for x in model_list]
model_ids.sort()
pprint.pprint(model_ids)
if __name__ == '__main__':
list_all_models()
Output on 2023-03-18 if no GPT-4 access:
['ada',
'ada-code-search-code',
'ada-code-search-text',
'ada-search-document',
'ada-search-query',
'ada-similarity',
'ada:2020-05-03',
'babbage',
'babbage-code-search-code',
'babbage-code-search-text',
'babbage-search-document',
'babbage-search-query',
'babbage-similarity',
'babbage:2020-05-03',
'code-cushman-001',
'code-davinci-002',
'code-davinci-edit-001',
'code-search-ada-code-001',
'code-search-ada-text-001',
'code-search-babbage-code-001',
'code-search-babbage-text-001',
'curie',
'curie-instruct-beta',
'curie-search-document',
'curie-search-query',
'curie-similarity',
'curie:2020-05-03',
'cushman:2020-05-03',
'davinci',
'davinci-if:3.0.0',
'davinci-instruct-beta',
'davinci-instruct-beta:2.0.0',
'davinci-search-document',
'davinci-search-query',
'davinci-similarity',
'davinci:2020-05-03',
'gpt-3.5-turbo',
'gpt-3.5-turbo-0301',
'if-curie-v2',
'if-davinci-v2',
'if-davinci:3.0.0',
'text-ada-001',
'text-ada:001',
'text-babbage-001',
'text-babbage:001',
'text-curie-001',
'text-curie:001',
'text-davinci-001',
'text-davinci-002',
'text-davinci-003',
'text-davinci-edit-001',
'text-davinci-insert-001',
'text-davinci-insert-002',
'text-davinci:001',
'text-embedding-ada-002',
'text-search-ada-doc-001',
'text-search-ada-query-001',
'text-search-babbage-doc-001',
'text-search-babbage-query-001',
'text-search-curie-doc-001',
'text-search-curie-query-001',
'text-search-davinci-doc-001',
'text-search-davinci-query-001',
'text-similarity-ada-001',
'text-similarity-babbage-001',
'text-similarity-curie-001',
'text-similarity-davinci-001',
'whisper-1']
If one has access to GPT-4, the following two models will be added to the list:
'gpt-4',
'gpt-4-0314',
Note that the access to GPT-4 is tied to both the OpenAI account and the organization ID (on https://openai.com/waitlist/gpt-4-api, one of the fields is the Organization ID).