diff --git a/sdk/ai/azure-ai-projects/azure/ai/projects/_patch.py b/sdk/ai/azure-ai-projects/azure/ai/projects/_patch.py index 95dc6b8ea967..7acec5304675 100644 --- a/sdk/ai/azure-ai-projects/azure/ai/projects/_patch.py +++ b/sdk/ai/azure-ai-projects/azure/ai/projects/_patch.py @@ -230,7 +230,7 @@ def from_connection_string(cls, conn_str: str, credential: "TokenCredential", ** project_name = parts[3] return cls(endpoint, subscription_id, resource_group_name, project_name, credential, **kwargs) - def upload_file(self, file_path: Union[Path, str, PathLike]) -> Tuple[str]: + def upload_file(self, file_path: Union[Path, str, PathLike]) -> Tuple[str, str]: """Upload a file to the Azure AI Studio project. This method required *azure-ai-ml* to be installed. diff --git a/sdk/ai/azure-ai-projects/azure/ai/projects/aio/_patch.py b/sdk/ai/azure-ai-projects/azure/ai/projects/aio/_patch.py index 97373d32cf3a..d70124530096 100644 --- a/sdk/ai/azure-ai-projects/azure/ai/projects/aio/_patch.py +++ b/sdk/ai/azure-ai-projects/azure/ai/projects/aio/_patch.py @@ -2,14 +2,17 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # ------------------------------------ +from azure.core.credentials import TokenCredential """Customize generated code here. Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize """ +import asyncio +import concurrent.futures import uuid from os import PathLike from pathlib import Path -from typing import List, Any, Union, Dict, Tuple, TYPE_CHECKING +from typing import List, Any, Union, Dict, Optional, Tuple, TYPE_CHECKING from azure.core import AsyncPipelineClient from azure.core.pipeline import policies from typing_extensions import Self @@ -22,6 +25,7 @@ if TYPE_CHECKING: from azure.core.credentials_async import AsyncTokenCredential + from azure.core.credentials import AccessToken class AIProjectClient(ClientGenerated): @@ -233,14 +237,14 @@ def from_connection_string(cls, conn_str: str, credential: "AsyncTokenCredential project_name = parts[3] return cls(endpoint, subscription_id, resource_group_name, project_name, credential, **kwargs) - def upload_file(self, file_path: Union[Path, str, PathLike]) -> Tuple[str]: + def upload_file(self, file_path: Union[Path, str, PathLike]) -> Tuple[str, str]: """Upload a file to the Azure AI Studio project. This method required *azure-ai-ml* to be installed. :param file_path: The path to the file to upload. :type file_path: Union[str, Path, PathLike] :return: The tuple, containing asset id and asset URI of uploaded file. - :rtype: Tuple[str] + :rtype: Tuple[str, str] """ try: from azure.ai.ml import MLClient # type: ignore @@ -258,9 +262,10 @@ def upload_file(self, file_path: Union[Path, str, PathLike]) -> Tuple[str]: is_anonymous=True, version="1", ) + # We have to wrap async method get_token of ml_client = MLClient( - self._config3.credential, + _SyncCredentialWrapper(self._config3.credential), self._config3.subscription_id, self._config3.resource_group_name, self._config3.project_name, @@ -283,6 +288,37 @@ def scope(self) -> Dict[str, str]: "AIProjectClient", ] # Add all objects you want publicly available to users at this package level +class _SyncCredentialWrapper(TokenCredential): + """ + The class, synchronizing AsyncTokenCredential. + + :param async_credential: The async credential to be synchronized. + :type async_credential: ~azure.core.credentials_async.AsyncTokenCredential + """ + + def __init__(self, async_credential: "AsyncTokenCredential"): + self._async_credential = async_credential + + def get_token( + self, + *scopes:str, + claims:Optional[str]=None, + tenant_id:Optional[str]=None, + enable_cae:bool=False, ** + kwargs:Any) -> "AccessToken": + + pool = concurrent.futures.ThreadPoolExecutor() + return pool.submit( + asyncio.run, + self._async_credential.get_token( + *scopes, + claims=claims, + tenant_id=tenant_id, + enable_cae=enable_cae, + **kwargs + ) + ).result() + def patch_sdk(): """Do not remove from this file. diff --git a/sdk/ai/azure-ai-projects/azure/ai/projects/aio/operations/_patch.py b/sdk/ai/azure-ai-projects/azure/ai/projects/aio/operations/_patch.py index 2771db4188e1..f2d00ffb7d5e 100644 --- a/sdk/ai/azure-ai-projects/azure/ai/projects/aio/operations/_patch.py +++ b/sdk/ai/azure-ai-projects/azure/ai/projects/aio/operations/_patch.py @@ -66,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. @@ -136,7 +136,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. diff --git a/sdk/ai/azure-ai-projects/azure/ai/projects/models/_patch.py b/sdk/ai/azure-ai-projects/azure/ai/projects/models/_patch.py index 08d483db4895..6d74afc54339 100644 --- a/sdk/ai/azure-ai-projects/azure/ai/projects/models/_patch.py +++ b/sdk/ai/azure-ai-projects/azure/ai/projects/models/_patch.py @@ -993,10 +993,11 @@ async def __anext__(self) -> Tuple[str, StreamEventData]: event_data_str, self.buffer = self.buffer.split("\n\n", 1) return await self._process_event(event_data_str) - def _parse_event_data(self, event_data_str: str) -> Tuple[str, StreamEventData]: + def _parse_event_data(self, event_data_str: str) -> Tuple[str, StreamEventData, str]: event_lines = event_data_str.strip().split("\n") event_type = None event_data = "" + error_string = "" for line in event_lines: if line.startswith("event:"): @@ -1053,11 +1054,12 @@ def _parse_event_data(self, event_data_str: str) -> Tuple[str, StreamEventData]: event_data_obj = _safe_instantiate(RunStepDeltaChunk, parsed_data) else: event_data_obj = parsed_data + error_string = str(parsed_data) - return event_type, event_data_obj + return event_type, event_data_obj, error_string async def _process_event(self, event_data_str: str) -> Tuple[str, StreamEventData]: - event_type, event_data_obj = self._parse_event_data(event_data_str) + event_type, event_data_obj, error_string = self._parse_event_data(event_data_str) if ( isinstance(event_data_obj, ThreadRun) @@ -1078,7 +1080,7 @@ async def _process_event(self, event_data_str: str) -> Tuple[str, StreamEventDat elif isinstance(event_data_obj, RunStepDeltaChunk): await self.event_handler.on_run_step_delta(event_data_obj) elif event_type == AgentStreamEvent.ERROR: - await self.event_handler.on_error(event_data_obj) + await self.event_handler.on_error(error_string) elif event_type == AgentStreamEvent.DONE: await self.event_handler.on_done() self.done = True # Mark the stream as done @@ -1142,10 +1144,11 @@ def __next__(self) -> Tuple[str, StreamEventData]: event_data_str, self.buffer = self.buffer.split("\n\n", 1) return self._process_event(event_data_str) - def _parse_event_data(self, event_data_str: str) -> Tuple[str, StreamEventData]: + def _parse_event_data(self, event_data_str: str) -> Tuple[str, StreamEventData, str]: event_lines = event_data_str.strip().split("\n") event_type = None event_data = "" + error_string = "" for line in event_lines: if line.startswith("event:"): @@ -1200,11 +1203,12 @@ def _parse_event_data(self, event_data_str: str) -> Tuple[str, StreamEventData]: event_data_obj = _safe_instantiate(RunStepDeltaChunk, parsed_data) else: event_data_obj = parsed_data + error_string = str(parsed_data) - return event_type, event_data_obj + return event_type, event_data_obj, error_string def _process_event(self, event_data_str: str) -> Tuple[str, StreamEventData]: - event_type, event_data_obj = self._parse_event_data(event_data_str) + event_type, event_data_obj, error_string= self._parse_event_data(event_data_str) if ( isinstance(event_data_obj, ThreadRun) @@ -1225,7 +1229,7 @@ def _process_event(self, event_data_str: str) -> Tuple[str, StreamEventData]: elif isinstance(event_data_obj, RunStepDeltaChunk): self.event_handler.on_run_step_delta(event_data_obj) elif event_type == AgentStreamEvent.ERROR: - self.event_handler.on_error(event_data_obj) + self.event_handler.on_error(error_string) elif event_type == AgentStreamEvent.DONE: self.event_handler.on_done() self.done = True # Mark the stream as done diff --git a/sdk/ai/azure-ai-projects/azure/ai/projects/operations/_patch.py b/sdk/ai/azure-ai-projects/azure/ai/projects/operations/_patch.py index 62ad9f7bb06d..c5587634c131 100644 --- a/sdk/ai/azure-ai-projects/azure/ai/projects/operations/_patch.py +++ b/sdk/ai/azure-ai-projects/azure/ai/projects/operations/_patch.py @@ -125,7 +125,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. diff --git a/sdk/ai/azure-ai-projects/azure/ai/projects/telemetry/agents/_ai_agents_instrumentor.py b/sdk/ai/azure-ai-projects/azure/ai/projects/telemetry/agents/_ai_agents_instrumentor.py index 1cb89d70ac56..1a853c8e5817 100644 --- a/sdk/ai/azure-ai-projects/azure/ai/projects/telemetry/agents/_ai_agents_instrumentor.py +++ b/sdk/ai/azure-ai-projects/azure/ai/projects/telemetry/agents/_ai_agents_instrumentor.py @@ -304,7 +304,7 @@ def _add_message_event( message_id: Optional[str] = None, thread_run_id: Optional[str] = None, message_status: Optional[str] = None, - incomplete_details: Optional[str] = None, + incomplete_details: Optional[MessageIncompleteDetails] = None, usage: Optional[_models.RunStepCompletionUsage] = None, ) -> None: # TODO document new fields diff --git a/sdk/ai/azure-ai-projects/pyproject.toml b/sdk/ai/azure-ai-projects/pyproject.toml index 326df8f77fd8..cbaf85637ea5 100644 --- a/sdk/ai/azure-ai-projects/pyproject.toml +++ b/sdk/ai/azure-ai-projects/pyproject.toml @@ -2,9 +2,14 @@ python_version = "3.8" exclude = [ "downloaded", - "samples" + # Types contains code, generated by typespec. + "_types", + # Error in typing caused by the typespec. + "sample_agents_with_file_search_attachment.py", + "sample_agents_with_code_interpreter_file_attachment.py", + "sample_agents_code_interpreter_attachment_enterprise_search.py", + "sample_agents_with_file_search_attachment_async.py" ] warn_unused_configs = true -follow_imports = "skip" ignore_missing_imports = true follow_imports_for_stubs = false \ No newline at end of file diff --git a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_basics_async.py b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_basics_async.py index f77fb6738625..de6edb55084b 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_basics_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_basics_async.py @@ -29,7 +29,7 @@ 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 ";;;" diff --git a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_basics_async_with_azure_monitor_tracing.py b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_basics_async_with_azure_monitor_tracing.py index b205684bb8a8..2f6154027772 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_basics_async_with_azure_monitor_tracing.py +++ b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_basics_async_with_azure_monitor_tracing.py @@ -25,7 +25,6 @@ """ import asyncio import time -import sys from azure.ai.projects.aio import AIProjectClient from azure.identity.aio import DefaultAzureCredential from azure.ai.projects.tracing.agents import AIAgentsInstrumentor @@ -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 ";;;" diff --git a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_basics_async_with_console_tracing.py b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_basics_async_with_console_tracing.py index c9d08f754472..a0e6b26b6cad 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_basics_async_with_console_tracing.py +++ b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_basics_async_with_console_tracing.py @@ -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 ";;;" @@ -54,7 +54,7 @@ async def main(): # Enable console tracing # or, if you have local OTLP endpoint running, change it to # project_client.telemetry.enable(destination="http://localhost:4317") - project_client.telemetry.enable(destination=sys.stdout) + await project_client.telemetry.enable(destination=sys.stdout) async with project_client: agent = await project_client.agents.create_agent( diff --git a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_code_interpreter_async.py b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_code_interpreter_async.py index 36e7028d1f2e..ebe2bc07b102 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_code_interpreter_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_code_interpreter_async.py @@ -31,7 +31,7 @@ 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 ";;;" diff --git a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_code_interpreter_attachment_async.py b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_code_interpreter_attachment_async.py index d3c36363d4ba..36b63adae474 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_code_interpreter_attachment_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_code_interpreter_attachment_async.py @@ -26,7 +26,7 @@ from azure.ai.projects.models import CodeInterpreterTool from azure.ai.projects.models import FilePurpose from azure.ai.projects.models import MessageAttachment -from azure.identity import DefaultAzureCredential +from azure.identity.aio import DefaultAzureCredential # Create an Azure AI Client from a connection string, copied from your AI Studio project. diff --git a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_code_interpreter_attachment_enterprise_search_async.py b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_code_interpreter_attachment_enterprise_search_async.py index 5dfc0432ed0c..ce06f5119303 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_code_interpreter_attachment_enterprise_search_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_code_interpreter_attachment_enterprise_search_async.py @@ -29,7 +29,7 @@ VectorStoreDataSource, VectorStoreDataSourceAssetType, ) -from azure.identity import DefaultAzureCredential +from azure.identity.aio import DefaultAzureCredential # Create an Azure AI Client from a connection string, copied from your AI Studio project. diff --git a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_functions_async.py b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_functions_async.py index 42d5ea9e318e..b4fe9b63c3ff 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_functions_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_functions_async.py @@ -24,7 +24,12 @@ import time from azure.ai.projects.aio import AIProjectClient -from azure.ai.projects.models import AsyncFunctionTool, RequiredFunctionToolCall, SubmitToolOutputsAction +from azure.ai.projects.models import ( + AsyncFunctionTool, + RequiredFunctionToolCall, + SubmitToolOutputsAction, + ToolOutput +) from azure.identity.aio import DefaultAzureCredential import os @@ -32,7 +37,7 @@ 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 ";;;" # Customer needs to login to Azure subscription via Azure CLI and set the environment variables @@ -86,10 +91,10 @@ async def main(): try: output = await functions.execute(tool_call) tool_outputs.append( - { - "tool_call_id": tool_call.id, - "output": output, - } + ToolOutput( + tool_call_id = tool_call.id, + output = output, + ) ) except Exception as e: print(f"Error executing tool_call {tool_call.id}: {e}") diff --git a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_run_with_toolset_async.py b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_run_with_toolset_async.py index ad3950642ea9..db888c32239b 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_run_with_toolset_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_run_with_toolset_async.py @@ -24,7 +24,7 @@ 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.ai.projects.models import AsyncFunctionTool, AsyncToolSet from user_async_functions import user_async_functions @@ -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(), diff --git a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_stream_eventhandler_async.py b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_stream_eventhandler_async.py index b7d1df7351e6..cde160ef8d23 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_stream_eventhandler_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_stream_eventhandler_async.py @@ -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 ";;;" # Customer needs to login to Azure subscription via Azure CLI and set the environment variables diff --git a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_stream_eventhandler_with_toolset_async.py b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_stream_eventhandler_with_toolset_async.py index 0359dc6e00e8..a42c83867d45 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_stream_eventhandler_with_toolset_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_stream_eventhandler_with_toolset_async.py @@ -26,7 +26,6 @@ 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 import os @@ -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 ";;;" # Customer needs to login to Azure subscription via Azure CLI and set the environment variables diff --git a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_stream_iteration_async.py b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_stream_iteration_async.py index 691ace56eb56..f2341802df4b 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_stream_iteration_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_stream_iteration_async.py @@ -30,7 +30,7 @@ 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 ";;;" # Customer needs to login to Azure subscription via Azure CLI and set the environment variables diff --git a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_vector_store_batch_enterprise_file_search_async.py b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_vector_store_batch_enterprise_file_search_async.py index afaf45fa5bf8..273f640bcdd6 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_vector_store_batch_enterprise_file_search_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_vector_store_batch_enterprise_file_search_async.py @@ -24,7 +24,7 @@ from azure.ai.projects.aio import AIProjectClient from azure.ai.projects.models import FileSearchTool, VectorStoreDataSource, VectorStoreDataSourceAssetType -from azure.identity import DefaultAzureCredential +from azure.identity.aio import DefaultAzureCredential async def main(): @@ -95,7 +95,7 @@ async def main(): print(f"Created run, run ID: {run.id}") await project_client.agents.delete_vector_store(vector_store.id) - print("Deleted vectore store") + print("Deleted vector store") await project_client.agents.delete_agent(agent.id) print("Deleted agent") diff --git a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_vector_store_batch_file_search_async.py b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_vector_store_batch_file_search_async.py index 680806f68682..a3fd0de9d8ee 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_vector_store_batch_file_search_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_vector_store_batch_file_search_async.py @@ -28,7 +28,7 @@ from azure.identity.aio 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 ";;;" # Customer needs to login to Azure subscription via Azure CLI and set the environment variables diff --git a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_vector_store_enterprise_file_search_async.py b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_vector_store_enterprise_file_search_async.py index 16f036e1a95a..0d3e543e3cf3 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_vector_store_enterprise_file_search_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_vector_store_enterprise_file_search_async.py @@ -23,7 +23,7 @@ from azure.ai.projects.aio import AIProjectClient from azure.ai.projects.models import FileSearchTool, VectorStoreDataSource, VectorStoreDataSourceAssetType -from azure.identity import DefaultAzureCredential +from azure.identity.aio import DefaultAzureCredential async def main(): @@ -70,7 +70,7 @@ async def main(): print(f"Created run, run ID: {run.id}") await project_client.agents.delete_vector_store(vector_store.id) - print("Deleted vectore store") + print("Deleted vector store") await project_client.agents.delete_agent(agent.id) print("Deleted agent") diff --git a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_vector_store_file_search_async.py b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_vector_store_file_search_async.py index f06151be4359..ef3f0477a6a4 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_vector_store_file_search_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_vector_store_file_search_async.py @@ -23,7 +23,7 @@ from azure.ai.projects.aio import AIProjectClient from azure.ai.projects.models import FileSearchTool, FilePurpose -from azure.identity import DefaultAzureCredential +from azure.identity.aio import DefaultAzureCredential async def main(): @@ -72,7 +72,7 @@ async def main(): print(f"Created run, run ID: {run.id}") await project_client.agents.delete_vector_store(vector_store.id) - print("Deleted vectore store") + print("Deleted vector store") await project_client.agents.delete_agent(agent.id) print("Deleted agent") diff --git a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_with_file_search_attachment_async.py b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_with_file_search_attachment_async.py index 3eda61dd302a..2a1a97be333f 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_with_file_search_attachment_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/async_samples/sample_agents_with_file_search_attachment_async.py @@ -30,7 +30,7 @@ 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 ";;;" # Customer needs to login to Azure subscription via Azure CLI and set the environment variables diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agents_enterprise_file_search.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agents_enterprise_file_search.py index d06618c8e7c7..36ec4c6f4f34 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agents_enterprise_file_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agents_enterprise_file_search.py @@ -69,7 +69,7 @@ print(f"Created run, run ID: {run.id}") project_client.agents.delete_vector_store(vector_store.id) - print("Deleted vectore store") + print("Deleted vector store") project_client.agents.delete_agent(agent.id) print("Deleted agent") diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agents_functions_with_azure_monitor_tracing.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agents_functions_with_azure_monitor_tracing.py index ca53f180e32e..f4a17b589e28 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agents_functions_with_azure_monitor_tracing.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agents_functions_with_azure_monitor_tracing.py @@ -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 FunctionTool, RequiredFunctionToolCall, SubmitToolOutputsAction, ToolOutput diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agents_functions_with_console_tracing.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agents_functions_with_console_tracing.py index 031314cfa944..1cf7f8261e58 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agents_functions_with_console_tracing.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agents_functions_with_console_tracing.py @@ -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 FunctionTool, RequiredFunctionToolCall, SubmitToolOutputsAction, ToolOutput diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agents_stream_eventhandler_with_azure_monitor_tracing.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agents_stream_eventhandler_with_azure_monitor_tracing.py index c033fc1df0dd..dadb7b2cdadd 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agents_stream_eventhandler_with_azure_monitor_tracing.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agents_stream_eventhandler_with_azure_monitor_tracing.py @@ -25,9 +25,8 @@ """ -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, @@ -35,11 +34,11 @@ 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 ";;;" @@ -59,7 +58,12 @@ 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}") @@ -67,9 +71,6 @@ def on_thread_run(self, run: "ThreadRun") -> None: 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}") diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agents_stream_eventhandler_with_console_tracing.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agents_stream_eventhandler_with_console_tracing.py index 49320a9555b8..f00781834344 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agents_stream_eventhandler_with_console_tracing.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agents_stream_eventhandler_with_console_tracing.py @@ -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, @@ -63,7 +62,12 @@ 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}") @@ -71,9 +75,6 @@ def on_thread_run(self, run: "ThreadRun") -> None: 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}") diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agents_stream_eventhandler_with_functions.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agents_stream_eventhandler_with_functions.py index a061bf02d7f8..c506a585a6d0 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agents_stream_eventhandler_with_functions.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agents_stream_eventhandler_with_functions.py @@ -27,10 +27,14 @@ from azure.ai.projects.models import ( AgentEventHandler, FunctionTool, + MessageDeltaChunk, MessageDeltaTextContent, RequiredFunctionToolCall, + RunStep, SubmitToolOutputsAction, - ToolOutput, + ThreadMessage, + ThreadRun, + ToolOutput ) from azure.identity import DefaultAzureCredential from user_functions import user_functions diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agents_stream_eventhandler_with_toolset.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agents_stream_eventhandler_with_toolset.py index 0bbbcf3cab88..cf7d92e16e03 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agents_stream_eventhandler_with_toolset.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agents_stream_eventhandler_with_toolset.py @@ -21,10 +21,8 @@ PROJECT_CONNECTION_STRING - the Azure AI Project connection string, as found in your AI Studio Project. """ -import os from azure.ai.projects import AIProjectClient from azure.ai.projects.models import ( - Agent, MessageDeltaChunk, MessageDeltaTextContent, RunStep, @@ -32,7 +30,6 @@ ThreadRun, ) from azure.ai.projects.models import AgentEventHandler -from azure.ai.projects.operations import AgentsOperations from azure.identity import DefaultAzureCredential from azure.ai.projects.models import FunctionTool, ToolSet diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agents_vector_store_file_search.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agents_vector_store_file_search.py index a019fd96daf0..eacf51437485 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agents_vector_store_file_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agents_vector_store_file_search.py @@ -70,7 +70,7 @@ print(f"Created run, run ID: {run.id}") project_client.agents.delete_vector_store(vector_store.id) - print("Deleted vectore store") + print("Deleted vector store") project_client.agents.delete_agent(agent.id) print("Deleted agent") diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agents_with_file_search_attachment.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agents_with_file_search_attachment.py index 2a01e1f1836f..265fc1f7a38b 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agents_with_file_search_attachment.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agents_with_file_search_attachment.py @@ -20,12 +20,13 @@ Set this environment variables with your own values: PROJECT_CONNECTION_STRING - the Azure AI Project connection string, as found in your AI Studio Project. """ - import os from azure.ai.projects import AIProjectClient -from azure.ai.projects.models import FilePurpose -from azure.ai.projects.models import MessageAttachment -from azure.ai.projects.models import FileSearchTool +from azure.ai.projects.models import ( + FilePurpose, + FileSearchTool, + MessageAttachment +) from azure.identity import DefaultAzureCredential diff --git a/sdk/ai/azure-ai-projects/samples/connections/async_samples/sample_connections_async.py b/sdk/ai/azure-ai-projects/samples/connections/async_samples/sample_connections_async.py index fb7ee382356e..afd4f442e2d1 100644 --- a/sdk/ai/azure-ai-projects/samples/connections/async_samples/sample_connections_async.py +++ b/sdk/ai/azure-ai-projects/samples/connections/async_samples/sample_connections_async.py @@ -23,6 +23,7 @@ in your AI Studio Hub page. 3) MODEL_DEPLOYMENT_NAME - The model deployment name, as found in your AI Studio Project. """ +from typing import cast import asyncio import os @@ -31,7 +32,7 @@ from azure.identity.aio import DefaultAzureCredential -async def sample_connections_async(): +async def sample_connections_async() -> None: project_connection_string = os.environ["PROJECT_CONNECTION_STRING"] connection_name = os.environ["CONNECTION_NAME"] @@ -78,6 +79,7 @@ async def sample_connections_async(): if connection.connection_type == ConnectionType.AZURE_OPEN_AI: from openai import AsyncAzureOpenAI + from azure.core.credentials_async import AsyncTokenCredential if connection.authentication_type == AuthenticationType.API_KEY: print("====> Creating AzureOpenAI client using API key authentication") @@ -93,7 +95,7 @@ async def sample_connections_async(): client = AsyncAzureOpenAI( # See https://learn.microsoft.com/en-us/python/api/azure-identity/azure.identity?view=azure-python#azure-identity-get-bearer-token-provider azure_ad_token_provider=get_bearer_token_provider( - connection.token_credential, "https://cognitiveservices.azure.com/.default" + cast(AsyncTokenCredential, connection.token_credential), "https://cognitiveservices.azure.com/.default" ), azure_endpoint=connection.endpoint_url, api_version="2024-06-01", # See "Data plane - inference" row in table https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#api-specs @@ -116,27 +118,28 @@ async def sample_connections_async(): from azure.ai.inference.aio import ChatCompletionsClient from azure.ai.inference.models import UserMessage + from azure.core.credentials_async import AsyncTokenCredential if connection.authentication_type == AuthenticationType.API_KEY: print("====> Creating ChatCompletionsClient using API key authentication") from azure.core.credentials import AzureKeyCredential - client = ChatCompletionsClient( - endpoint=connection.endpoint_url, credential=AzureKeyCredential(connection.key) + inference_client = ChatCompletionsClient( + endpoint=connection.endpoint_url, credential=AzureKeyCredential(connection.key or "") ) elif connection.authentication_type == AuthenticationType.ENTRA_ID: # MaaS models do not yet support EntraID auth print("====> Creating ChatCompletionsClient using Entra ID authentication") - client = ChatCompletionsClient( - endpoint=connection.endpoint_url, credential=connection.properties.token_credential + inference_client = ChatCompletionsClient( + endpoint=connection.endpoint_url, credential=cast(AsyncTokenCredential, connection.token_credential) ) else: raise ValueError(f"Authentication type {connection.authentication_type} not supported.") - response = await client.complete( + response = await inference_client.complete( model=model_deployment_name, messages=[UserMessage(content="How many feet are in a mile?")] ) - await client.close() + await inference_client.close() print(response.choices[0].message.content) diff --git a/sdk/ai/azure-ai-projects/samples/connections/sample_connections.py b/sdk/ai/azure-ai-projects/samples/connections/sample_connections.py index 38f1397155c3..5cf2b7d0a297 100644 --- a/sdk/ai/azure-ai-projects/samples/connections/sample_connections.py +++ b/sdk/ai/azure-ai-projects/samples/connections/sample_connections.py @@ -23,14 +23,13 @@ in your AI Studio Hub page. 3) MODEL_DEPLOYMENT_NAME - The model deployment name, as found in your AI Studio Project. """ +from typing import cast import os from azure.ai.projects import AIProjectClient from azure.ai.projects.models import ConnectionType, AuthenticationType from azure.identity import DefaultAzureCredential -# from azure.identity import DefaultAzureCredential, get_bearer_token_provider - project_connection_string = os.environ["PROJECT_CONNECTION_STRING"] connection_name = os.environ["CONNECTION_NAME"] model_deployment_name = os.environ["MODEL_DEPLOYMENT_NAME"] @@ -86,12 +85,14 @@ ) elif connection.authentication_type == AuthenticationType.ENTRA_ID: print("====> Creating AzureOpenAI client using Entra ID authentication") + from azure.core.credentials import TokenCredential from azure.identity import get_bearer_token_provider client = AzureOpenAI( # See https://learn.microsoft.com/en-us/python/api/azure-identity/azure.identity?view=azure-python#azure-identity-get-bearer-token-provider azure_ad_token_provider=get_bearer_token_provider( - connection.token_credential, "https://cognitiveservices.azure.com/.default" + cast(TokenCredential, connection.token_credential), + "https://cognitiveservices.azure.com/.default" ), azure_endpoint=connection.endpoint_url, api_version="2024-06-01", # See "Data plane - inference" row in table https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#api-specs @@ -120,18 +121,18 @@ print("====> Creating ChatCompletionsClient using API key authentication") from azure.core.credentials import AzureKeyCredential - client = ChatCompletionsClient(endpoint=connection.endpoint_url, credential=AzureKeyCredential(connection.key)) + client = ChatCompletionsClient(endpoint=connection.endpoint_url, credential=AzureKeyCredential(connection.key or "")) elif connection.authentication_type == AuthenticationType.ENTRA_ID: # MaaS models do not yet support EntraID auth print("====> Creating ChatCompletionsClient using Entra ID authentication") - client = ChatCompletionsClient( - endpoint=connection.endpoint_url, credential=connection.properties.token_credential + inference_client = ChatCompletionsClient( + endpoint=connection.endpoint_url, credential=connection.token_credential ) else: raise ValueError(f"Authentication type {connection.authentication_type} not supported.") - response = client.complete( + response = inference_client.complete( model=model_deployment_name, messages=[UserMessage(content="How many feet are in a mile?")] ) - client.close() + inference_client.close() print(response.choices[0].message.content) diff --git a/sdk/ai/azure-ai-projects/samples/evaluations/async_samples/sample_evaluations_async.py b/sdk/ai/azure-ai-projects/samples/evaluations/async_samples/sample_evaluations_async.py index ee490f846797..92185dcd7048 100644 --- a/sdk/ai/azure-ai-projects/samples/evaluations/async_samples/sample_evaluations_async.py +++ b/sdk/ai/azure-ai-projects/samples/evaluations/async_samples/sample_evaluations_async.py @@ -21,7 +21,6 @@ PROJECT_CONNECTION_STRING - the Azure AI Project connection string, as found in your AI Studio Project. """ import asyncio -import time import os from azure.ai.projects.aio import AIProjectClient diff --git a/sdk/ai/azure-ai-projects/samples/evaluations/sample_evaluations.py b/sdk/ai/azure-ai-projects/samples/evaluations/sample_evaluations.py index 435e43875821..d370265679f5 100644 --- a/sdk/ai/azure-ai-projects/samples/evaluations/sample_evaluations.py +++ b/sdk/ai/azure-ai-projects/samples/evaluations/sample_evaluations.py @@ -21,7 +21,7 @@ PROJECT_CONNECTION_STRING - the Azure AI Project connection string, as found in your AI Studio Project. """ -import os, time +import os from azure.ai.projects import AIProjectClient from azure.identity import DefaultAzureCredential from azure.ai.projects.models import Evaluation, Dataset, EvaluatorConfiguration, ConnectionType @@ -82,5 +82,6 @@ print("----------------------------------------------------------------") print("Created evaluation, evaluation ID: ", get_evaluation_response.id) print("Evaluation status: ", get_evaluation_response.status) -print("AI Studio URI: ", get_evaluation_response.properties["AiStudioEvaluationUri"]) +if isinstance(get_evaluation_response.properties, dict): + print("AI Studio URI: ", get_evaluation_response.properties["AiStudioEvaluationUri"]) print("----------------------------------------------------------------") diff --git a/sdk/ai/azure-ai-projects/samples/evaluations/sample_evaluations_schedules.py b/sdk/ai/azure-ai-projects/samples/evaluations/sample_evaluations_schedules.py index 18cbb8fb59ac..c7dde4be6a86 100644 --- a/sdk/ai/azure-ai-projects/samples/evaluations/sample_evaluations_schedules.py +++ b/sdk/ai/azure-ai-projects/samples/evaluations/sample_evaluations_schedules.py @@ -4,7 +4,6 @@ from azure.ai.projects.models import ( ApplicationInsightsConfiguration, EvaluatorConfiguration, - SamplingStrategy, EvaluationSchedule, CronTrigger, RecurrenceTrigger, diff --git a/sdk/ai/azure-ai-projects/samples/inference/sample_chat_completions_with_azure_ai_inference_client_and_console_tracing.py b/sdk/ai/azure-ai-projects/samples/inference/sample_chat_completions_with_azure_ai_inference_client_and_console_tracing.py index bb7254a594e8..7a901a20c5f6 100644 --- a/sdk/ai/azure-ai-projects/samples/inference/sample_chat_completions_with_azure_ai_inference_client_and_console_tracing.py +++ b/sdk/ai/azure-ai-projects/samples/inference/sample_chat_completions_with_azure_ai_inference_client_and_console_tracing.py @@ -30,8 +30,8 @@ """ import os import sys -from azure.ai.projects import AIProjectClient from azure.ai.inference.models import UserMessage +from azure.ai.projects import AIProjectClient from azure.identity import DefaultAzureCredential project_connection_string = os.environ["PROJECT_CONNECTION_STRING"] diff --git a/sdk/ai/azure-ai-projects/tests/agents/test_agents_client.py b/sdk/ai/azure-ai-projects/tests/agents/test_agents_client.py index 093245923d15..83cc23838f51 100644 --- a/sdk/ai/azure-ai-projects/tests/agents/test_agents_client.py +++ b/sdk/ai/azure-ai-projects/tests/agents/test_agents_client.py @@ -1,9 +1,4 @@ # pylint: disable=too-many-lines -# pylint: disable=too-many-lines -# pylint: disable=too-many-lines -# pylint: disable=too-many-lines -# pylint: disable=too-many-lines -# pylint: disable=too-many-lines # # ------------------------------------ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. @@ -22,7 +17,6 @@ import functools from azure.ai.projects import AIProjectClient -from azure.core.pipeline.transport import RequestsTransport from devtools_testutils import AzureRecordedTestCase, EnvironmentVariableLoader, recorded_by_proxy from azure.ai.projects.models import ( CodeInterpreterTool, @@ -37,10 +31,10 @@ ToolResources, ToolSet, VectorStore, - VectorStoreAzureConfigurations, - VectorStorageConfiguration, - VectorStorageDataSource, - VectorStorageDataSourceAssetType, + VectorStoreConfigurations, + VectorStoreConfiguration, + VectorStoreDataSource, + VectorStoreDataSourceAssetType, ) @@ -1212,9 +1206,9 @@ def _do_test_create_vector_store(self, **kwargs): ds = None else: ds = [ - VectorStorageDataSource( + VectorStoreDataSource( storage_uri=kwargs["azure_ai_projects_data_path"], - asset_type=VectorStorageDataSourceAssetType.URI_ASSET, + asset_type=VectorStoreDataSourceAssetType.URI_ASSET, ) ] vector_store = ai_client.agents.create_vector_store_and_poll( @@ -1232,15 +1226,15 @@ def test_vector_store_threads_file_search_azure(self, **kwargs): assert isinstance(ai_client, AIProjectClient) ds = [ - VectorStorageDataSource( + VectorStoreDataSource( storage_uri=kwargs["azure_ai_projects_data_path"], - asset_type=VectorStorageDataSourceAssetType.URI_ASSET, + asset_type=VectorStoreDataSourceAssetType.URI_ASSET, ) ] fs = FileSearchToolResource( vector_stores=[ - VectorStoreAzureConfigurations( - store_name="my_vector_store", store_configuration=VectorStorageConfiguration(data_sources=ds) + VectorStoreConfigurations( + store_name="my_vector_store", store_configuration=VectorStoreConfiguration(data_sources=ds) ) ] ) @@ -1292,7 +1286,7 @@ def _do_test_create_vector_store_add_file(self, **kwargs): if file_id: ds = None else: - ds = [VectorStorageDataSource(storage_uri=kwargs["azure_ai_projects_data_path"], asset_type="uri_asset")] + ds = [VectorStoreDataSource(storage_uri=kwargs["azure_ai_projects_data_path"], asset_type="uri_asset")] vector_store = ai_client.agents.create_vector_store_and_poll(file_ids=[], name="sample_vector_store") assert vector_store.id vector_store_file = ai_client.agents.create_vector_store_file( @@ -1327,9 +1321,9 @@ def _do_test_create_vector_store_batch(self, **kwargs): else: file_ids = None ds = [ - VectorStorageDataSource( + VectorStoreDataSource( storage_uri=kwargs["azure_ai_projects_data_path"], - asset_type=VectorStorageDataSourceAssetType.URI_ASSET, + asset_type=VectorStoreDataSourceAssetType.URI_ASSET, ) ] vector_store = ai_client.agents.create_vector_store_and_poll(file_ids=[], name="sample_vector_store") @@ -1380,8 +1374,8 @@ def _test_file_search( @recorded_by_proxy def test_message_attachement_azure(self, **kwargs): """Test message attachment with azure ID.""" - ds = VectorStorageDataSource( - storage_uri=kwargs["azure_ai_projects_data_path"], asset_type=VectorStorageDataSourceAssetType.URI_ASSET + ds = VectorStoreDataSource( + storage_uri=kwargs["azure_ai_projects_data_path"], asset_type=VectorStoreDataSourceAssetType.URI_ASSET ) self._do_test_message_attachment(data_sources=[ds], **kwargs) @@ -1433,8 +1427,8 @@ def _do_test_message_attachment(self, **kwargs): @recorded_by_proxy def test_create_assistant_with_interpreter_azure(self, **kwargs): """Test Create assistant with code interpreter with azure asset ids.""" - ds = VectorStorageDataSource( - storage_uri=kwargs["azure_ai_projects_data_path"], asset_type=VectorStorageDataSourceAssetType.URI_ASSET + ds = VectorStoreDataSource( + storage_uri=kwargs["azure_ai_projects_data_path"], asset_type=VectorStoreDataSourceAssetType.URI_ASSET ) self._do_test_create_assistant_with_interpreter(data_sources=[ds], **kwargs) @@ -1490,8 +1484,8 @@ def _do_test_create_assistant_with_interpreter(self, **kwargs): @recorded_by_proxy def test_create_thread_with_interpreter_azure(self, **kwargs): """Test Create assistant with code interpreter with azure asset ids.""" - ds = VectorStorageDataSource( - storage_uri=kwargs["azure_ai_projects_data_path"], asset_type=VectorStorageDataSourceAssetType.URI_ASSET + ds = VectorStoreDataSource( + storage_uri=kwargs["azure_ai_projects_data_path"], asset_type=VectorStoreDataSourceAssetType.URI_ASSET ) self._do_test_create_thread_with_interpreter(data_sources=[ds], **kwargs) @@ -1552,15 +1546,15 @@ def test_create_assistant_with_inline_vs_azure(self, **kwargs): assert isinstance(ai_client, AIProjectClient) ds = [ - VectorStorageDataSource( + VectorStoreDataSource( storage_uri=kwargs["azure_ai_projects_data_path"], - asset_type=VectorStorageDataSourceAssetType.URI_ASSET, + asset_type=VectorStoreDataSourceAssetType.URI_ASSET, ) ] fs = FileSearchToolResource( vector_stores=[ - VectorStoreAzureConfigurations( - store_name="my_vector_store", store_configuration=VectorStorageConfiguration(data_sources=ds) + VectorStoreConfigurations( + store_name="my_vector_store", store_configuration=VectorStoreConfiguration(data_sources=ds) ) ] ) @@ -1593,8 +1587,8 @@ def test_create_assistant_with_inline_vs_azure(self, **kwargs): @recorded_by_proxy def test_create_attachment_in_thread_azure(self, **kwargs): """Create thread with message attachment inline with azure asset IDs.""" - ds = VectorStorageDataSource( - storage_uri=kwargs["azure_ai_projects_data_path"], asset_type=VectorStorageDataSourceAssetType.URI_ASSET + ds = VectorStoreDataSource( + storage_uri=kwargs["azure_ai_projects_data_path"], asset_type=VectorStoreDataSourceAssetType.URI_ASSET ) self._do_test_create_attachment_in_thread_azure(data_sources=[ds], **kwargs) diff --git a/sdk/ai/azure-ai-projects/tests/agents/test_agents_client_async.py b/sdk/ai/azure-ai-projects/tests/agents/test_agents_client_async.py index 24ebd1567982..e456be2ebb45 100644 --- a/sdk/ai/azure-ai-projects/tests/agents/test_agents_client_async.py +++ b/sdk/ai/azure-ai-projects/tests/agents/test_agents_client_async.py @@ -1,16 +1,9 @@ # pylint: disable=too-many-lines -# pylint: disable=too-many-lines -# pylint: disable=too-many-lines -# pylint: disable=too-many-lines -# pylint: disable=too-many-lines -# pylint: disable=too-many-lines -# pylint: disable=too-many-lines -# pylint: disable=too-many-lines -# pylint: disable=too-many-lines # # ------------------------------------ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # ------------------------------------ +# cSpell:disable import datetime import functools import json diff --git a/sdk/ai/azure-ai-projects/tests/agents/test_vector_store.py b/sdk/ai/azure-ai-projects/tests/agents/test_vector_store.py index ffad05175c55..5796e9a7fa3f 100644 --- a/sdk/ai/azure-ai-projects/tests/agents/test_vector_store.py +++ b/sdk/ai/azure-ai-projects/tests/agents/test_vector_store.py @@ -2,7 +2,7 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # ------------------------------------ - +# cSpell:disable import unittest from azure.ai.projects._model_base import _deserialize from azure.ai.projects.models import _models diff --git a/sdk/ai/azure-ai-projects/tests/check_sample_name.sh b/sdk/ai/azure-ai-projects/tests/check_sample_name.sh index e6a6f70dffa2..d705795e6fc8 100644 --- a/sdk/ai/azure-ai-projects/tests/check_sample_name.sh +++ b/sdk/ai/azure-ai-projects/tests/check_sample_name.sh @@ -1,6 +1,6 @@ #!/bin/bash # This is simple helper script to chreck the name of a file -# the name sgould encounter in two places: +# the name should encounter in two places: # FILE: $fname # ... # python $fname