我能够使用gpt-3.5-turbo-0301模型来访问ChatGPT API,但无法使用任何gpt-4模型。以下是我用来测试的代码(不包括我的OpenAI API密钥)。代码按原样运行,但当我将“gpt-3.5-turbo-0301”替换为“gpt-4”、“gpt-4-0314”或“gpt-4-32k-0314”时,它会返回一个错误
openai.error.InvalidRequestError: The model: `gpt-4` does not exist
我有ChatGPT+订阅,使用我自己的API密钥,并且可以通过OpenAI的界面成功使用gpt-4。
如果我使用gpt-4-0314或gpt-4-32k-0314,也会出现同样的错误。我看到几篇文章声称这种或类似的代码使用“gpt-4”作为模型规格是有效的,我下面粘贴的代码就是其中一篇文章的。
是否可以通过Python + API访问gpt-4模型,如果可以,如何操作?
openai_key = "sk..."openai.api_key = openai_keysystem_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 APIdef 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 aboveask_GPT4(system_intel, prompt)
回答:
目前,GPT-4 API是有限制的,即使对于拥有ChatGPT +订阅的用户也是如此。
您可能需要加入等待列表来访问API。