Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,49 +1,26 @@
//<chat_completion>
using Azure;
using Azure.Identity;
using Azure.AI.Projects;
using Azure.AI.Inference;
using Azure.Core;
using Azure.Core.Pipeline;

var projectEndpoint = Evironment.GetEnvironmentVariable("AZURE_AI_ENDPOINT");
var modelDeploymentName = Evironment.GetEnvironmentVariable("AZURE_AI_MODEL");
var credential = new DefaultAzureCredential();

namespace AiAgentsTests
{
//<chat_completion>
public class SimpleInference
{
public static void Main(string[] args)
{

var endpointUrl = Evironment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
var modelName = Evironment.GetEnvironmentVariable("AZURE_OPENAI_MODEL_NAME");

var endpoint = new Uri(endpointUrl);
var credential = new DefaultAzureCredential();
var model = modelName;

AzureAIInferenceClientOptions clientOptions = new AzureAIInferenceClientOptions();
BearerTokenAuthenticationPolicy tokenPolicy = new BearerTokenAuthenticationPolicy(credential, new string[] { "https://cognitiveservices.azure.com/.default" });
clientOptions.AddPolicy(tokenPolicy, HttpPipelinePosition.PerRetry);
AIProjectClient client = new AIProjectClient(projectEndpoint, credential);

ChatCompletionsClient chatClient = client.GetChatCompletionsClient();

var client = new ChatCompletionsClient(
endpoint,
credential,
clientOptions
);

var requestOptions = new ChatCompletionsOptions()
{
Messages =
{
new ChatRequestSystemMessage("You are a helpful assistant."),
new ChatRequestUserMessage("How many feet are in a mile?"),
},
};

Response<ChatCompletions> response = client.Complete(requestOptions);
Console.WriteLine(response.Value.Content);

}
}
// </chat_completion>
}
var requestOptions = new ChatCompletionsOptions()
{
Messages =
{
new ChatRequestSystemMessage("You are a helpful assistant."),
new ChatRequestUserMessage("How many feet are in a mile?"),
},
Model = modelDeploymentName
};
Response<ChatCompletions> response = chatClient.Complete(requestOptions);
Console.WriteLine(response.Value.Content);
// </chat_completion>
Loading