Skip to content

Commit 20cc68a

Browse files
authored
Update Python Code Examples as methods are updated
Python code to extract the connectionID of a Azure AI Search connection list of AI Project. The previous doc is not updated with the changes in AI Agent Service methods.
1 parent 9f898c9 commit 20cc68a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

articles/ai-services/agents/includes/azure-search/code-examples.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,18 @@ Get the connection ID of the Azure AI Search connection in the project. You can
8585

8686
```python
8787
# AI Search resource connection ID
88-
# This code prints out the connection ID of all the Azure AI Search connections in the project
89-
# If you have more than one AI search connection, make sure to select the correct one that contains the index you want to use.
90-
conn_list = project_client.connections.list()
88+
# This code look for the AI Search Connection ID and safe it as variable conn_id
89+
# If you have more than one AI search connection, try to stablished the value into your .env file.
90+
# Extract the connection list.
91+
conn_list = project_client.connections._list_connections()["value"]
9192
conn_id = ""
93+
94+
# Search into the metadata field the azure_ai_search type and get the id value to stablished the variable
9295
for conn in conn_list:
93-
if conn.connection_type == "AZURE_AI_SEARCH":
94-
print(f"Connection ID: {conn.id}")
96+
metadata = conn["properties"].get("metadata", {})
97+
if metadata.get("type", "").upper() == "AZURE_AI_SEARCH":
98+
conn_id = conn["id"]
99+
break
95100
```
96101
# [C#](#tab/csharp)
97102
```csharp
@@ -429,4 +434,4 @@ curl $AZURE_AI_AGENTS_ENDPOINT/threads/thread_abc123/messages?api-version=2024-1
429434
-H "Authorization: Bearer $AZURE_AI_AGENTS_TOKEN"
430435
```
431436
432-
---
437+
---

0 commit comments

Comments
 (0)