4 Essential LLM Tasks in .NET 10 Using GitHub Models 🚀
Ever wondered how to integrate AI into your .NET applications? In this post, I'll show you 4 fundamental LLM tasks that you can implement in .NET 10 using GitHub Models - and the best part? It's surprisingly simple!
🎯 What We'll Build
- 💬 Chat Completion - Interactive AI conversations
- 🏷️ Text Classification - Automatic categorization of user feedback
- 📝 Text Summarization - Condensing long articles into bullet points
- 😊 Sentiment Analysis - Understanding customer emotions from reviews
💡 All code is available on GitHub: genai-dotnet-basic_llm_tasks
🔧 Prerequisites
Before we dive in, make sure you have:
- ✅ .NET 10 SDK installed
- ✅ Visual Studio 2022 or VS Code
- ✅ GitHub Personal Access Token with access to GitHub Models
Getting Started with GitHub Models
GitHub Models provides free access to powerful AI models! Here's how to get started:
-
Get a GitHub PAT (Personal Access Token)
- Go to GitHub Settings → Developer Settings → Tokens
- Generate a token with
repoaccess - Save it securely!
Configure User Secrets (Keep your token safe!)
cd YourProject
dotnet user-secrets set "GitHubModels:Token" "your-github-token-here"
📚 Learn more: Check out the official GitHub Models documentation for detailed setup instructions.
1️⃣ Chat Completion - Your AI Assistant 💬
Let's start with the basics: having a conversation with AI. This project demonstrates both non-streaming (get complete response) and streaming (real-time, token-by-token) responses.
Architecture at a Glance
Configuration → Authentication → AI Client → Chat Response
The Code
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Configuration;
using OpenAI;
using System.ClientModel;
// Load configuration
IConfigurationRoot configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false)
.AddUserSecrets<Program>()
.Build();
// Authenticate with GitHub Models
ApiKeyCredential credential = new ApiKeyCredential(
configuration["GitHubModels:Token"]
?? throw new InvalidOperationException("Token not found!"));
// Initialize AI client
IChatClient chatClient = new OpenAIClient(credential, new OpenAIClientOptions
{
Endpoint = new Uri("https://models.inference.ai.azure.com")
})
.GetChatClient("gpt-4o-mini")
.AsIChatClient();
// Get streaming response
var responseStream = chatClient.GetStreamingResponseAsync(
"Explain quantum computing in simple terms",
new ChatOptions { Temperature = 0.7f, MaxOutputTokens = 300 }
);
Console.Write("AI: ");
await foreach (var message in responseStream)
{
Console.Write(message.Text);
}
🎨 What Makes It Cool?
- Real-time streaming for better UX
- Token usage tracking for cost management
- Configurable temperature (0.0 = focused, 1.0 = creative)
Use cases: Chatbots, Q&A systems, code assistants
2️⃣ Text Classification - Smart Categorization 🏷️
Automatically categorize user feedback into Complaint, Suggestion, Praise, or Other. Perfect for customer support automation!
The Magic Prompt
var classificationPrompt = @"Classify the text into one category:
Complaint, Suggestion, Praise, or Other.
Respond with only the category name.
Text: '{0}'";
var userFeedback = "The app keeps crashing when I upload photos!";
var response = await chatClient.GetResponseAsync(
string.Format(classificationPrompt, userFeedback),
new ChatOptions
{
Temperature = 0.1f, // Low temp for consistency
MaxOutputTokens = 50
}
);
Console.WriteLine($"Classification: {response.Text}");
// Output: Complaint
💡 Pro Tips
- Use low temperature (0.1) for consistent classifications
- Keep
MaxOutputTokensminimal since you only need one word - Perfect for routing support tickets!
Real-world impact: Route 1000s of customer messages automatically 📮
3️⃣ Text Summarization - TL;DR Generator 📝
Turn lengthy articles into concise bullet points. Save reading time and improve information accessibility!
Quick Example
var summaryPrompt = @"Summarize the following text as bullet points.
Provide 2-5 key points.
Text: '{0}'";
var longText = @"The quarterly earnings report shows our company
exceeded expectations with a 15% revenue increase. Growth was driven
by Asia-Pacific sales and new product launches. Profit margin
improved from 12% to 14%, and the board approved a 5% dividend increase.";
var summary = await chatClient.GetResponseAsync(
string.Format(summaryPrompt, longText),
new ChatOptions { Temperature = 0.1f, MaxOutputTokens = 150 }
);
Console.WriteLine($"Summary:\n{summary.Text}");
Output
• Company revenue increased 15% year-over-year, beating expectations
• Growth driven by Asia-Pacific sales and new product launches
• Profit margin improved from 12% to 14%
• Board approved 5% dividend increase for shareholders
Use cases: News aggregation, document processing, meeting notes
4️⃣ Sentiment Analysis - Understand Customer Emotions 😊
Go beyond simple positive/negative! This returns structured JSON with sentiment breakdown, positive/negative aspects, and emotional tone.
The Smart Prompt
var sentimentPrompt = @"Analyze the sentiment of this product review.
Return as JSON with this structure:
{
""overallSentiment"": ""Positive/Negative/Neutral/Mixed"",
""positiveAspects"": [""list of good things""],
""negativeAspects"": [""list of bad things""],
""emotionalTone"": ""description of tone""
}
Review: '{0}'";
var review = @"This laptop is amazing! Battery lasts all day,
screen is crystal clear. Best purchase this year!";
var analysis = await chatClient.GetResponseAsync(
string.Format(sentimentPrompt, review),
new ChatOptions { Temperature = 0.1f, MaxOutputTokens = 200 }
);
Console.WriteLine($"Analysis:\n{analysis.Text}");
Sample Output
{
"overallSentiment": "Positive",
"positiveAspects": [
"Excellent battery life lasting all day",
"Crystal clear screen quality",
"Overall satisfaction with purchase"
],
"negativeAspects": [],
"emotionalTone": "Enthusiastic and highly satisfied"
}
🎯 Why JSON?
- Easy to parse programmatically
- Structured data for dashboards
- Multi-dimensional insights in one request
Business value: Build customer sentiment dashboards, track product issues, identify improvement areas 📊
🚀 Getting Started
Ready to try it yourself?
# Clone the repo
git clone https://github.com/Rahul1994jh/genai-dotnet-basic_llm_tasks
cd genai-dotnet-basic_llm_tasks
# Setup your GitHub token
dotnet user-secrets set "GitHubModels:Token" "your-token-here"
# Run any project
dotnet run --project TextCompletion
dotnet run --project Classification
dotnet run --project Summarization
dotnet run --project SentimentAnalysis
Each project has a detailed README with:
- Architecture diagrams
- Customization guides
- Troubleshooting tips
- Best practices
🎓 Key Takeaways
| Task | Best For | Temperature | Model |
|---|---|---|---|
| Chat Completion | Conversations, Q&A | 0.7 | gpt-4o-mini |
| Classification | Categorization | 0.1 | gpt-4o-mini |
| Summarization | Content condensing | 0.1 | gpt-4o-mini |
| Sentiment Analysis | Emotion detection | 0.1 | gpt-4o-mini |
💰 Cost Optimization Tips
- Use
gpt-4o-minifor general tasks (10x cheaper!) - Set
MaxOutputTokensappropriately - Use low temperature for predictable tasks
- Monitor token usage in production
🔐 Security Best Practices
✅ DO:
- Store tokens in User Secrets (development)
- Use Azure Key Vault (production)
- Use
.gitignorefor secrets - Rotate tokens regularly
❌ DON'T:
- Hardcode API keys in code
- Commit secrets to Git
- Share tokens publicly
🎯 What's Next?
Now that you've mastered the basics, here are some ideas to level up:
- Combine tasks: Classify → Analyze Sentiment → Summarize
- Add conversation history for multi-turn chats
- Build a web API with ASP.NET Core
- Create a Blazor UI for interactive demos
- Add function calling for tool integration
📚 Resources
- 📦 GitHub Repo: genai-dotnet-basic_llm_tasks
- 🤖 GitHub Models: Official Documentation
- 🔧 Microsoft.Extensions.AI: NuGet Package
- 📖 .NET 10: What's New
💬 Let's Connect!
Found this helpful? Have questions or ideas?
- ⭐ Star the repo on GitHub
- 💬 Drop a comment below
- 🐦 Share with your network
Happy coding! 🎉
Built with ❤️ using .NET 10, Microsoft.Extensions.AI, and GitHub Models
Top comments (0)