Skip to content

Commit 199dec1

Browse files
committed
updating csharp code
1 parent 29d4d35 commit 199dec1

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

articles/ai-foundry/agents/how-to/tools/bing-code-samples.md

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,29 @@ print("Deleted agent")
162162
::: zone-end
163163

164164
::: zone pivot="csharp"
165+
166+
* The endpoint for your project. This string is in the format:
167+
168+
`https://<AIFoundryResourceName>.services.ai.azure.com/api/projects/<ProjectName>`
169+
170+
[!INCLUDE [endpoint-string-portal](../../includes/endpoint-string-portal.md)]
171+
172+
Set this endpoint in an environment variable named `ProjectEndpoint`.
173+
174+
* The name of your model deployment.
175+
176+
[!INCLUDE [model-name-portal](../../includes/model-name-portal.md)]
177+
178+
Save the name of your model deployment name as an environment variable named `ModelDeploymentName`.
179+
180+
* The connection ID for your Grounding with Bing Search resource. You can find it in the Azure AI Foundry portal by selecting **Management center** from the left navigation menu. Then selecting **Connected resources**. Then select your bing resource.
181+
182+
:::image type="content" source="../../media/tools/deep-research/bing-resource-name.png" alt-text="A screenshot showing the Grounding with Bing Search resource name. " lightbox="../../media/tools/deep-research/bing-resource-name.png":::
183+
184+
Copy the ID, and save it to an environment variable named `BingConnectionId`.
185+
186+
:::image type="content" source="../../media/tools/deep-research/bing-id.png" alt-text="A screenshot showing the Grounding with Bing Search ID. " lightbox="../../media/tools/deep-research/bing-id.png":::
187+
165188
## Create a project client
166189

167190
Create a client object, which will contain the project endpoint for connecting to your AI project and other resources.
@@ -170,19 +193,10 @@ Create a client object, which will contain the project endpoint for connecting t
170193
using Azure;
171194
using Azure.AI.Agents.Persistent;
172195
using Azure.Identity;
173-
using Microsoft.Extensions.Configuration;
174-
using System;
175-
using System.Threading;
176196

177-
// Get Connection information from app configuration
178-
IConfigurationRoot configuration = new ConfigurationBuilder()
179-
.SetBasePath(AppContext.BaseDirectory)
180-
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
181-
.Build();
182-
183-
var projectEndpoint = configuration["ProjectEndpoint"];
184-
var modelDeploymentName = configuration["ModelDeploymentName"];
185-
var bingConnectionId = configuration["BingConnectionId"];
197+
var projectEndpoint = System.Environment.GetEnvironmentVariable("ProjectEndpoint");
198+
var projectEndpoint = System.Environment.GetEnvironmentVariable("ModelDeploymentName");
199+
var projectEndpoint = System.Environment.GetEnvironmentVariable("BingConnectionId");
186200

187201
// Create the Agent Client
188202
PersistentAgentsClient agentClient = new(projectEndpoint, new DefaultAzureCredential());
@@ -193,18 +207,10 @@ PersistentAgentsClient agentClient = new(projectEndpoint, new DefaultAzureCreden
193207
To make the Grounding with Bing search tool available to your agent, use a connection to initialize the tool and attach it to the agent. You can find your connection in the **connected resources** section of your project in the [Azure AI Foundry portal](https://ai.azure.com/?cid=learnDocs).
194208

195209
```csharp
196-
BingGroundingSearchConfiguration searchConfig = new BingGroundingSearchConfiguration(bingConnectionId)
197-
{
198-
Count = 5,
199-
Freshness = "Week"
200-
};
201-
202-
// Create the BingGroundingToolDefinition object used when creating the agent
203-
BingGroundingToolDefinition bingGroundingTool = new BingGroundingToolDefinition(
210+
211+
BingGroundingToolDefinition bingGroundingTool = new(
204212
new BingGroundingSearchToolParameters(
205-
[
206-
searchConfig
207-
]
213+
[new BingGroundingSearchConfiguration(bingConnectionId)]
208214
)
209215
);
210216

@@ -335,7 +341,6 @@ Clean up the resources from this sample.
335341
agentClient.Threads.DeleteThread(threadId: thread.Id);
336342
agentClient.Administration.DeleteAgent(agentId: agent.Id);
337343
```
338-
339344
::: zone-end
340345

341346
::: zone pivot="javascript"

0 commit comments

Comments
 (0)