Skip to content

Commit e95ad3f

Browse files
authored
Merge pull request #275 from frdeange/patch-2
Update Python Code Examples as methods are updated
2 parents 0893317 + 72e4317 commit e95ad3f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,19 @@ 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 looks for the AI Search Connection ID and saves it as variable conn_id
89+
90+
# If you have more than one AI search connection, try to establish the value in your .env file.
91+
# Extract the connection list.
92+
conn_list = project_client.connections._list_connections()["value"]
9193
conn_id = ""
94+
95+
# Search in the metadata field of each connection in the list for the azure_ai_search type and get the id value to establish the variable
9296
for conn in conn_list:
93-
if conn.connection_type == "AZURE_AI_SEARCH":
94-
print(f"Connection ID: {conn.id}")
97+
metadata = conn["properties"].get("metadata", {})
98+
if metadata.get("type", "").upper() == "AZURE_AI_SEARCH":
99+
conn_id = conn["id"]
100+
break
95101
```
96102
# [C#](#tab/csharp)
97103
```csharp
@@ -429,4 +435,4 @@ curl $AZURE_AI_AGENTS_ENDPOINT/threads/thread_abc123/messages?api-version=2024-1
429435
-H "Authorization: Bearer $AZURE_AI_AGENTS_TOKEN"
430436
```
431437
432-
---
438+
---

0 commit comments

Comments
 (0)