Skip to content

Commit

Permalink
fix typing in samples (Azure#39084)
Browse files Browse the repository at this point in the history
  • Loading branch information
kristapratico authored Jan 8, 2025
1 parent d26753e commit 4bdccb6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions sdk/openai/azure-openai/samples/chat_completions_oyd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down
16 changes: 8 additions & 8 deletions sdk/openai/azure-openai/samples/images_aoai_quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()

0 comments on commit 4bdccb6

Please sign in to comment.