Azure OpenAI Service REST DALL-E Python

Todward 0 Reputation points
2023-10-21T19:49:46.2133333+00:00

I follow the example from Dall-e playground azure website and can create images there. But get an error running the python code locally:

/usr/local/bin/python3 /Users//..../gitlab/ml/dalle/dalle-2.py
Traceback (most recent call last):
  File "/Users/r..../gitlab/ml/dalle/dalle-2.py", line 11, in <module>
    response = openai.Image.create(
               ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/openai/api_resources/image.py", line 36, in create
    response, _, api_key = requestor.request(
                           ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/openai/api_requestor.py", line 230, in request
    resp, got_stream = self._interpret_response(result, stream)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/openai/api_requestor.py", line 624, in _interpret_response
    self._interpret_response_line(
  File "/usr/local/lib/python3.11/site-packages/openai/api_requestor.py", line 687, in _interpret_response_line
    raise self.handle_error_response(
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://dalxxxxxx.openai.azure.com/"
openai.api_version = "2023-06-01-preview"
openai.api_key = os.getenv("OPENAI_API_KEY")

response = openai.Image.create(
   prompt='The seattle skyline and space needle, impressionist painting',
    size='1024x1024',
    n=1
)

image_url = response["data"][0]["url"]

Checked multiple times the api key and it is in useast .

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
4,081 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
3,602 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Konstantinos Passadis 19,586 Reputation points MVP
    2023-10-21T21:43:59.0566667+00:00

    Hello @Todward !

    Welcome to Microsft QnA!

    The error message you are encountering (openai.error.InvalidRequestError: Resource not found) shows that the API endpoint you're requesting does not exist or is not available for your OpenAI account.

    Make sure for

    The correct .env and requirments.txt file exist

    Sample requirements.txt

    ....

    python-dotenv==1.0.0

    openai==0.27.8

    .....

    OR run pip install openai --upgrade

    Make sure your API is not locked by Network Firewall in Azure Portal

    Check these and come back wit your feedback !


    I hope this helps!

    Kindly mark the answer as Accepted and Upvote in case it helped!

    Regards


  2. Konstantinos Passadis 19,586 Reputation points MVP
    2023-10-22T12:31:37.3233333+00:00

    Hello @Todward !

    As per :

    https://learn.microsoft.com/en-us/azure/ai-services/openai/dall-e-quickstart?tabs=command-line&pivots=programming-language-python

    You need :


    I hope this helps!

    Kindly mark the answer as Accepted and Upvote in case it helped!

    Regards

    0 comments No comments

  3. Konstantinos Passadis 19,586 Reputation points MVP
    2023-10-23T19:27:17.1933333+00:00

    Hello @Todward !

    Please check my message

    You need :

    -------->

    • The following Python libraries: os, requests, json. (Are these in your code ?)

    I hope this helps!

    Kindly mark the answer as Accepted and Upvote in case it helped!

    Regards


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.