Skip to content

Commit 6066ea3

Browse files
committed
Updating Inference from SDK
1 parent 93e91ff commit 6066ea3

File tree

1 file changed

+19
-42
lines changed

1 file changed

+19
-42
lines changed
Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,26 @@
1+
//<chat_completion>
12
using Azure;
23
using Azure.Identity;
4+
using Azure.AI.Projects;
35
using Azure.AI.Inference;
4-
using Azure.Core;
5-
using Azure.Core.Pipeline;
66

7+
var projectEndpoint = Evironment.GetEnvironmentVariable("AZURE_AI_ENDPOINT");
8+
var modelDeploymentName = Evironment.GetEnvironmentVariable("AZURE_AI_MODEL");
9+
var credential = new DefaultAzureCredential();
710

8-
namespace AiAgentsTests
9-
{
10-
//<chat_completion>
11-
public class SimpleInference
12-
{
13-
public static void Main(string[] args)
14-
{
15-
16-
var endpointUrl = Evironment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
17-
var modelName = Evironment.GetEnvironmentVariable("AZURE_OPENAI_MODEL_NAME");
18-
19-
var endpoint = new Uri(endpointUrl);
20-
var credential = new DefaultAzureCredential();
21-
var model = modelName;
22-
23-
AzureAIInferenceClientOptions clientOptions = new AzureAIInferenceClientOptions();
24-
BearerTokenAuthenticationPolicy tokenPolicy = new BearerTokenAuthenticationPolicy(credential, new string[] { "https://cognitiveservices.azure.com/.default" });
25-
clientOptions.AddPolicy(tokenPolicy, HttpPipelinePosition.PerRetry);
11+
AIProjectClient client = new AIProjectClient(projectEndpoint, credential);
2612

13+
ChatCompletionsClient chatClient = client.GetChatCompletionsClient();
2714

28-
var client = new ChatCompletionsClient(
29-
endpoint,
30-
credential,
31-
clientOptions
32-
);
33-
34-
var requestOptions = new ChatCompletionsOptions()
35-
{
36-
Messages =
37-
{
38-
new ChatRequestSystemMessage("You are a helpful assistant."),
39-
new ChatRequestUserMessage("How many feet are in a mile?"),
40-
},
41-
};
42-
43-
Response<ChatCompletions> response = client.Complete(requestOptions);
44-
Console.WriteLine(response.Value.Content);
45-
46-
}
47-
}
48-
// </chat_completion>
49-
}
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);
26+
// </chat_completion>

0 commit comments

Comments
 (0)