Edit

Share via


Phi Silica walkthrough

Screenshot of the home page for the Windows AI Foundry Sample app.

This short tutorial walks through the Windows AI Foundry Sample for .NET MAUI.

Prerequisites

Complete the steps in the Getting Started page for .NET MAUI.

Introduction

This sample shows how to use various Windows AI APIs, including LanguageModel for text generation and ImageScaler for scaling and sharpening images.

The sample includes the following four files:

  1. MauiWindowsCopilotRuntimeSample.csproj: Adds the required Windows App SDK package reference for the Windows AI APIs and sets the necessary TargetFramework for Windows.
  2. Platforms/Windows/MainPage.cs: Implements partial methods from the shared MainPage class that show and handle the text generation and image scaling functionality.
  3. MainPage.xaml: Defines controls for showing text generation and image scaling.
  4. MainPage.xaml.cs: Defines partial methods that MainPage.cs implements.

In the second file listed above, you'll find the following function, which demonstrates text summarization functionality.

  1. Create a LanguageModel instance (languageModel).
  2. Pass that LanguageModel to the TextSummarizer constructor.
  3. Pass some text to the SummarizeAsync method and print the result.
using Microsoft.Windows.AI; 
 
using LanguageModel languageModel = await LanguageModel.CreateAsync(); 
 
string prompt = "This is a large amount of text I want to have summarized.";

LanguageModelOptions options = new LanguageModelOptions {
    Skill = LanguageModelSkill.Summarize
};
 
var result = await languageModel.GenerateResponseAsync(options, prompt); 
 
Console.WriteLine(result.Text); 
using namespace winrt::Microsoft::Windows::AI::Generative;

auto languageModel = LanguageModel::CreateAsync().get();

std::string prompt = "This is a large amount of text I want to have summarized.";

LanguageModelOptions options = LanguageModelOptions();
options.Skill = LanguageModelSkill.Summarize;

auto result = languageModel.GenerateResponseAsync(options, prompt).get();

std::cout << result.Text() << std::endl;

The sample app after calling the ImageScaler and LanguageModel APIs.

Build and run the sample

  1. Clone the repository onto your Copilot+ PC.
  2. Open the solution file MauiWindowsCopilotRuntimeSample.sln in Visual Studio 2022.
  3. Ensure the debug toolbar has "Windows Machine" set as the target device.
  4. Press F5 or select "Start Debugging" from the Debug menu to run the sample. (The sample can also be run without debugging by selecting "Start Without Debugging" from the Debug menu or Ctrl+F5.)
  5. Click one of the "Scale" buttons to scale the image, or enter a text prompt and click the "Generate" button to generate a text response.

See also