Open AI error: "InvalidRequestError: Resource not found". Please help to fix.

AIoTMR Architect 40 Reputation points
2023-03-07T06:45:55.61+00:00

Dear Team

Could you please help us fixing this error? Code has been taken from sample given and key has been tried as key1 and key2 both separately. Same error is found.

python result: openai.error.InvalidRequestError: Resource not found

#Note: The openai-python library support for Azure OpenAI is in preview.
import os
import openai
openai.api_type = "azure"
openai.api_base = "https://explore123.openai.azure.com/"
openai.api_version = "2022-12-01"
#openai.api_key = os.getenv("66bcffe0ed6c440dba76940d04a7bb03")
openai.api_key = "<key>"

response = openai.Completion.create(
  engine="text-davinci-002",
  prompt="Classify the following news article into 1 of the following categories: categories: [Business, Tech, Politics, Sport, Entertainment]\n\nnews article: Donna Steffensen Is Cooking Up a New Kind of Perfection. The Internet’s most beloved cooking guru has a buzzy new book and a fresh new perspective:\n\nClassified category: Business",
  temperature=0,
  max_tokens=60,
  top_p=1,
  frequency_penalty=0,
  presence_penalty=0,
  best_of=1,
  stop=None)

print(response)

Result:

Traceback (most recent call last):
  File "test1.py", line 19, in <module>
    stop=None)
  File "/home/user/.local/lib/python3.6/site-packages/openai/api_resources/completion.py", line 31, in create
    return super().create(*args, **kwargs)
  File "/home/user/.local/lib/python3.6/site-packages/openai/api_resources/abstract/engine_api_resource.py", line 67, in create
    "post", url, params, headers, stream=stream
  File "/home/user/.local/lib/python3.6/site-packages/openai/api_requestor.py", line 129, in request
    resp = self.interpret_response(rbody, rcode, rheaders, stream=stream)
  File "/home/user/.local/lib/python3.6/site-packages/openai/api_requestor.py", line 348, in interpret_response
    return self.interpret_response_line(rbody, rcode, rheaders, stream)
  File "/home/user/.local/lib/python3.6/site-packages/openai/api_requestor.py", line 368, in interpret_response_line
    rbody, rcode, resp.data, rheaders, stream_error=stream_error
openai.error.InvalidRequestError: Resource not found

======================================================================

Curl Result:  -> no error shown but how can i see the result?

curl https://explore123.openai.azure.com/openai/deployments/text-davinci-002/completions?api-version=2022-12-01   -H "Content-Type: application/json"   -H "api-key: 66bcffe0ed6c440dba76940d04a7bb03"   -d '{
  "prompt": "Classify the following news article into 1 of the following categories: categories: [Business, Tech, Politics, Sport, Entertainment]\n\nnews article: Donna Steffensen Is Cooking Up a New Kind of Perfection. The Internet’s most beloved cooking guru has a buzzy new book and a fresh new perspective:\n\nClassified category: Business",
  "max_tokens": 60,
  "temperature": 0,
  "frequency_penalty": 0,
  "presence_penalty": 0,
  "top_p": 1,
  "best_of": 1,
  "stop": null
}'
{"id":"cmpl-6rLFaLc8zTYo8oHbjA5WNm5Tp6i7k","object":"text_completion","created":1678171090,"model":"text-davinci-002","choices":[{"text":"","index":0,"finish_reason":"stop","logprobs":null}],"usage":{"prompt_tokens":73,"total_tokens":73}}



Regards
Champak
Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
2,647 questions
{count} votes

9 answers

Sort by: Most helpful
  1. Michael B 0 Reputation points Microsoft Employee
    2023-03-13T17:43:18.29+00:00

    I'll clean up the docs to make this more clear this week.

    openai.api_base ="Your endpoint address"
    

    This corresponds to the unique endpoint address for your Azure OpenAI resource where the gpt-35-model is deployed. You can find this by going to Keys and Endpoint for your resource.

    User's image

    User's image

     engine="This is the name you assigned to the deployment when you deployed the gpt-35-turbo model"
    

  2. Shreshtha Agrahari 0 Reputation points
    2023-04-15T05:18:24.8666667+00:00

    I am getting the same error, azure openAI chat completion SDK works locally but when deployed to Azure function app gives 404- Resource not found error. How to solve this issue?

    0 comments No comments

  3. Gianluca D'Ardia 5 Reputation points Microsoft Employee
    2023-04-15T12:49:39.64+00:00

    I got same issue: worked on local but not on deployed env. I solved providing right module version. Checked version on my local env with

    pip list | more
    

    In my local env I had 0.27.4 but in deployed env I got 0.10.0 changed requirements.txt in code repo (python flask app) with

    openai==0.27.4
    

    and everything worked.


  4. Shawn Mittal 35 Reputation points Microsoft Employee
    2023-04-26T15:45:12.0633333+00:00

    Hi folks, looks like there seems to be an issue with the openai==0.27.4 version for python. Try installing openai==0.27.0. This fix worked for me on local. Not sure if it'll work once deployed on Azure Functions or in an App Service, but I intend to try it out.

    0 comments No comments