CoreTemplate.AI
1.3.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package CoreTemplate.AI --version 1.3.0
NuGet\Install-Package CoreTemplate.AI -Version 1.3.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CoreTemplate.AI" Version="1.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CoreTemplate.AI" Version="1.3.0" />
<PackageReference Include="CoreTemplate.AI" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CoreTemplate.AI --version 1.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CoreTemplate.AI, 1.3.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CoreTemplate.AI@1.3.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CoreTemplate.AI&version=1.3.0
#tool nuget:?package=CoreTemplate.AI&version=1.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Core.AI
Modular and extensible AI integration layer for .NET applications. Supports multiple AI providers like OpenRouter and Ollama via pluggable architecture and Semantic Kernel.
Version 1.3.0: Added Semantic Kernel Agent service and full provider configurability.
Features
- Plug-and-play architecture
- Provider support: OpenRouter, Ollama
- Semantic Kernel-based agent support
- Dynamic model selection and validation
- Streaming & prompt support
- Memory support (user-based history)
- Easily extendable with your own providers
Installation
dotnet add package Core.AI --version 1.3.0
Configuration
Add the following to your appsettings.json:
"AiSettings": {
"Provider": "OpenRouter",
"Model": "mistralai/mistral-7b-instruct"
},
"OpenRouterAI": {
"ApiKey": "sk-xxx"
},
"AgentProfiles": [
{
"Name": "Default",
"Context": "You are a helpful assistant.",
"Temperature": 0.7,
"Model": "gpt-3.5-turbo"
},
{
"Name": "CodeHelper",
"Context": "You are an expert .NET developer. Answer code questions precisely.",
"Temperature": 0.5,
"Model": "gpt-4"
},
{
"Name": "TravelGuide",
"Context": "You are a friendly travel guide helping users plan trips.",
"Temperature": 0.9,
"Model": "gpt-3.5-turbo"
}
],
// --- AI Services ---
builder.Services.AddOptions<AISettings>()
.Bind(builder.Configuration.GetSection("AiSettings"))
.Validate(settings => Enum.IsDefined(typeof(AIProvider), settings.Provider),
"Invalid AI provider configured in AiSettings.Provider");
builder.Services.AddSingleton(sp =>
sp.GetRequiredService<IOptions<AISettings>>().Value);
// Providers
builder.Services.AddScoped<OpenRouterAiService>();
builder.Services.AddScoped<OllamaAiService>();
builder.Services.AddScoped<IAIService, AIServiceResolver>();
// Model Providers
builder.Services.AddScoped<OpenRouterModelProvider>();
builder.Services.AddScoped<OllamaModelProvider>();
builder.Services.AddScoped<AIModelProviderResolver>();
// Agent Service
builder.Services.AddScoped<IAgentService, SemanticKernelAgentService>();
builder.Services.AddSingleton<ChatHistoryStore>();
builder.Services.AddSingleton<AgentProfileProvider>();
Memory Support
User messages are stored in-memory with ChatHistoryStore, enabling contextful chat.
Usage Example
using Azure;
using Core.AI.Abstractions;
using Core.AI.Models;
using Microsoft.AspNetCore.Mvc;
using System.Text;
namespace CoreApp.WebAPI.Controllers
{
[Route("api/agent")]
[ApiController]
public class AgentController : ControllerBase
{
private readonly IAgentService _agentService;
public AgentController(IAgentService agentService)
{
_agentService = agentService;
}
// POST /api/agent/prompt
[HttpPost("prompt")]
public async Task<IActionResult> Prompt([FromBody] AgentPromptRequest request)
{
var result = await _agentService.ChatAsync(request.Prompt, request.Options, request.UserId);
return Ok(new { result });
}
// POST /api/agent/stream
[HttpPost("stream")]
public async Task StreamPrompt([FromBody] AgentPromptRequest request)
{
Response.ContentType = "text/plain";
await foreach (var chunk in _agentService.StreamChatAsync(request.Prompt, request.Options, request.UserId))
{
var buffer = Encoding.UTF8.GetBytes(chunk);
await Response.Body.WriteAsync(buffer);
await Response.Body.FlushAsync();
}
}
}
}
POST /api/agent/prompt Content-Type: application/json
{
"prompt": "What's an interesting fact about the universe?",
"options": {
"context": "You are a helpful astrophysicist AI.",
"temperature": 0.7,
"model": "mistralai/mistral-7b-instruct",
"provider": "OpenRouter",
"profile": "Default"
},
"userId": "user-abc-123"
}
Field Descriptions
| Field | Description |
|---|---|
prompt |
The main question or instruction sent to the AI. |
context |
System-level instruction defining how the AI should behave (e.g. helpful assistant, coding expert, etc.). |
temperature |
Controls creativity: 0 = focused & factual, 1.0 = more creative/random. |
model |
The specific model to use (e.g. gpt-4, mistralai/mistral-7b-instruct). |
provider |
The AI provider, such as OpenRouter or Ollama. |
profile |
A predefined profile from appsettings.json that sets defaults for context, model, and temperature. |
userId |
A unique user identifier used to maintain memory/history between messages. |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- FluentValidation (>= 12.0.0)
- MediatR (>= 9.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.7)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.7)
- Microsoft.Extensions.Options (>= 9.0.7)
- Microsoft.SemanticKernel (>= 1.60.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.