Skip to content

Commit 86acb71

Browse files
authored
Updating Inference and instructions for Agent in the .NET Quickstart (#317)
1 parent c6ff3bd commit 86acb71

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

samples/microsoft/csharp/mslearn-resources/quickstart/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,10 @@ This sample demonstrates how to use the AI Foundry platform with C#/.NET. It pro
1515
1. Clone this repository
1616
2. Set up your Azure Ai Foundry account and secrets at the .env file
1717

18+
## NOTE
19+
20+
- The sample in SimpleInference.cs uses a diferent endpoint. In this case, you will need to set the environment variable `AZURE_AI_ENDPOINT` to the root of the AI Foundry endpoint, e.g. `https://{your-resource-name}.services.ai.azure.com/`. While the other samples use `AZURE_AI_ENDPOINT` which should be set to the full endpoint, e.g. `https://{your-resource-name}.services.ai.azure.com/api/projects/{project-id}`.
21+
22+
- The agent samples require the `AZURE_AI_MODEL` environment variable to be set to an OpenAI-compatible model, e.g. `gpt-4.1`, as not all models are supported for agent use cases, including tooling.
1823

1924
## Running the Sample
Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
//<chat_completion>
2-
using Azure;
2+
using System.ClientModel.Primitives;
33
using Azure.Identity;
4-
using Azure.AI.Projects;
5-
using Azure.AI.Inference;
4+
using OpenAI;
5+
using OpenAI.Chat;
66

7-
var projectEndpoint = new Uri(System.Environment.GetEnvironmentVariable("AZURE_AI_ENDPOINT"));
8-
var modelDeploymentName = System.Environment.GetEnvironmentVariable("AZURE_AI_MODEL");
9-
var credential = new DefaultAzureCredential();
7+
#pragma warning disable OPENAI001
108

11-
AIProjectClient client = new AIProjectClient(projectEndpoint, credential);
9+
string projectEndpoint = System.Environment.GetEnvironmentVariable("AZURE_AI_ENDPOINT")!;
10+
string modelDeploymentName = System.Environment.GetEnvironmentVariable("AZURE_AI_MODEL")!;
1211

13-
ChatCompletionsClient chatClient = client.GetChatCompletionsClient();
12+
BearerTokenPolicy tokenPolicy = new(
13+
new DefaultAzureCredential(),
14+
"https://ai.azure.com/.default");
15+
OpenAIClient openAIClient = new(
16+
authenticationPolicy: tokenPolicy,
17+
options: new OpenAIClientOptions()
18+
{
19+
Endpoint = new($"{projectEndpoint}/openai/v1"),
20+
});
21+
ChatClient chatClient = openAIClient.GetChatClient(modelDeploymentName);
1422

15-
var requestOptions = new ChatCompletionsOptions()
16-
{
17-
Messages =
18-
{
19-
new ChatRequestSystemMessage("You are a helpful assistant."),
20-
new ChatRequestUserMessage("How many feet are in a mile?"),
21-
},
22-
Model = modelDeploymentName
23-
};
24-
Response<ChatCompletions> response = chatClient.Complete(requestOptions);
25-
Console.WriteLine(response.Value.Content);
23+
ChatCompletion completion = await chatClient.CompleteChatAsync(
24+
[
25+
new SystemChatMessage("You are a helpful assistant."),
26+
new UserChatMessage("How many feet are in a mile?")
27+
]);
28+
29+
Console.WriteLine(completion.Content[0].Text);
2630
// </chat_completion>

0 commit comments

Comments
 (0)