Introduction
AI (Artificial Intelligence) and ML (Machine Learning) are changing the way web applications interact with users. From recommendations, chatbots, and predictions to image recognition, AI/ML features make applications smarter and more engaging.
In this tutorial, we will explore how to integrate AI/ML into a full-stack app using ASP.NET Core as the backend and Angular as the frontend. We will also discuss options like Azure Cognitive Services , OpenAI API , and custom ML models .
Why Add AI/ML to Your Apps?
Personalization: Recommend products or content.
Automation: Predict outcomes and automate decisions.
User Engagement: Chatbots and smart assistants.
Competitive Advantage: Smarter applications stand out in the market.
Architecture Diagram
+----------------+ HTTP/API +---------------------+
| Angular App | <-------------------------> | ASP.NET Core Backend |
| (Frontend) | | (API & ML Logic) |
+----------------+ +---------------------+
^ |
| |
+------------------ AI/ML Services (Azure Cognitive, Custom ML, OpenAI) --------+
Explanation
Angular sends input data (text, image, user behavior) to the backend.
ASP.NET Core processes the request and calls AI/ML services or models.
AI/ML service returns predictions, recommendations, or results.
Angular displays results to the user in real-time.
Step 1. Using AI/ML API (Example: Text Sentiment Analysis)
Backend: ASP.NET Core Web API
Install NuGet package for calling external APIs:
dotnet add package RestSharp
Create a controller (
AiController.cs):
using Microsoft.AspNetCore.Mvc;
using RestSharp;
using System.Threading.Tasks;
[ApiController]
[Route("api/[controller]")]
public class AiController : ControllerBase
{
private readonly string apiKey = "<YOUR_OPENAI_API_KEY>";
[HttpPost("sentiment")]
public async Task<IActionResult> AnalyzeSentiment([FromBody] string text)
{
var client = new RestClient("https://api.openai.com/v1/completions");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", $"Bearer {apiKey}");
request.AddJsonBody(new
{
model = "text-rg-003",
prompt = $"Analyze the sentiment of this text: {text}",
max_tokens = 60
});
var response = await client.ExecuteAsync(request);
return Ok(response.Content);
}
}

Join the conversation! Your thoughts help the community grow.