ChatAsistant 1.0.3
dotnet add package ChatAsistant --version 1.0.3
NuGet\Install-Package ChatAsistant -Version 1.0.3
<PackageReference Include="ChatAsistant" Version="1.0.3" />
<PackageVersion Include="ChatAsistant" Version="1.0.3" />
<PackageReference Include="ChatAsistant" />
paket add ChatAsistant --version 1.0.3
#r "nuget: ChatAsistant, 1.0.3"
#:package ChatAsistant@1.0.3
#addin nuget:?package=ChatAsistant&version=1.0.3
#tool nuget:?package=ChatAsistant&version=1.0.3
ChatAsistant
ChatAsistant is a .NET 8 library that lets you drop a modern chat assistant widget into your ASP.NET Core app, backed by a simple RAG flow on top of PostgreSQL + pgvector + Ollama.
Features
- Embeddable chat widget with a floating button and modern UI
- RAG-based routing: stores your app/page metadata (path, title, description) and finds the most relevant route by vector similarity
- Ollama integration for both embeddings and chat
- Configurable system prompt: from appsettings, file, or a custom provider
- Returns an optional redirect URL so the widget can show a “Go to page” chip
Requirements
- .NET 8 (
net8.0) - PostgreSQL with the
vectorextension (pgvector) - Ollama running (default:
http://localhost:11434)
Screenshots
You can see how the widget looks in action:
- Light theme:
docs/widget-light.png - Dark theme:
docs/widget-dark.png
The assistant appears as a floating button in the bottom-right corner and opens a compact chat window when clicked.
Install
dotnet add package ChatAsistant
Package Manager:
Install-Package ChatAsistant
csproj:
<PackageReference Include="ChatAsistant" Version="1.0.3" />
Quick start
1. Configure via appsettings.json
{
"ChatAsistant": {
"ConnectionString": "Host=...;Database=...;Username=...;Password=...",
"OllamaBaseUrl": "http://localhost:11434"
}
}
2. Register in Program.cs
using ChatAsistant;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddChatAsistant(builder.Configuration);
var app = builder.Build();
app.MapChatAsistant();
app.Run();
This will:
- Register EF Core
ChatAsistantDbContextusing Npgsql + pgvector - Register
RagService,IEmbeddingService,IChatService(Ollama-based) - Expose:
- Static files under
/{prefix}/*(default prefix:_chatasistant) - API under
/{prefix}/api/*
- Static files under
Embed the widget
In your layout/page:
<script src="/_chatasistant/js/chatbot-embed.js"></script>
Optional attributes:
<script
src="/_chatasistant/js/chatbot-embed.js"
data-api-url="https://your-domain.com"
data-prefix="_chatasistant"
data-api-key="YOUR_API_KEY">
</script>
The widget talks to /{prefix}/api/chat and shows a floating assistant button.
System prompt configuration
You can drive the system prompt per project in three ways (priority order):
1. Custom provider (dynamic, tenant-based, DB, etc.)
using ChatAsistant.Services;
public class MySystemPromptProvider : ISystemPromptProvider
{
public Task<string> GetPromptAsync(CancellationToken ct = default)
=> Task.FromResult("Project-specific system prompt...");
}
builder.Services.AddSingleton<ISystemPromptProvider, MySystemPromptProvider>();
builder.Services.AddChatAsistant(builder.Configuration);
2. From file (prompt in a .txt file)
appsettings.json:
{
"ChatAsistant": {
"SystemPromptFilePath": "Prompts/system-prompt.txt"
}
}
3. Inline in config/options
appsettings.json:
{
"ChatAsistant": {
"SystemPrompt": "You are the assistant for this application..."
}
}
Or via code:
builder.Services.AddChatAsistant(o =>
{
o.ConnectionString = "...";
o.SystemPrompt = "You are the assistant for this application...";
});
If none of these are provided, a generic, app-agnostic default system prompt is used.
API endpoints
Base path: /{prefix}/api (default prefix: _chatasistant)
POST /chat
Body:
{ "message": "..." }Response:
{ "message": "assistant reply...", "redirectUrl": "/some/route-or-null" }
Note: For backward compatibility, the JSON may also include Turkish keys (
mesaj,yonlendirilecekUrl) in some versions. New integrations should prefermessageandredirectUrl.
POST /search
Body:
{ "query": "..." }Returns a list of matching routes (path, title, description).
POST /routes
Body:
{ "path": "/x", "title": "X", "description": "..." }Adds a single route and embeds it.
POST /seed
Body:
[ { "path": "...", "title": "...", "description": "..." } ]Bulk insert + embed routes.
Configuration options
ChatAsistantOptions:
ConnectionString(required): PostgreSQL connection stringOllamaBaseUrl: Ollama base URL (default:http://localhost:11434)EmbeddingModel: embedding model name (default:mxbai-embed-large)ChatModel: chat model name (default:llama3.1)EmbeddingDimension: pgvector dimension (default:1024)MaxEmbeddingInputLength: trims long inputs before embedding (default:500)RoutePrefix: URL prefix for static files + API (default:_chatasistant)SystemPrompt: system prompt text (if not using file/provider)SystemPromptFilePath: optional path to a prompt fileApiKey: optional API key that the widget sends asX-API-Key
Security & hosting
- The assistant endpoints are regular ASP.NET Core endpoints hosted in your app. You are responsible for exposing them only where appropriate (e.g. behind your existing auth).
- If you set
ApiKeyinChatAsistantOptions, the widget will send it asX-API-Key. You can validate this header in middleware or endpoint filters to restrict access to the assistant. - Do not expose the assistant API publicly without proper authentication/authorization if it can access sensitive internal routes or data.
Database & migrations
- Database: EF Core entity
PageRoutestoresPath,Title,Descriptionand a pgvectorEmbeddingcolumn; make sure thevectorextension is enabled in your database. - Migrations: The package does not run migrations automatically. You are responsible for creating/applying EF Core migrations for
ChatAsistantDbContext.
Example:
dotnet ef migrations add InitChatAsistant -c ChatAsistantDbContext
dotnet ef database update -c ChatAsistantDbContext
Performance notes
- Route search uses pgvector cosine distance ordering. For small datasets this is fine out of the box.
- For tens of thousands of routes and above, you should:
- Add a pgvector index (e.g. IVFFLAT or HNSW)
- Tune index parameters such as
listsandprobesaccording to your workload
- End-to-end latency for
/chatis roughly:- vector search time in PostgreSQL (index + data size dependent)
- plus Ollama model inference time over HTTP (model and hardware dependent)
Static assets
- The widget expects an avatar at
/{prefix}/images/bot-avatar.png. You can serve your own from the host app or customize the script if needed.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. 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. |
-
net8.0
- Microsoft.EntityFrameworkCore (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.FileProviders.Embedded (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 8.0.0)
- Pgvector.EntityFrameworkCore (>= 0.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.