Skip to content

Commit b02a3e0

Browse files
authored
Push updates from the latest typespec (#40616)
* Fix * Fix linters * Fix
1 parent aedeac2 commit b02a3e0

18 files changed

+605
-172
lines changed

sdk/ai/azure-ai-assistants/README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ auth = OpenApiAnonymousAuthDetails()
652652

653653
# Initialize assistant OpenApi tool using the read in OpenAPI spec
654654
openapi_tool = OpenApiTool(
655-
name="get_weather", spec=openapi_weather, description="Retrieve weather information for a location", auth=auth
655+
name="get_weather", spec=openapi_weather, description="Retrieve weather information for a location", auth=auth, default_parameters=["format"]
656656
)
657657
openapi_tool.add_definition(
658658
name="get_countries", spec=openapi_countries, description="Retrieve a list of countries", auth=auth
@@ -743,6 +743,19 @@ thread = assistants_client.create_thread(tool_resources=file_search.resources)
743743
```
744744

745745
<!-- END SNIPPET -->
746+
747+
#### List Threads
748+
749+
To list all threads attached to a given agent, use the list_threads API:
750+
751+
<!-- SNIPPET:sample_assistants_basics.list_threads -->
752+
753+
```python
754+
threads = assistants_client.list_threads()
755+
```
756+
757+
<!-- END SNIPPET -->
758+
746759
### Create Message
747760

748761
To create a message for assistant to process, you pass `user` as `role` and a question as `content`:

sdk/ai/azure-ai-assistants/apiview-properties.json

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
"azure.ai.assistants.models.BingGroundingToolDefinition": "Azure.AI.Assistants.BingGroundingToolDefinition",
2020
"azure.ai.assistants.models.CodeInterpreterToolDefinition": "Azure.AI.Assistants.CodeInterpreterToolDefinition",
2121
"azure.ai.assistants.models.CodeInterpreterToolResource": "Azure.AI.Assistants.CodeInterpreterToolResource",
22+
"azure.ai.assistants.models.ConnectedAgentDetails": "Azure.AI.Assistants.ConnectedAgentDetails",
23+
"azure.ai.assistants.models.ConnectedAgentToolDefinition": "Azure.AI.Assistants.ConnectedAgentToolDefinition",
2224
"azure.ai.assistants.models.FileDeletionStatus": "Azure.AI.Assistants.FileDeletionStatus",
2325
"azure.ai.assistants.models.FileListResponse": "Azure.AI.Assistants.FileListResponse",
2426
"azure.ai.assistants.models.FileSearchRankingOptions": "Azure.AI.Assistants.FileSearchRankingOptions",
@@ -67,6 +69,7 @@
6769
"azure.ai.assistants.models.MicrosoftFabricToolDefinition": "Azure.AI.Assistants.MicrosoftFabricToolDefinition",
6870
"azure.ai.assistants.models.OpenAIFile": "Azure.AI.Assistants.OpenAIFile",
6971
"azure.ai.assistants.models.OpenAIPageableListOfAssistant": "Azure.AI.Assistants.OpenAIPageableListOf",
72+
"azure.ai.assistants.models.OpenAIPageableListOfAssistantThread": "Azure.AI.Assistants.OpenAIPageableListOf",
7073
"azure.ai.assistants.models.OpenAIPageableListOfRunStep": "Azure.AI.Assistants.OpenAIPageableListOf",
7174
"azure.ai.assistants.models.OpenAIPageableListOfThreadMessage": "Azure.AI.Assistants.OpenAIPageableListOf",
7275
"azure.ai.assistants.models.OpenAIPageableListOfThreadRun": "Azure.AI.Assistants.OpenAIPageableListOf",
@@ -210,6 +213,7 @@
210213
"azure.ai.assistants.AssistantsClient.get_thread": "Azure.AI.Assistants.getThread",
211214
"azure.ai.assistants.AssistantsClient.update_thread": "Azure.AI.Assistants.updateThread",
212215
"azure.ai.assistants.AssistantsClient.delete_thread": "Azure.AI.Assistants.deleteThread",
216+
"azure.ai.assistants.AssistantsClient.list_threads": "Azure.AI.Assistants.listThreads",
213217
"azure.ai.assistants.AssistantsClient.create_message": "Azure.AI.Assistants.createMessage",
214218
"azure.ai.assistants.AssistantsClient.list_messages": "Azure.AI.Assistants.listMessages",
215219
"azure.ai.assistants.AssistantsClient.get_message": "Azure.AI.Assistants.getMessage",

sdk/ai/azure-ai-assistants/azure/ai/assistants/_operations/_operations.py

+120
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,40 @@ def build_assistants_delete_thread_request(thread_id: str, **kwargs: Any) -> Htt
279279
return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs)
280280

281281

282+
def build_assistants_list_threads_request(
283+
*,
284+
limit: Optional[int] = None,
285+
order: Optional[Union[str, _models.ListSortOrder]] = None,
286+
after: Optional[str] = None,
287+
before: Optional[str] = None,
288+
**kwargs: Any
289+
) -> HttpRequest:
290+
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
291+
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})
292+
293+
api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2025-05-15-preview"))
294+
accept = _headers.pop("Accept", "application/json")
295+
296+
# Construct URL
297+
_url = "/threads"
298+
299+
# Construct parameters
300+
_params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
301+
if limit is not None:
302+
_params["limit"] = _SERIALIZER.query("limit", limit, "int")
303+
if order is not None:
304+
_params["order"] = _SERIALIZER.query("order", order, "str")
305+
if after is not None:
306+
_params["after"] = _SERIALIZER.query("after", after, "str")
307+
if before is not None:
308+
_params["before"] = _SERIALIZER.query("before", before, "str")
309+
310+
# Construct headers
311+
_headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
312+
313+
return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs)
314+
315+
282316
def build_assistants_create_message_request(thread_id: str, **kwargs: Any) -> HttpRequest:
283317
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
284318
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})
@@ -2326,6 +2360,92 @@ def delete_thread(self, thread_id: str, **kwargs: Any) -> _models.ThreadDeletion
23262360

23272361
return deserialized # type: ignore
23282362

2363+
@distributed_trace
2364+
def list_threads(
2365+
self,
2366+
*,
2367+
limit: Optional[int] = None,
2368+
order: Optional[Union[str, _models.ListSortOrder]] = None,
2369+
after: Optional[str] = None,
2370+
before: Optional[str] = None,
2371+
**kwargs: Any
2372+
) -> _models.OpenAIPageableListOfAssistantThread:
2373+
"""Gets a list of threads that were previously created.
2374+
2375+
:keyword limit: A limit on the number of objects to be returned. Limit can range between 1 and
2376+
100, and the default is 20. Default value is None.
2377+
:paramtype limit: int
2378+
:keyword order: Sort order by the created_at timestamp of the objects. asc for ascending order
2379+
and desc for descending order. Known values are: "asc" and "desc". Default value is None.
2380+
:paramtype order: str or ~azure.ai.assistants.models.ListSortOrder
2381+
:keyword after: A cursor for use in pagination. after is an object ID that defines your place
2382+
in the list. For instance, if you make a list request and receive 100 objects, ending with
2383+
obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the
2384+
list. Default value is None.
2385+
:paramtype after: str
2386+
:keyword before: A cursor for use in pagination. before is an object ID that defines your place
2387+
in the list. For instance, if you make a list request and receive 100 objects, ending with
2388+
obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of
2389+
the list. Default value is None.
2390+
:paramtype before: str
2391+
:return: OpenAIPageableListOfAssistantThread. The OpenAIPageableListOfAssistantThread is
2392+
compatible with MutableMapping
2393+
:rtype: ~azure.ai.assistants.models.OpenAIPageableListOfAssistantThread
2394+
:raises ~azure.core.exceptions.HttpResponseError:
2395+
"""
2396+
error_map: MutableMapping = {
2397+
401: ClientAuthenticationError,
2398+
404: ResourceNotFoundError,
2399+
409: ResourceExistsError,
2400+
304: ResourceNotModifiedError,
2401+
}
2402+
error_map.update(kwargs.pop("error_map", {}) or {})
2403+
2404+
_headers = kwargs.pop("headers", {}) or {}
2405+
_params = kwargs.pop("params", {}) or {}
2406+
2407+
cls: ClsType[_models.OpenAIPageableListOfAssistantThread] = kwargs.pop("cls", None)
2408+
2409+
_request = build_assistants_list_threads_request(
2410+
limit=limit,
2411+
order=order,
2412+
after=after,
2413+
before=before,
2414+
api_version=self._config.api_version,
2415+
headers=_headers,
2416+
params=_params,
2417+
)
2418+
path_format_arguments = {
2419+
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
2420+
}
2421+
_request.url = self._client.format_url(_request.url, **path_format_arguments)
2422+
2423+
_stream = kwargs.pop("stream", False)
2424+
pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
2425+
_request, stream=_stream, **kwargs
2426+
)
2427+
2428+
response = pipeline_response.http_response
2429+
2430+
if response.status_code not in [200]:
2431+
if _stream:
2432+
try:
2433+
response.read() # Load the body in memory and close the socket
2434+
except (StreamConsumedError, StreamClosedError):
2435+
pass
2436+
map_error(status_code=response.status_code, response=response, error_map=error_map)
2437+
raise HttpResponseError(response=response)
2438+
2439+
if _stream:
2440+
deserialized = response.iter_bytes()
2441+
else:
2442+
deserialized = _deserialize(_models.OpenAIPageableListOfAssistantThread, response.json())
2443+
2444+
if cls:
2445+
return cls(pipeline_response, deserialized, {}) # type: ignore
2446+
2447+
return deserialized # type: ignore
2448+
23292449
@overload
23302450
def create_message(
23312451
self,

sdk/ai/azure-ai-assistants/azure/ai/assistants/_patch.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, TokenCre
6868
f"/Microsoft.MachineLearningServices/workspaces/{project_name}"
6969
)
7070
# Override the credential scope with the legacy one.
71-
kwargs['credential_scopes'] = ["https://management.azure.com/.default"]
71+
kwargs["credential_scopes"] = ["https://management.azure.com/.default"]
7272
# End of legacy endpoints handling.
7373
super().__init__(endpoint, credential, **kwargs)
7474
self._toolset: Dict[str, _models.ToolSet] = {}
@@ -1791,7 +1791,7 @@ def upload_file(
17911791
"""
17921792
Uploads a file for use by other operations, delegating to the generated operations.
17931793
1794-
1794+
17951795
17961796
:param body: JSON. Required if `file` and `purpose` are not provided.
17971797
:type body: Optional[JSON]

sdk/ai/azure-ai-assistants/azure/ai/assistants/aio/_operations/_operations.py

+87
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
build_assistants_list_messages_request,
6060
build_assistants_list_run_steps_request,
6161
build_assistants_list_runs_request,
62+
build_assistants_list_threads_request,
6263
build_assistants_list_vector_store_file_batch_files_request,
6364
build_assistants_list_vector_store_files_request,
6465
build_assistants_list_vector_stores_request,
@@ -1222,6 +1223,92 @@ async def delete_thread(self, thread_id: str, **kwargs: Any) -> _models.ThreadDe
12221223

12231224
return deserialized # type: ignore
12241225

1226+
@distributed_trace_async
1227+
async def list_threads(
1228+
self,
1229+
*,
1230+
limit: Optional[int] = None,
1231+
order: Optional[Union[str, _models.ListSortOrder]] = None,
1232+
after: Optional[str] = None,
1233+
before: Optional[str] = None,
1234+
**kwargs: Any
1235+
) -> _models.OpenAIPageableListOfAssistantThread:
1236+
"""Gets a list of threads that were previously created.
1237+
1238+
:keyword limit: A limit on the number of objects to be returned. Limit can range between 1 and
1239+
100, and the default is 20. Default value is None.
1240+
:paramtype limit: int
1241+
:keyword order: Sort order by the created_at timestamp of the objects. asc for ascending order
1242+
and desc for descending order. Known values are: "asc" and "desc". Default value is None.
1243+
:paramtype order: str or ~azure.ai.assistants.models.ListSortOrder
1244+
:keyword after: A cursor for use in pagination. after is an object ID that defines your place
1245+
in the list. For instance, if you make a list request and receive 100 objects, ending with
1246+
obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the
1247+
list. Default value is None.
1248+
:paramtype after: str
1249+
:keyword before: A cursor for use in pagination. before is an object ID that defines your place
1250+
in the list. For instance, if you make a list request and receive 100 objects, ending with
1251+
obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of
1252+
the list. Default value is None.
1253+
:paramtype before: str
1254+
:return: OpenAIPageableListOfAssistantThread. The OpenAIPageableListOfAssistantThread is
1255+
compatible with MutableMapping
1256+
:rtype: ~azure.ai.assistants.models.OpenAIPageableListOfAssistantThread
1257+
:raises ~azure.core.exceptions.HttpResponseError:
1258+
"""
1259+
error_map: MutableMapping = {
1260+
401: ClientAuthenticationError,
1261+
404: ResourceNotFoundError,
1262+
409: ResourceExistsError,
1263+
304: ResourceNotModifiedError,
1264+
}
1265+
error_map.update(kwargs.pop("error_map", {}) or {})
1266+
1267+
_headers = kwargs.pop("headers", {}) or {}
1268+
_params = kwargs.pop("params", {}) or {}
1269+
1270+
cls: ClsType[_models.OpenAIPageableListOfAssistantThread] = kwargs.pop("cls", None)
1271+
1272+
_request = build_assistants_list_threads_request(
1273+
limit=limit,
1274+
order=order,
1275+
after=after,
1276+
before=before,
1277+
api_version=self._config.api_version,
1278+
headers=_headers,
1279+
params=_params,
1280+
)
1281+
path_format_arguments = {
1282+
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
1283+
}
1284+
_request.url = self._client.format_url(_request.url, **path_format_arguments)
1285+
1286+
_stream = kwargs.pop("stream", False)
1287+
pipeline_response: PipelineResponse = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access
1288+
_request, stream=_stream, **kwargs
1289+
)
1290+
1291+
response = pipeline_response.http_response
1292+
1293+
if response.status_code not in [200]:
1294+
if _stream:
1295+
try:
1296+
await response.read() # Load the body in memory and close the socket
1297+
except (StreamConsumedError, StreamClosedError):
1298+
pass
1299+
map_error(status_code=response.status_code, response=response, error_map=error_map)
1300+
raise HttpResponseError(response=response)
1301+
1302+
if _stream:
1303+
deserialized = response.iter_bytes()
1304+
else:
1305+
deserialized = _deserialize(_models.OpenAIPageableListOfAssistantThread, response.json())
1306+
1307+
if cls:
1308+
return cls(pipeline_response, deserialized, {}) # type: ignore
1309+
1310+
return deserialized # type: ignore
1311+
12251312
@overload
12261313
async def create_message(
12271314
self,

sdk/ai/azure-ai-assistants/azure/ai/assistants/aio/_patch.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def __init__(
7171
f"/Microsoft.MachineLearningServices/workspaces/{project_name}"
7272
)
7373
# Override the credential scope with the legacy one.
74-
kwargs['credential_scopes'] = ["https://management.azure.com/.default"]
74+
kwargs["credential_scopes"] = ["https://management.azure.com/.default"]
7575
# End of legacy endpoints handling.
7676
super().__init__(endpoint, credential, **kwargs)
7777
self._toolset: Dict[str, _models.AsyncToolSet] = {}

sdk/ai/azure-ai-assistants/azure/ai/assistants/models/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
BingGroundingToolDefinition,
3232
CodeInterpreterToolDefinition,
3333
CodeInterpreterToolResource,
34+
ConnectedAgentDetails,
35+
ConnectedAgentToolDefinition,
3436
FileDeletionStatus,
3537
FileListResponse,
3638
FileSearchRankingOptions,
@@ -79,6 +81,7 @@
7981
MicrosoftFabricToolDefinition,
8082
OpenAIFile,
8183
OpenAIPageableListOfAssistant,
84+
OpenAIPageableListOfAssistantThread,
8285
OpenAIPageableListOfRunStep,
8386
OpenAIPageableListOfThreadMessage,
8487
OpenAIPageableListOfThreadRun,
@@ -240,6 +243,8 @@
240243
"BingGroundingToolDefinition",
241244
"CodeInterpreterToolDefinition",
242245
"CodeInterpreterToolResource",
246+
"ConnectedAgentDetails",
247+
"ConnectedAgentToolDefinition",
243248
"FileDeletionStatus",
244249
"FileListResponse",
245250
"FileSearchRankingOptions",
@@ -288,6 +293,7 @@
288293
"MicrosoftFabricToolDefinition",
289294
"OpenAIFile",
290295
"OpenAIPageableListOfAssistant",
296+
"OpenAIPageableListOfAssistantThread",
291297
"OpenAIPageableListOfRunStep",
292298
"OpenAIPageableListOfThreadMessage",
293299
"OpenAIPageableListOfThreadRun",

sdk/ai/azure-ai-assistants/azure/ai/assistants/models/_enums.py

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class AssistantsNamedToolChoiceType(str, Enum, metaclass=CaseInsensitiveEnumMeta
4747
"""Tool type ``azure_ai_search``"""
4848
BING_CUSTOM_SEARCH = "bing_custom_search"
4949
"""Tool type ``bing_custom_search``"""
50+
CONNECTED_AGENT = "connected_agent"
51+
"""Tool type ``connected_agent``"""
5052

5153

5254
class AssistantStreamEvent(str, Enum, metaclass=CaseInsensitiveEnumMeta):

0 commit comments

Comments
 (0)