Get started with Phi Silica in the Windows App SDK
Important
This feature is not yet available. It is expected to ship in an upcoming experimental channel release of the Windows App SDK.
The Windows App SDK experimental channel includes APIs and features in early stages of development. All APIs in the experimental channel are subject to extensive revisions and breaking changes and may be removed from subsequent releases at any time. They are not supported for use in production environments, and apps that use experimental features cannot be published to the Microsoft Store.
Phi Silica is a local language model that you will be able to integrate into your Windows apps using the Windows App SDK.
As Microsoft's most powerful NPU-tuned local language model, Phi Silica is optimized for efficiency and performance on Windows Copilot+ PCs devices while still offering many of the capabilities found in Large Language Models (LLMs).
This level of optimization is exclusive to the model within the Windows App SDK and is not available in other versions of Phi.
For API details, see API ref for Phi Silica in the Windows App SDK.
Tip
Provide feedback on these APIs and their functionality by creating a new Issue in the Windows App SDK GitHub repo. (Make sure you include Phi Silica in the title!)
Prerequisites
- CoPilot+ PCs containing a Qualcomm Snapdragon® X Elite processor.
Use the Windows App SDK to integrate Phi Silica into your Windows app
With a local Phi Silica language model and the Windows App SDK you can generate text responses to user prompts.
Generate a complete response
This example shows how to generate a response to a Q&A prompt where the full response is generated before the result is returned.
- First, we ensure the language model is available by calling the IsAvailable method and waiting for the MakeAvailableAsync method to return successfully.
- Once the language model is available, we create a LanguageModel object to reference it.
- Finally, we submit a string prompt to the model using the GenerateResponseAsync method, which returns the complete result.
using Microsoft.Windows.AI.Generative;
if (!LanguageModel.IsAvailable())
{
var op = await LanguageModel.MakeAvailableAsync();
}
using LanguageModel languageModel = await LanguageModel.CreateAsync();
string prompt = "Provide the molecular formula for glucose.";
var result = await languageModel.GenerateResponseAsync(prompt);
Console.WriteLine(result.Response);
using namespace winrt::Microsoft::Windows::AI::Generative;
if (!LanguageModel::IsAvailable())
{
auto op = LanguageModel::MakeAvailableAsync().get();
}
auto languageModel = LanguageModel::CreateAsync().get();
std::string prompt = "Provide the molecular formula for glucose.";
auto result = languageModel.GenerateResponseAsync(prompt).get();
std::cout << result.Response << std::endl;
The response generated by this example is:
The molecular formula for glucose is C6H12O6.
Generate a stream of partial responses
This example shows how to generate a response to a Q&A prompt where the response is returned as a stream of partial results.
- First we create a LanguageModel object to reference the local language model (we already checked for the presence of the language model in the previous snippet).
- Then we asynchronously retrieve the LanguageModelResponse in a call to GenerateResponseWithProgressAsync and write it to the console as the response is generated.
using Microsoft.Windows.AI.Generative;
using LanguageModel languageModel = await LanguageModel.CreateAsync();
string prompt = "Provide the molecular formula for glucose.";
AsyncOperationProgressHandler<LanguageModelResponse, string>
progressHandler = (asyncInfo, delta) =>
{
Console.WriteLine($"Progress: {delta}");
Console.WriteLine($"Response so far: {asyncInfo.GetResults().Response()}");
};
var asyncOp = languageModel.GenerateResponseWithProgressAsync(prompt);
asyncOp.Progress = progressHandler;
var result = await asyncOp;
Console.WriteLine(result.Response);
using namespace winrt::Microsoft::Windows::AI::Generative;
auto languageModel = LanguageModel::CreateAsync().get();
std::string prompt = "Provide the molecular formula for glucose.";
AsyncOperationProgressHandler<LanguageModelResponse, std::string> progressHandler =
[](const IAsyncOperationWithProgress<LanguageModelResponse, std::string>& asyncInfo, const std::string& delta)
{
std::cout << "Progress: " << delta << std::endl;
std::cout << "Response so far: " << asyncInfo.GetResults().Response() << std::endl;
};
auto asyncOp = languageModel.GenerateResponseWithProgressAsync(prompt);
asyncOp.Progress(progressHandler);
auto result = asyncOp.get();
std::cout << result.Response() << std::endl;
Responsible AI
Phi Silica provides developers with a powerful, trustworthy model for building apps with safe, secure AI experiences. The following steps have been taken to ensure Phi Silica is trustworthy, secure, and built responsibly (we also recommend reviewing the best practices described in Responsible Generative AI Development on Windows).
- Thorough testing and evaluation of the model quality to identify and mitigate potential risks.
- Creation of a Phi Silica model card that describes the strengths and limitations of the model and provides clarity about intended uses.
- Incremental roll out of Phi Silica experimental releases. Following the final Phi Silica experimental release, the roll out will expand to signed apps to ensure that malware scans have been applied to applications with local model capabilities.
- Provide customer controls through the Capability Access Manager in Settings so users can turn off the model on the device for the system, user, or app.
- Provide a local AI model for content moderation that identifies and filters harmful content in both the input and AI-generated output of Phi Silica. This local content moderation model is based on the Azure AI Content Safety model for text moderation and provides similar performance.
Important
No content safety system is infallible and occasional errors can occur, so we recommend integrating supplementary Responsible AI (RAI) tools and practices. For more details, see Responsible Generative AI Development on Windows.
Additional resources
Access files and folders with Windows App SDK and WinRT APIs