-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
69 changed files
with
668 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ jobs: | |
|
||
- name: Run lints | ||
run: ./scripts/lint | ||
|
||
test: | ||
name: test | ||
runs-on: ubuntu-latest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
".": "1.59.7" | ||
".": "1.60.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
configured_endpoints: 69 | ||
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-b5b0e2c794b012919701c3fd43286af10fa25d33ceb8a881bec2636028f446e0.yml | ||
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-3904ef6b29a89c98f93a9b7da19879695f3c440564be6384db7af1b734611ede.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,67 @@ | ||
from azure.identity import DefaultAzureCredential, get_bearer_token_provider | ||
import asyncio | ||
|
||
from openai import AzureOpenAI | ||
from openai.lib.azure import AzureOpenAI, AsyncAzureOpenAI, AzureADTokenProvider, AsyncAzureADTokenProvider | ||
|
||
token_provider = get_bearer_token_provider(DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default") | ||
scopes = "https://cognitiveservices.azure.com/.default" | ||
|
||
|
||
# may change in the future | ||
# May change in the future | ||
# https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#rest-api-versioning | ||
api_version = "2023-07-01-preview" | ||
|
||
# https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/create-resource?pivots=web-portal#create-a-resource | ||
endpoint = "https://my-resource.openai.azure.com" | ||
|
||
client = AzureOpenAI( | ||
api_version=api_version, | ||
azure_endpoint=endpoint, | ||
azure_ad_token_provider=token_provider, | ||
) | ||
|
||
completion = client.chat.completions.create( | ||
model="deployment-name", # e.g. gpt-35-instant | ||
messages=[ | ||
{ | ||
"role": "user", | ||
"content": "How do I output all files in a directory using Python?", | ||
}, | ||
], | ||
) | ||
print(completion.to_json()) | ||
deployment_name = "deployment-name" # e.g. gpt-35-instant | ||
|
||
|
||
def sync_main() -> None: | ||
from azure.identity import DefaultAzureCredential, get_bearer_token_provider | ||
|
||
token_provider: AzureADTokenProvider = get_bearer_token_provider(DefaultAzureCredential(), scopes) | ||
|
||
client = AzureOpenAI( | ||
api_version=api_version, | ||
azure_endpoint=endpoint, | ||
azure_ad_token_provider=token_provider, | ||
) | ||
|
||
completion = client.chat.completions.create( | ||
model=deployment_name, | ||
messages=[ | ||
{ | ||
"role": "user", | ||
"content": "How do I output all files in a directory using Python?", | ||
} | ||
], | ||
) | ||
|
||
print(completion.to_json()) | ||
|
||
|
||
async def async_main() -> None: | ||
from azure.identity.aio import DefaultAzureCredential, get_bearer_token_provider | ||
|
||
token_provider: AsyncAzureADTokenProvider = get_bearer_token_provider(DefaultAzureCredential(), scopes) | ||
|
||
client = AsyncAzureOpenAI( | ||
api_version=api_version, | ||
azure_endpoint=endpoint, | ||
azure_ad_token_provider=token_provider, | ||
) | ||
|
||
completion = await client.chat.completions.create( | ||
model=deployment_name, | ||
messages=[ | ||
{ | ||
"role": "user", | ||
"content": "How do I output all files in a directory using Python?", | ||
} | ||
], | ||
) | ||
|
||
print(completion.to_json()) | ||
|
||
|
||
sync_main() | ||
|
||
asyncio.run(async_main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import os | ||
import asyncio | ||
|
||
from azure.identity.aio import DefaultAzureCredential, get_bearer_token_provider | ||
|
||
from openai import AsyncAzureOpenAI | ||
|
||
# Azure OpenAI Realtime Docs | ||
|
||
# How-to: https://learn.microsoft.com/azure/ai-services/openai/how-to/realtime-audio | ||
# Supported models and API versions: https://learn.microsoft.com/azure/ai-services/openai/how-to/realtime-audio#supported-models | ||
# Entra ID auth: https://learn.microsoft.com/azure/ai-services/openai/how-to/managed-identity | ||
|
||
|
||
async def main() -> None: | ||
"""The following example demonstrates how to configure Azure OpenAI to use the Realtime API. | ||
For an audio example, see push_to_talk_app.py and update the client and model parameter accordingly. | ||
|
||
When prompted for user input, type a message and hit enter to send it to the model. | ||
Enter "q" to quit the conversation. | ||
""" | ||
|
||
credential = DefaultAzureCredential() | ||
client = AsyncAzureOpenAI( | ||
azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"], | ||
azure_ad_token_provider=get_bearer_token_provider(credential, "https://cognitiveservices.azure.com/.default"), | ||
api_version="2024-10-01-preview", | ||
) | ||
async with client.beta.realtime.connect( | ||
model="gpt-4o-realtime-preview", # deployment name for your model | ||
) as connection: | ||
await connection.session.update(session={"modalities": ["text"]}) # type: ignore | ||
while True: | ||
user_input = input("Enter a message: ") | ||
if user_input == "q": | ||
break | ||
|
||
await connection.conversation.item.create( | ||
item={ | ||
"type": "message", | ||
"role": "user", | ||
"content": [{"type": "input_text", "text": user_input}], | ||
} | ||
) | ||
await connection.response.create() | ||
async for event in connection: | ||
if event.type == "response.text.delta": | ||
print(event.delta, flush=True, end="") | ||
elif event.type == "response.text.done": | ||
print() | ||
elif event.type == "response.done": | ||
break | ||
|
||
await credential.close() | ||
|
||
|
||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,3 @@ rye run lint | |
|
||
echo "==> Making sure it imports" | ||
rye run python -c 'import openai' | ||
|
Oops, something went wrong.