Domain-Specific AI Vs Generic AI
Domain-Specific AI vs Generic AI
Practical demonstration using C# + ASP.NET Core + OpenAI
The objective is to make understand that the same LLM/API can behave very differently depending on the system instructions and the application design.
1. Learning Objectives
- What is an LLM-based AI application?
- What is a Generic AI Assistant?
- What is a Domain-Specific AI Assistant?
- What is the role of the system prompt?
- How the same OpenAI API can support different applications.
- Why a domain-specific prompt does not automatically provide company knowledge.
- How Domain-Specific AI leads naturally to RAG.
- How to implement both approaches using ASP.NET Core.
- How to test domain boundaries.
-
Why the existing
AIHRAssistantWebAPIcan behave as a generic technical AI assistant.
2. Big Picture
Start the class with this diagram:
LLM │ OpenAI API │ ┌────────────┴────────────┐ │ │ ▼ ▼ Generic AI Domain-Specific AI │ │ ▼ ▼ Technical Assistant HR Assistant │ │ C#, SQL, AI, etc. Leave, Payroll, HR
The important point is:
The LLM is the same. The application behavior is controlled largely by the instructions, data, tools and application logic surrounding the LLM.
3. What is an LLM?
What?
LLM stands for Large Language Model.
An LLM is an AI model trained on large amounts of text so that it can understand and generate natural language.
Examples include models from OpenAI and other providers.
Why?
Traditional applications generally follow predefined programming logic:
Input ↓ if/else ↓ Business Logic ↓ Output
An LLM allows applications to process natural-language requests:
User Question ↓ LLM ↓ Natural Language Answer
How?
Your application sends a request containing instructions and the user's question.
Conceptually:
{ "model": "model-name", "messages": [ { "role": "system", "content": "You are a technical assistant." }, { "role": "user", "content": "Explain Dependency Injection." } ] }
The LLM generates the answer.
4. What is Generic AI?
What?
A Generic AI Assistant is designed to answer questions across multiple areas rather than being restricted to one business domain.
For example:
C# SQL Server ASP.NET Core Angular REST APIs AI Machine Learning Git
Why?
A generic assistant is useful when users need help across different technical areas.
For example:
Explain Dependency Injection. Explain INNER JOIN. What is middleware? What is RAG? Explain polymorphism.
The same assistant can handle all these questions.
How?
The system prompt provides a broad set of supported capabilities.
Example:
You are a helpful and knowledgeable AI assistant. You can answer questions about: - C# - .NET - ASP.NET Core - OOP - REST APIs - SQL Server - Angular - Git - Artificial Intelligence - Generative AI - RAG Answer questions clearly and provide practical examples.
5. What is Domain-Specific AI?
What?
A Domain-Specific AI Assistant is designed to operate primarily within a particular business or professional domain.
Examples:
HR AI Assistant Banking AI Assistant Healthcare AI Assistant Legal AI Assistant Insurance AI Assistant Education AI Assistant
For your demonstration:
HR AI Assistant
Why?
A company may not want an AI assistant answering everything.
For example, an HR assistant should primarily deal with:
Leave Attendance Payroll Recruitment Onboarding Benefits HR policies
It should not necessarily answer:
Explain C# inheritance.
6. Important Concept
Make this distinction clear to trainees:
Domain-specific does not automatically mean domain-knowledgeable.
For example:
"You are an HR assistant."
does not automatically give the AI access to:
Company Leave Policy.pdf Employee Handbook.pdf Payroll Rules.pdf Company Database
This becomes extremely important when you teach RAG.
7. Demonstration Architecture
For the demonstration, use the same ASP.NET Core API architecture:
Angular / Swagger │ ▼ ASP.NET Core Controller │ ▼ AI Service Interface │ ▼ OpenAI Service │ ▼ OpenAI API │ ▼ LLM │ ▼ AI Response
Only the system instructions change between the two demonstrations.
8. Step 1 — Create ASP.NET Core Web API
Create:
ASP.NET Core Web API
Recommended:
.NET 8
Project name:
AIDomainDemoAPI
9. Step 2 — Install/Use Required Components
You need:
ASP.NET Core Web API HttpClient System.Text.Json Swagger OpenAI API access
For a simple teaching demonstration, direct HttpClient integration is perfectly reasonable because it helps trainees understand the underlying REST API communication.
10. Step 3 — Create Models
Create:
Models ├── ChatRequest.cs ├── Message.cs ├── ChatResponse.cs ├── Choice.cs └── AssistantMessage.cs
These are the five models you previously used.
11. ChatRequest.cs
using System.Text.Json.Serialization; namespace AIDomainDemoAPI.Models { public class ChatRequest { [JsonPropertyName("model")] public string Model { get; set; } = string.Empty; [JsonPropertyName("messages")] public List<Message> Messages { get; set; } = new(); } }
What?
Represents the request we send to the AI API.
Why?
We need to convert our C# object into the JSON expected by the API.
How?
For example:
{ "model": "gpt-5", "messages": [] }
12. Message.cs
using System.Text.Json.Serialization; namespace AIDomainDemoAPI.Models { public class Message { [JsonPropertyName("role")] public string Role { get; set; } = string.Empty; [JsonPropertyName("content")] public string Content { get; set; } = string.Empty; } }
This represents:
system message user message assistant message
For our application, the important messages are:
system user
13. ChatResponse.cs
using System.Text.Json.Serialization; namespace AIDomainDemoAPI.Models { public class ChatResponse { [JsonPropertyName("choices")] public List<Choice> Choices { get; set; } = new(); } }
This represents the response received from the AI API.
14. Choice.cs
using System.Text.Json.Serialization; namespace AIDomainDemoAPI.Models { public class Choice { [JsonPropertyName("message")] public AssistantMessage Message { get; set; } = new(); } }
The API response contains choices.
We extract:
choices ↓ message
15. AssistantMessage.cs
using System.Text.Json.Serialization; namespace AIDomainDemoAPI.Models { public class AssistantMessage { [JsonPropertyName("role")] public string Role { get; set; } = string.Empty; [JsonPropertyName("content")] public string Content { get; set; } = string.Empty; } }
This finally gives us the AI-generated text.
The response flow is:
ChatResponse ↓ Choices ↓ Choice ↓ Message ↓ Content
16. Step 4 — appsettings.json
For your classroom demonstration, you can keep the API key in configuration as you have been doing.
{ "OpenAI": { "ApiKey": "YOUR_API_KEY", "Endpoint": "https://api.openai.com/v1/chat/completions", "Model": "YOUR_MODEL" } }
Important
For actual production applications:
Do not commit API keys into Git.
Use:
User Secrets Environment Variables Azure Key Vault Managed Identity
For classroom demonstration, however, keeping the configuration simple helps trainees understand the API flow.
17. Step 5 — Create Interface
Create:
Services └── IAIChatService.cs
namespace AIDomainDemoAPI.Services { public interface IAIChatService { Task<string> GetResponseAsync(string question); } }
Why interface?
It separates:
What the service does
from:
How the service does it
It also makes the application easier to:
- test
- replace
- maintain
- extend
18. Step 6 — Generic AI Service
Create:
AIChatService.cs
using AIDomainDemoAPI.Models; using System.Net.Http.Headers; using System.Text; using System.Text.Json; namespace AIDomainDemoAPI.Services { public class AIChatService : IAIChatService { private readonly HttpClient _httpClient; private readonly IConfiguration _configuration; public AIChatService( HttpClient httpClient, IConfiguration configuration) { _httpClient = httpClient; _configuration = configuration; } public async Task<string> GetResponseAsync(string question) { try { // Read OpenAI configuration string apiKey = _configuration["OpenAI:ApiKey"]!; string endpoint = _configuration["OpenAI:Endpoint"]!; string model = _configuration["OpenAI:Model"]!; // Add Bearer token _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue( "Bearer", apiKey); // Create request ChatRequest request = new ChatRequest { Model = model, Messages = new List<Message> { new Message { Role = "system", Content = """ You are a helpful and knowledgeable AI technical assistant. Answer questions about: - C# - .NET - ASP.NET Core - OOP - REST APIs - SQL Server - Angular - Git - Artificial Intelligence - Generative AI - RAG Explain concepts clearly. Provide practical examples whenever appropriate. Explain What, Why and How. """ }, new Message { Role = "user", Content = question } } }; // Convert C# object to JSON string jsonRequest = JsonSerializer.Serialize(request); StringContent content = new StringContent( jsonRequest, Encoding.UTF8, "application/json"); // Call OpenAI HttpResponseMessage response = await _httpClient.PostAsync( endpoint, content); // Read response string jsonResponse = await response.Content.ReadAsStringAsync(); // Handle API error if (!response.IsSuccessStatusCode) { return $""" OpenAI API Error Status: {(int)response.StatusCode} Details: {jsonResponse} """; } // Convert JSON to C# object ChatResponse? result = JsonSerializer.Deserialize<ChatResponse>( jsonResponse); if (result == null || result.Choices.Count == 0) { return "No response received."; } // Return AI answer return result .Choices[0] .Message .Content; } catch (Exception ex) { return $"Error: {ex.Message}"; } } } }
19. Step 7 — Register the Service
In Program.cs:
builder.Services.AddHttpClient<IAIChatService, AIChatService>();
This means:
IAIChatService ↓ AIChatService
ASP.NET Core's DI container will create the service and inject HttpClient and IConfiguration.
20. Step 8 — Create Controller
using AIDomainDemoAPI.Services; using Microsoft.AspNetCore.Mvc; namespace AIDomainDemoAPI.Controllers { [ApiController] [Route("api/[controller]")] public class AIController : ControllerBase { private readonly IAIChatService _aiService; public AIController(IAIChatService aiService) { _aiService = aiService; } [HttpPost("ask")] public async Task<IActionResult> Ask( [FromBody] string question) { string answer = await _aiService.GetResponseAsync(question); return Ok(new { question, answer }); } } }
21. Test Generic AI
Run the application.
Open Swagger.
Send:
"Explain Dependency Injection in C#"
Expected:
{ "question": "Explain Dependency Injection in C#", "answer": "Dependency Injection is..." }
22. Generic AI Test Cases
Test Case 1
Explain Dependency Injection in C#.
Expected:
AI answers.
Test Case 2
Explain INNER JOIN with an example.
Expected:
AI answers SQL question.
Test Case 3
What is middleware in ASP.NET Core?
Expected:
AI answers.
Test Case 4
What is RAG?
Expected:
AI answers.
Test Case 5
Explain polymorphism with C# code.
Expected:
AI answers.
23. Now Change to Domain-Specific AI
This is the most important part of the demonstration.
Do not create another project.
Keep:
Controller Interface Service Models OpenAI API
exactly the same.
Change only the system content.
24. HR Domain System Prompt
Replace the generic system message with:
You are an AI HR Assistant for ABC Technologies. Your responsibility is to answer ONLY questions related to Human Resources. You can answer questions about: - Employee leave - Attendance - Payroll - Recruitment - Employee onboarding - Employee benefits - Working hours - Work-from-home policies - HR procedures Rules: 1. Stay within the HR domain. 2. Do not answer programming questions. 3. Do not answer SQL questions. 4. Do not answer technical questions. 5. Do not invent company policies. 6. If company-specific information has not been provided, clearly say that the information is not available. 7. Do not guess. 8. Answer professionally and clearly. 9. Keep answers concise. If a question is outside the HR domain, respond: "I am an HR Assistant and can answer only HR-related questions."
25. Test HR AI
Test 1
What is employee onboarding?
Expected:
HR-related answer.
Test 2
What is payroll?
Expected:
HR-related answer.
Test 3
What is employee attendance?
Expected:
HR-related answer.
Test 4
Explain Dependency Injection in C#.
Expected:
I am an HR Assistant and can answer only HR-related questions.
Test 5
Explain INNER JOIN in SQL.
Expected:
I am an HR Assistant and can answer only HR-related questions.
26. Test Domain Boundary
This is an important test.
Ask:
What is the company's annual leave policy?
If you have not supplied the actual policy, the AI should not invent one.
Expected behavior:
The company's annual leave policy has not been provided. Please refer to the official HR policy or contact HR.
Prompt instructions control behavior, but prompts are not a company database.
27. Generic vs Domain-Specific Comparison
Use this table during the class:
| Question | Generic AI | HR AI |
|---|---|---|
| What is payroll? | ✅ | ✅ |
| What is onboarding? | ✅ | ✅ |
| What is C#? | ✅ | ❌ |
| What is Dependency Injection? | ✅ | ❌ |
| What is INNER JOIN? | ✅ | ❌ |
| What is ASP.NET Core middleware? | ✅ | ❌ |
| What is RAG? | ✅ | ❌ |
| What is employee attendance? | ✅ | ✅ |
A Better Naming Structure
For a generic assistant:
AIChatService IAIChatService
For an HR-specific assistant:
HRChatService IHRChatService
But don't create unnecessary duplicate services just for the demonstration.
TIt understand that the same underlying OpenAI integration can support multiple application types.
Real-World Architecture
OpenAI / LLM │ ┌──────────┴──────────┐ │ │ ▼ ▼ Generic AI Domain AI │ │ │ HR / Banking / │ Healthcare etc. │ │ └──────────┬──────────┘ │ REST API │ ┌──────────┴──────────┐ │ │ Angular Mobile App
Later:
Domain AI + RAG + Tools + Database + Authentication
becomes a much more realistic enterprise AI application.
Final Learning Flow
LLM
│ ▼ OpenAI API │ ┌─────────┴─────────┐ │ │ ▼ ▼ Generic AI Domain AI │ │ │ │ C# / SQL / AI HR / Banking / etc. Healthcare │ ▼ Domain Knowledge │ ▼ RAG │ ▼ Enterprise AI
The key message
Generic AI answers across multiple supported topics. Domain-specific AI is intentionally restricted to a particular business area. A system prompt can establish the role and boundaries, but it does not by itself provide private business knowledge. When the AI needs to answer using company documents or other external knowledge, techniques such as RAG are introduced.
Comments
Post a Comment