Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typing in samples #38354

Open
wants to merge 13 commits into
base: feature/azure-ai-projects
Choose a base branch
from
6 changes: 3 additions & 3 deletions sdk/ai/azure-ai-projects/azure/ai/projects/aio/_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .operations._patch import InferenceOperations

if TYPE_CHECKING:
from azure.core.credentials_async import AsyncTokenCredential
from azure.core.credentials import TokenCredential


class AIProjectClient(ClientGenerated):
Expand All @@ -32,7 +32,7 @@ def __init__(
subscription_id: str,
resource_group_name: str,
project_name: str,
credential: "AsyncTokenCredential",
credential: "TokenCredential",
**kwargs: Any,
) -> None:
# TODO: Validate input formats with regex match (e.g. subscription ID)
Expand Down Expand Up @@ -216,7 +216,7 @@ async def __aexit__(self, *exc_details: Any) -> None:
await self._client3.__aexit__(*exc_details)

@classmethod
def from_connection_string(cls, conn_str: str, credential: "AsyncTokenCredential", **kwargs) -> "AIProjectClient":
def from_connection_string(cls, conn_str: str, credential: "TokenCredential", **kwargs) -> "AIProjectClient":
"""
Create an asynchronous AIProjectClient from a connection string.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import time
from pathlib import Path
from azure.core.exceptions import ResourceNotFoundError
from io import TextIOWrapper
from typing import (
IO,
Any,
Expand Down Expand Up @@ -67,7 +66,7 @@ def __init__(self, outer_instance):
self._outer_instance = outer_instance

@distributed_trace_async
async def get_chat_completions_client(self, **kwargs) -> "Optional[ChatCompletionsClient]":
async def get_chat_completions_client(self, **kwargs) -> "ChatCompletionsClient":
"""Get an authenticated asynchronous ChatCompletionsClient (from the package azure-ai-inference) for the default
Azure AI Services connected resource. At least one AI model that supports chat completions must be deployed
in this resource. The packages `azure-ai-inference` and `aiohttp` must be installed prior to calling this method.
Expand Down Expand Up @@ -134,7 +133,7 @@ async def get_chat_completions_client(self, **kwargs) -> "Optional[ChatCompletio
return client

@distributed_trace_async
async def get_embeddings_client(self, **kwargs) -> "Optional[EmbeddingsClient]":
async def get_embeddings_client(self, **kwargs) -> "EmbeddingsClient":
"""Get an authenticated asynchronous EmbeddingsClient (from the package azure-ai-inference) for the default
Azure AI Services connected resource. At least one AI model that supports text embeddings must be deployed
in this resource. The packages `azure-ai-inference` and `aiohttp` must be installed prior to calling this method.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# pylint: disable=too-many-lines
# pylint: disable=too-many-lines
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
Expand All @@ -11,7 +10,8 @@
import sys, io, logging, os, time
from azure.core.exceptions import ResourceNotFoundError
from io import TextIOWrapper
from typing import List, Union, IO, Any, Dict, Optional, overload, Sequence, TYPE_CHECKING, Iterator, TextIO, cast
from typing import List, Union, IO, Any, Dict, Optional, overload, Sequence, TYPE_CHECKING, Iterator, cast,\
TextIO
from pathlib import Path

from ._operations import ConnectionsOperations as ConnectionsOperationsGenerated
Expand Down Expand Up @@ -124,7 +124,7 @@ def get_chat_completions_client(self, **kwargs) -> "ChatCompletionsClient":
return client

@distributed_trace
def get_embeddings_client(self, **kwargs) -> "Optional[EmbeddingsClient]":
def get_embeddings_client(self, **kwargs) -> "EmbeddingsClient":
"""Get an authenticated EmbeddingsClient (from the package azure-ai-inference) for the default
Azure AI Services connected resource. At least one AI model that supports text embeddings must be deployed
in this resource. The package `azure-ai-inference` must be installed prior to calling this method.
Expand Down
3 changes: 1 addition & 2 deletions sdk/ai/azure-ai-projects/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[tool.mypy]
python_version = "3.8"
exclude = [
"downloaded",
"samples"
"downloaded"
]
warn_unused_configs = true
follow_imports = "skip"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
import time

from azure.ai.projects.aio import AIProjectClient
from azure.identity.aio import DefaultAzureCredential
from azure.identity import DefaultAzureCredential

import os


async def main():
async def main() -> None:

# Create an Azure AI Client from a connection string, copied from your AI Studio project.
# At the moment, it should be in the format "<HostName>;<AzureSubscriptionId>;<ResourceGroup>;<HubName>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
"""
import asyncio
import time
import sys
from azure.ai.projects.aio import AIProjectClient
from azure.identity.aio import DefaultAzureCredential
from azure.identity import DefaultAzureCredential
from azure.ai.projects.tracing.agents import AIAgentsInstrumentor
from opentelemetry import trace
import os
Expand All @@ -38,7 +37,7 @@


@tracer.start_as_current_span(__file__)
async def main():
async def main() -> None:

# Create an Azure AI Project Client from a connection string, copied from your AI Studio project.
# At the moment, it should be in the format "<HostName>;<AzureSubscriptionId>;<ResourceGroup>;<HubName>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import time
import sys
from azure.ai.projects.aio import AIProjectClient
from azure.identity.aio import DefaultAzureCredential
from azure.identity import DefaultAzureCredential
from opentelemetry import trace
import os

Expand All @@ -41,7 +41,7 @@


@tracer.start_as_current_span(__file__)
async def main():
async def main() -> None:

# Create an Azure AI Project Client from a connection string, copied from your AI Studio project.
# At the moment, it should be in the format "<HostName>;<AzureSubscriptionId>;<ResourceGroup>;<HubName>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
from azure.ai.projects.aio import AIProjectClient
from azure.ai.projects.models import CodeInterpreterTool
from azure.ai.projects.models import FilePurpose
from azure.identity.aio import DefaultAzureCredential
from azure.identity import DefaultAzureCredential
from pathlib import Path

import os


async def main():
async def main() -> None:

# Create an Azure AI Client from a connection string, copied from your AI Studio project.
# At the moment, it should be in the format "<HostName>;<AzureSubscriptionId>;<ResourceGroup>;<HubName>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@

from azure.ai.projects.aio import AIProjectClient
from azure.ai.projects.models import AsyncFunctionTool, RequiredFunctionToolCall, SubmitToolOutputsAction
from azure.identity.aio import DefaultAzureCredential
from azure.identity import DefaultAzureCredential

import os

from user_async_functions import user_async_functions


async def main():
async def main() -> None:
# Create an Azure AI Client from a connection string, copied from your AI Studio project.
# At the moment, it should be in the format "<HostName>;<AzureSubscriptionId>;<ResourceGroup>;<HubName>"
# Customer needs to login to Azure subscription via Azure CLI and set the environment variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

import os, asyncio
from azure.ai.projects.aio import AIProjectClient
from azure.identity.aio import DefaultAzureCredential
from azure.ai.projects.models import AsyncFunctionTool, AsyncToolSet, CodeInterpreterTool
from azure.identity import DefaultAzureCredential
from azure.ai.projects.models import AsyncFunctionTool, AsyncToolSet
from user_async_functions import user_async_functions


Expand All @@ -33,7 +33,7 @@
# Customer needs to login to Azure subscription via Azure CLI and set the environment variables


async def main():
async def main() -> None:

project_client = AIProjectClient.from_connection_string(
credential=DefaultAzureCredential(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
ThreadRun,
)
from azure.ai.projects.models._patch import AsyncAgentEventHandler
from azure.identity.aio import DefaultAzureCredential
from azure.identity import DefaultAzureCredential

import os

Expand Down Expand Up @@ -63,7 +63,7 @@ async def on_unhandled_event(self, event_type: str, event_data: Any) -> None:
print(f"Unhandled Event Type: {event_type}, Data: {event_data}")


async def main():
async def main() -> None:
# Create an Azure AI Client from a connection string, copied from your AI Studio project.
# At the moment, it should be in the format "<HostName>;<AzureSubscriptionId>;<ResourceGroup>;<HubName>"
# Customer needs to login to Azure subscription via Azure CLI and set the environment variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
from azure.ai.projects.aio import AIProjectClient
from azure.ai.projects.models import MessageDeltaChunk, MessageDeltaTextContent, RunStep, ThreadMessage, ThreadRun
from azure.ai.projects.models import AsyncAgentEventHandler, AsyncFunctionTool, AsyncToolSet
from azure.ai.projects.aio.operations import AgentsOperations
from azure.identity.aio import DefaultAzureCredential
from azure.identity import DefaultAzureCredential

import os

Expand Down Expand Up @@ -64,7 +63,7 @@ async def on_unhandled_event(self, event_type: str, event_data: Any) -> None:
print(f"Unhandled Event Type: {event_type}, Data: {event_data}")


async def main():
async def main() -> None:
# Create an Azure AI Client from a connection string, copied from your AI Studio project.
# At the moment, it should be in the format "<HostName>;<AzureSubscriptionId>;<ResourceGroup>;<HubName>"
# Customer needs to login to Azure subscription via Azure CLI and set the environment variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
from azure.ai.projects.aio import AIProjectClient
from azure.ai.projects.models import AgentStreamEvent
from azure.ai.projects.models import MessageDeltaChunk, MessageDeltaTextContent, RunStep, ThreadMessage, ThreadRun
from azure.identity.aio import DefaultAzureCredential
from azure.identity import DefaultAzureCredential

import os


async def main():
async def main() -> None:
# Create an Azure AI Client from a connection string, copied from your AI Studio project.
# At the moment, it should be in the format "<HostName>;<AzureSubscriptionId>;<ResourceGroup>;<HubName>"
# Customer needs to login to Azure subscription via Azure CLI and set the environment variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
import os
from azure.ai.projects.aio import AIProjectClient
from azure.ai.projects.models import FileSearchTool, FilePurpose
from azure.identity.aio import DefaultAzureCredential
from azure.identity import DefaultAzureCredential


async def main():
async def main() -> None:
# Create an Azure AI Client from a connection string, copied from your AI Studio project.
# At the moment, it should be in the format "<HostName>;<AzureSubscriptionId>;<ResourceGroup>;<HubName>"
# Customer needs to login to Azure subscription via Azure CLI and set the environment variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
from azure.ai.projects.aio import AIProjectClient
from azure.ai.projects.models import FilePurpose
from azure.ai.projects.models import FileSearchTool, MessageAttachment, ToolResources
from azure.identity.aio import DefaultAzureCredential
from azure.identity import DefaultAzureCredential

import os


async def main():
async def main() -> None:
# Create an Azure AI Client from a connection string, copied from your AI Studio project.
# At the moment, it should be in the format "<HostName>;<AzureSubscriptionId>;<ResourceGroup>;<HubName>"
# Customer needs to login to Azure subscription via Azure CLI and set the environment variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
View the results in the "Tracing" tab in your Azure AI Studio project page.

USAGE:
python sample_agents_basics_with_azure_monitor_tracing.py
python sample_agents_functions_with_azure_monitor_tracing.py

Before running the sample:

Expand All @@ -23,9 +23,9 @@
* AZURE_TRACING_GEN_AI_CONTENT_RECORDING_ENABLED - Optional. Set to `true` to trace the content of chat
messages, which may contain personal data. False by default.
"""

import os, sys, time, json
from typing import Any, Callable, Set

import os, time, json
from azure.ai.projects import AIProjectClient
from azure.identity import DefaultAzureCredential
from azure.ai.projects.models import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
the Azure Agents service using a synchronous client with tracing to console.

USAGE:
python sample_agents_basics_with_console_tracing.py
python sample_agents_functions_with_console_tracing.py

Before running the sample:

Expand All @@ -28,9 +28,9 @@
* AZURE_TRACING_GEN_AI_CONTENT_RECORDING_ENABLED - Optional. Set to `true` to trace the content of chat
messages, which may contain personal data. False by default.
"""
from typing import Any, Callable, Set

import os, sys, time, json
from typing import Any, Callable, Set
from azure.ai.projects import AIProjectClient
from azure.identity import DefaultAzureCredential
from azure.ai.projects.models import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,20 @@

"""

import os, sys
import os
from azure.ai.projects import AIProjectClient
from azure.ai.projects.models._enums import RunStepType
from azure.identity import DefaultAzureCredential
from azure.ai.projects.models import (
AgentEventHandler,
MessageDeltaTextContent,
MessageDeltaChunk,
ThreadMessage,
ThreadRun,
RunStep,
RunStep
)
from typing import Any
from opentelemetry import trace
from azure.monitor.opentelemetry import configure_azure_monitor
from azure.monitor.opentelemetry import configure_azure_monitor

# Create an Azure AI Project Client from a connection string, copied from your AI Studio project.
# At the moment, it should be in the format "<HostName>;<AzureSubscriptionId>;<ResourceGroup>;<HubName>"
Expand All @@ -59,17 +58,19 @@ def on_message_delta(self, delta: "MessageDeltaChunk") -> None:
print(f"Text delta received: {text_value}")

def on_thread_message(self, message: "ThreadMessage") -> None:
print(f"ThreadMessage created. ID: {message.id}, Status: {message.status}")
if len(message.content):
print(f"ThreadMessage created. ID: {message.id}, "
f"Status: {message.status}, Content: {message.content[0].as_dict()}")
else:
print(f"ThreadMessage created. ID: {message.id}, "
f"Status: {message.status}")

def on_thread_run(self, run: "ThreadRun") -> None:
print(f"ThreadRun status: {run.status}")

def on_run_step(self, step: "RunStep") -> None:
print(f"RunStep type: {step.type}, Status: {step.status}")

def on_thread_message(self, message: "ThreadMessage") -> None:
print(f"Message status: {message.status}, Content: {message.content[0].as_dict()}")

def on_error(self, data: str) -> None:
print(f"An error occurred. Data: {data}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

import os, sys
from azure.ai.projects import AIProjectClient
from azure.ai.projects.models._enums import RunStepType
from azure.identity import DefaultAzureCredential
from azure.ai.projects.models import (
AgentEventHandler,
Expand Down Expand Up @@ -63,17 +62,19 @@ def on_message_delta(self, delta: "MessageDeltaChunk") -> None:
print(f"Text delta received: {text_value}")

def on_thread_message(self, message: "ThreadMessage") -> None:
print(f"ThreadMessage created. ID: {message.id}, Status: {message.status}")
if len(message.content):
print(f"ThreadMessage created. ID: {message.id}, "
f"Status: {message.status}, Content: {message.content[0].as_dict()}")
else:
print(f"ThreadMessage created. ID: {message.id}, "
f"Status: {message.status}")

def on_thread_run(self, run: "ThreadRun") -> None:
print(f"ThreadRun status: {run.status}")

def on_run_step(self, step: "RunStep") -> None:
print(f"RunStep type: {step.type}, Status: {step.status}")

def on_thread_message(self, message: "ThreadMessage") -> None:
print(f"Message status: {message.status}, Content: {message.content[0].as_dict()}")

def on_error(self, data: str) -> None:
print(f"An error occurred. Data: {data}")

Expand Down
Loading
Loading