| title | Creating a Phi Silica addon for Electron |
|---|---|
| description | Learn how to create a C# native addon that uses the Phi Silica AI model to summarize text on-device in your Electron app. |
| ms.date | 02/20/2026 |
| ms.topic | how-to |
This guide shows you how to create a C# native addon that uses the Phi Silica AI model to summarize text on-device in your Electron app. Phi Silica is a small language model that runs locally on Windows 11 devices with NPUs.
- Completed the development environment setup
- Copilot+ PC (Windows 11 with NPU support)
Note
Phi Silica requires a Copilot+ PC with NPU support. The API will return an error on devices without NPU support.
npx winapp node create-addon --template cs --name csAddonThis creates a csAddon/ folder with:
addon.cs- Your C# code that will call Windows APIscsAddon.csproj- Project file with references to Windows SDK and Windows App SDKREADME.md- Documentation
The command also adds a build-addon script to your package.json.
Build the addon:
npm run build-addonOpen csAddon/addon.cs and add the Phi Silica summarization code:
using Microsoft.JavaScript.NodeApi;
using Microsoft.Windows.AI.Generative;
namespace CsAddon;
[JSExport]
public static class Addon
{
public static async Task<string> SummarizeText(string text)
{
var session = await LanguageModel.CreateAsync();
var result = await session.GenerateResponseAsync($"Summarize: {text}");
return result.Response;
}
}npm run build-addonThis compiles your C# code using Native AOT (Ahead-of-Time compilation), which creates a .node binary that requires no .NET runtime on target machines.
Open src/index.js and load the addon:
const csAddon = require('../csAddon/dist/csAddon.node');Add a test function:
const callPhiSilica = async () => {
console.log('Summarizing with Phi Silica: ')
const result = await csAddon.Addon.summarizeText("The Windows App Development CLI is a powerful tool that bridges cross-platform development with Windows-native capabilities.");
console.log('Summary:', result);
};Call it in createWindow():
callPhiSilica();Open appxmanifest.xml and add the systemAIModels capability:
<Capabilities>
<rescap:Capability Name="runFullTrust" />
<rescap:Capability Name="systemAIModels" />
</Capabilities>After modifying appxmanifest.xml, update the debug identity:
npx winapp node add-electron-debug-identityRun the app:
npm startCheck the console output for the Phi Silica summary.
Note
There is a known Windows bug with sparse packaging Electron applications that can cause crashes or blank windows. See the setup guide for the workaround.
- Creating a WinML addon - Run machine learning models
- Packaging for distribution - Create a signed MSIX package