If you want to automatically fetch meta description, title, keywords, and category from a given piece of content using AI in
.NET, you basically need a pipeline that:
Takes your article/blog/content as input.
Sends it to an AI model (e.g., OpenAI GPT, Azure OpenAI, Hugging Face, etc.)
Parses the model's structured output into your .NET objects.
1. Example Prompt for AI Extraction
You can design a prompt like:
Extract the following fields from the given content:
- Title: A concise headline
- Meta description: Summary under 160 characters
- Keywords: 5–10 relevant SEO keywords
- Category: Broad topic classification
Return JSON only in this format:
{
"title": "...",
"metaDescription": "...",
"keywords": ["...", "..."],
"category": "..."
}
Content:
[YOUR CONTENT HERE]
2. .NET C# Example with OpenAI
Here’s a working example using Azure OpenAI (but you can adapt for OpenAI API directly):
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
class Program
{
static async Task Main()
{
string content = @"Your blog/article text here...";
string prompt = $@"
Extract the following fields from the given content:
- Title: A concise headline
- Meta description: Summary under 160 characters
- Keywords: 5–10 relevant SEO keywords
- Category: Broad topic classification
Return JSON only in this format:
{{
""title"": """",
""metaDescription"": """",
""keywords"": [""...""],
""category"": """"
}}
Content:
{content}
";
string endpoint = "https://YOUR_AZURE_OPENAI_ENDPOINT/openai/deployments/YOUR_MODEL/chat/completions?api-version=2024-05-01-preview";
string apiKey = "YOUR_API_KEY";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
var requestBody = new
{
messages = new[]
{
new { role = "system", content = "You are an assistant that extracts SEO metadata from content." },
new { role = "user", content = prompt }
},
matokens = 300,
temperature = 0.3
};
var json = Newtonsoft.Json.JsonConvert.SerializeObject(requestBody);
var response = await client.PostAsync(endpoint, new StringContent(json, Encoding.UTF8, "application/json"));
string result = await response.Content.ReadAsStringAsync();
var parsed = JObject.Parse(result);
string jsonResponse = parsed["choices"]?[0]?["message"]?["content"]?.ToString();
Console.WriteLine("Extracted Metadata:\n" + jsonResponse);
}
}
}
3. Why Use AI Instead of Regex?
AI understands context — it can create SEO-friendly titles and summaries, not just extract first
<p> tags.
It can classify category (e.g., “Technology”, “Travel”, “Health”) even if the article never explicitly says it.
AI can choose optimal keywords for SEO rather than just picking frequent words.
4. If You Want to Avoid Paid APIs
Use Local LLMs with Ollama or
LM Studio and call them from
.NET.
Use Hugging Face models like facebook/bart-large-cnn for summaries or
keyBERT for keyword extraction (via Python interop or ONNX in C#).
5. Possible Architecture
Content (HTML/Text)
↓
[Pre-processing] (strip HTML, clean text)
↓
[AI Call] (Prompt for title, meta, keywords, category)
↓
[Parse JSON Output]
↓
Save to DB / Show in UI
If you want, I can give you a ready-to-use .NET method that:
Takes raw HTML or text
Cleans it
Sends it to AI
Returns strongly-typed SEOData model with Title,
MetaDescription, Keywords, Category.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
If you want to automatically fetch meta description, title, keywords, and category from a given piece of content using AI in .NET, you basically need a pipeline that:
.NETobjects.1. Example Prompt for AI Extraction
You can design a prompt like:
2. .NET C# Example with OpenAI
Here’s a working example using Azure OpenAI (but you can adapt for OpenAI API directly):
3. Why Use AI Instead of Regex?
<p>tags.4. If You Want to Avoid Paid APIs
.NET.facebook/bart-large-cnnfor summaries orkeyBERTfor keyword extraction (via Python interop or ONNX in C#).5. Possible Architecture
If you want, I can give you a ready-to-use .NET method that:
SEODatamodel withTitle,MetaDescription,Keywords,Category.