From 4bdccb6f7daee743266d1930a212c45fd8e84ae9 Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Wed, 8 Jan 2025 14:59:07 -0800 Subject: [PATCH] fix typing in samples (#39084) --- .../samples/chat_completions_aoai_quickstart.py | 2 +- .../azure-openai/samples/chat_completions_oyd.py | 8 ++++---- .../samples/completions_aoai_quickstart.py | 6 +++--- .../samples/images_aoai_quickstart.py | 16 ++++++++-------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/sdk/openai/azure-openai/samples/chat_completions_aoai_quickstart.py b/sdk/openai/azure-openai/samples/chat_completions_aoai_quickstart.py index bce2cfef04a3..3f27481957d6 100644 --- a/sdk/openai/azure-openai/samples/chat_completions_aoai_quickstart.py +++ b/sdk/openai/azure-openai/samples/chat_completions_aoai_quickstart.py @@ -25,7 +25,7 @@ # These lines are intentionally excluded from the sample code, we use them to configure any vars # or to tweak usage in ways that keep samples looking consistent when rendered in docs and tools import os -os.environ["AZURE_OPENAI_ENDPOINT"] = os.getenv("AZ_OPENAI_ENDPOINT") +os.environ["AZURE_OPENAI_ENDPOINT"] = os.environ["AZ_OPENAI_ENDPOINT"] def chat_completions_aoai_quickstart() -> None: #[START chat_completions_aoai_quickstart] diff --git a/sdk/openai/azure-openai/samples/chat_completions_oyd.py b/sdk/openai/azure-openai/samples/chat_completions_oyd.py index b4c11acabfba..90fef9b31799 100644 --- a/sdk/openai/azure-openai/samples/chat_completions_oyd.py +++ b/sdk/openai/azure-openai/samples/chat_completions_oyd.py @@ -27,15 +27,15 @@ # These lines are intentionally excluded from the sample code, we use them to configure any vars # or to tweak usage in ways that keep samples looking consistent when rendered in docs and tools import os -os.environ["AZURE_OPENAI_ENDPOINT"] = os.getenv("AZ_OPENAI_ENDPOINT") +os.environ["AZURE_OPENAI_ENDPOINT"] = os.environ["AZ_OPENAI_ENDPOINT"] def chat_completion_oyd_studio_viewcode() -> None: import os from openai import AzureOpenAI from azure.identity import DefaultAzureCredential, get_bearer_token_provider - endpoint = os.getenv("AZURE_OPENAI_ENDPOINT") - deployment = os.getenv("AZURE_OPENAI_CHAT_DEPLOYMENT") + endpoint = os.environ["AZURE_OPENAI_ENDPOINT"] + deployment = os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT"] token_provider = get_bearer_token_provider( DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default" @@ -44,7 +44,7 @@ def chat_completion_oyd_studio_viewcode() -> None: client = AzureOpenAI( azure_endpoint=endpoint, azure_ad_token_provider=token_provider, - api_version=os.getenv("API_VERSION_GA"), + api_version=os.environ["API_VERSION_GA"], ) completion = client.chat.completions.create( diff --git a/sdk/openai/azure-openai/samples/completions_aoai_quickstart.py b/sdk/openai/azure-openai/samples/completions_aoai_quickstart.py index cb7c7c947f82..cb1ffcbb77a7 100644 --- a/sdk/openai/azure-openai/samples/completions_aoai_quickstart.py +++ b/sdk/openai/azure-openai/samples/completions_aoai_quickstart.py @@ -26,7 +26,7 @@ # These lines are intentionally excluded from the sample code, we use them to configure any vars # or to tweak usage in ways that keep samples looking consistent when rendered in docs and tools import os -os.environ["AZURE_OPENAI_ENDPOINT"] = os.getenv("AZ_OPENAI_ENDPOINT") +os.environ["AZURE_OPENAI_ENDPOINT"] = os.environ["AZ_OPENAI_ENDPOINT"] os.environ["AZURE_OPENAI_COMPLETIONS_DEPLOYMENT"] = "gpt-35-turbo-instruct" def completions_aoai_quickstart() -> None: @@ -40,8 +40,8 @@ def completions_aoai_quickstart() -> None: client = AzureOpenAI( azure_ad_token_provider=token_provider, - azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT"), - api_version=os.getenv("API_VERSION_GA") + azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"], + api_version=os.environ["API_VERSION_GA"] ) #This will correspond to the custom name you chose for your deployment when you deployed a model. diff --git a/sdk/openai/azure-openai/samples/images_aoai_quickstart.py b/sdk/openai/azure-openai/samples/images_aoai_quickstart.py index 0de556da685d..73558748b313 100644 --- a/sdk/openai/azure-openai/samples/images_aoai_quickstart.py +++ b/sdk/openai/azure-openai/samples/images_aoai_quickstart.py @@ -25,7 +25,7 @@ """ import os -os.environ["AZURE_OPENAI_ENDPOINT"] = os.getenv("AZURE_OPENAI_SWEDENCENTRAL_ENDPOINT") +os.environ["AZURE_OPENAI_ENDPOINT"] = os.environ["AZURE_OPENAI_SWEDENCENTRAL_ENDPOINT"] os.environ["AZURE_OPENAI_IMAGE_DEPLOYMENT"] = "dall-e-3" def images_aoai_quickstart() -> None: @@ -62,16 +62,16 @@ def images_aoai_quickstart() -> None: image_path = os.path.join(image_dir, 'generated_image.png') # Retrieve the generated image - image_url = result.data[0].url # extract image URL from response - generated_image = httpx.get(image_url).content # download the image + if image_url: + generated_image = httpx.get(image_url).content # download the image - with open(image_path, "wb") as image_file: - image_file.write(generated_image) + with open(image_path, "wb") as image_file: + image_file.write(generated_image) - # Display the image in the default image viewer - image = Image.open(image_path) - image.show() + # Display the image in the default image viewer + image = Image.open(image_path) + image.show() if __name__ == "__main__": images_aoai_quickstart() \ No newline at end of file