Back to Blog
2 min read

Windows AI Features: Building for the AI PC

Windows AI features enable developers to build intelligent applications that run locally on AI PCs.

Windows AI Development

// Windows AI APIs for on-device inference

using Microsoft.Windows.AI;
using Microsoft.Windows.AI.MachineLearning;

public class WindowsAIService
{
    private readonly AIModelSession _session;

    public async Task InitializeAsync()
    {
        // Check for AI hardware capabilities
        var capabilities = await AIDeviceCapabilities.GetCapabilitiesAsync();

        if (capabilities.HasNPU)
        {
            Console.WriteLine($"NPU available: {capabilities.NPUName}");
            Console.WriteLine($"NPU TOPS: {capabilities.NPUPerformance}");
        }

        // Load model optimized for Windows AI
        var modelPath = "ms-appx:///Models/phi-3-mini.onnx";
        _session = await AIModelSession.CreateFromPathAsync(
            modelPath,
            new AIModelSessionOptions
            {
                DeviceType = AIDeviceType.NPU,
                EnableCaching = true
            }
        );
    }

    public async Task<string> GenerateResponseAsync(string prompt)
    {
        var input = new AIModelInput
        {
            Text = prompt,
            MaxTokens = 500,
            Temperature = 0.7f
        };

        var result = await _session.GenerateAsync(input);
        return result.Text;
    }

    public async Task<float[]> GetEmbeddingAsync(string text)
    {
        // Use Windows AI for local embeddings
        var embeddingModel = await AIEmbeddingModel.CreateAsync();
        return await embeddingModel.EmbedTextAsync(text);
    }
}

// XAML integration
public class AITextBox : TextBox
{
    public bool EnableAIAssist { get; set; } = true;

    protected override async void OnTextChanged(TextChangedEventArgs e)
    {
        base.OnTextChanged(e);

        if (EnableAIAssist && Text.EndsWith("?"))
        {
            var suggestion = await GetAISuggestion(Text);
            ShowSuggestionPopup(suggestion);
        }
    }
}

Key Windows AI Capabilities

FeatureDescriptionUse Case
NPU InferenceHardware-accelerated AILocal LLM, embeddings
Windows Copilot RuntimeSystem-level AI servicesApp integration
RecallAI-powered memorySemantic search
Live CaptionsReal-time transcriptionAccessibility

Windows AI brings powerful on-device intelligence to every application.

Michael John Peña

Michael John Peña

Senior Data Engineer based in Sydney. Writing about data, cloud, and technology.