This project demonstrates the integration of the Microsoft.Extensions.AI
package with the AIPrompt
component. The integration enables AI-powered interactions leveraging the built-in IChatClient
service. The example shows how to use the various models supported by Microsoft.Extensions.AI
.
The Microsoft.Extensions.AI
package provides an abstraction for AI-powered services, making it easy to integrate large language models (LLMs) into .NET applications. It simplifies AI interaction by offering dependency injection support and a structured way to handle AI-based workflows.
- The
AIPrompt
component is configured to useMicrosoft.Extensions.AI
for AI-driven prompts. - The project registers several
IChatClient
services in theProgram.cs
file - one for each model supported byMicrosoft.Extensions.AI
. - The
OnPromptRequest
event of theAIPrompt
is not handled, so the component will automatically use the registeredIChatClient
service to generate a response.
To run the project successfully, you need to provide your endpoint and credentials for the model you want to use.
- Open the
Program.cs
file. - Locate the
IChatClient
service registration that uses your preferred model. - Uncomment the service registration.
- Replace the placeholder values with your actual endpoint and credentials.
- Run the application and interact with the
AIPrompt
component.
Azure AI Inference Client registration
Program.cs
var innerClient = new Azure.AI.Inference.ChatCompletionsClient(
new Uri(endpoint),
new AzureKeyCredential(apikey)
).AsChatClient(model);
Azure OpenAI Client registration
Program.cs
var innerClient = new AzureOpenAIClient(
new Uri(endpoint),
new AzureKeyCredential(apikey)
).AsChatClient(model);
OpenAI Client registration
Program.cs
var innerClient = new OpenAIClient(apikey)
.AsChatClient(model);
GitHub Models Client registration
Program.cs
var innerClient = new OpenAIClient(
new ApiKeyCredential(apikey),
new OpenAIClientOptions()
{
Endpoint = new Uri(endpoint)
}
).AsChatClient(model);
Ollama Client registration
Program.cs
var innerClient = new OllamaChatClient(new Uri(endpoint), model);