Last active
November 8, 2025 14:08
-
-
Save ynkdir/d97b2ac1ea906b39a473d4eb7e64517b to your computer and use it in GitHub Desktop.
Test Phi Silica
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://learn.microsoft.com/en-us/windows/ai/apis/phi-silica | |
| # https://learn.microsoft.com/en-us/windows/ai/ | |
| # https://github.com/ynkdir/py-win32more/blob/main/docs/howto-create-packaged-application.md | |
| # | |
| # To use AI Api, | |
| # 1. Unlock Limited Access Feature (fill the following variable). See url above to request access token. | |
| # 2. Make application (python.exe) packaged with package family name used to request access token. | |
| # (It seems to available for unpackaged application, but I can not get it work.) | |
| # | |
| # There is a problem in Phi Silica API access through LAF (resolved by KB5067036). | |
| # | |
| LAF_FEATURE_ID = "" | |
| LAF_TOKEN = "" | |
| LAF_ATTESTATION = "" | |
| import asyncio | |
| from win32more.Microsoft.Windows.AI import AIFeatureReadyState | |
| from win32more.Microsoft.Windows.AI.Text import LanguageModel | |
| from win32more.Windows.ApplicationModel import LimitedAccessFeatures, LimitedAccessFeatureStatus | |
| async def main(): | |
| result = LimitedAccessFeatures.TryUnlockFeature(LAF_FEATURE_ID, LAF_TOKEN, LAF_ATTESTATION) | |
| if result.Status != LimitedAccessFeatureStatus.Available: | |
| raise RuntimeError("unlock feature failed") | |
| if LanguageModel.GetReadyState() == AIFeatureReadyState.NotReady: | |
| await LanguageModel.EnsureReadyAsync() | |
| language_model = await LanguageModel.CreateAsync() | |
| while True: | |
| prompt = input("> ") | |
| if prompt == "quit": | |
| break | |
| result = await language_model.GenerateResponseAsync(prompt) | |
| print(result.Text) | |
| if __name__ == "__main__": | |
| asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment