Windows 应用 SDK中 Phi 硅的 API ref
重要
Windows 应用 SDK 的最新试验通道版本中提供。
Windows 应用 SDK 试验通道包括开发早期阶段的 API 和功能。 试验通道中的所有 API 都可能经过大量修订和中断性变更,并且随时可从后续版本中删除。 实验性功能在生产环境中不受支持,并且使用这些功能的应用程序无法发布到 Microsoft Store。
- 皮硅在中国不可用。
- 不支持解压缩的应用。
了解可以访问本地语言模型的Windows 应用 SDK API,例如 Phi 硅、Microsoft功能最强大的 NPU 优化本地语言模型,可实现设备处理和聊天生成、推理文本、数学求解、代码生成等。
有关详细信息,请参阅 Windows 应用 SDK 中的 Phi 硅入门。
Microsoft.Windows.AI.Generative 命名空间
提供用于本地、设备上的生成式 AI 提示处理和响应的 API。
ImageDescriptionGenerator 类
public sealed class ImageDescriptionGenerator : System.IDisposable
ImageDescriptionGenerator.Close 方法
// This member is not implemented in C#
注解
未在 C# 中实现。
ImageDescriptionGenerator.CreateAsync 方法
public static Windows.Foundation.IAsyncOperation<Microsoft.Windows.AI.Generative.ImageDescriptionGenerator> CreateAsync ();
ImageDescriptionGenerator.DescribeAsync(Microsoft.Windows.Imaging.ImageBuffer) 方法
public Windows.Foundation.IAsyncOperationWithProgress<Microsoft.Windows.AI.Generative.LanguageModelResponse,string> DescribeAsync (Microsoft.Windows.Imaging.ImageBuffer image);
警告
在图像上调用 ImageDescriptionGenerator.DescribeAsync()
时,有时会引发错误。 可以跳过此错误,使调试器能够继续并生成正确的输出。 此错误仅在开发人员环境中可见,不适用于最终用户(使用你的应用的客户)。 使用调试或发布版本将触发此错误。 此错误间歇性地出现,而不是在每次运行时出现。
ImageDescriptionGenerator.DescribeAsync(Microsoft.Graphics.Imaging.ImageBuffer,Microsoft.Windows.AI.Generative.ImageDescriptionScenario) 方法
public Windows.Foundation.IAsyncOperationWithProgress<Microsoft.Windows.AI.Generative.LanguageModelResponse,string> DescribeAsync (Microsoft.Graphics.Imaging.ImageBuffer image, Microsoft.Windows.AI.Generative.ImageDescriptionScenario scenario);
参数
image
方案
返回
注解
ImageDescriptionGenerator.DescribeAsync(Microsoft.Graphics.Imaging.ImageBuffer,Microsoft.Windows.AI.Generative.ImageDescriptionScenario,Microsoft.Windows.AI.ContentModeration.ContentFilterOptions) 方法
public Windows.Foundation.IAsyncOperationWithProgress<Microsoft.Windows.AI.Generative.LanguageModelResponse,string> DescribeAsync (Microsoft.Graphics.Imaging.ImageBuffer image, Microsoft.Windows.AI.Generative.ImageDescriptionScenario scenario, Microsoft.Windows.AI.ContentModeration.ContentFilterOptions contentFilterOptions);
参数
image
方案
内容过滤选项
返回
注解
ImageDescriptionGenerator.IsAvailable 方法
public static bool IsAvailable ();
ImageDescriptionGenerator.MakeAvailableAsync 方法
public static Windows.Foundation.IAsyncOperationWithProgress<Microsoft.Windows.Management.Deployment.PackageDeploymentResult,Microsoft.Windows.Management.Deployment.PackageDeploymentProgress> MakeAvailableAsync ();
ImageDescriptionScenario 枚举器
public enum ImageDescriptionScenario
字段
Accessibility:1
Caption:2
DetailedNarration:3
OfficeCharts:4
ImageLLMAdapterCreator 类
public sealed class ImageLLMAdapterCreator : System.IDisposable
ImageLLMAdapterCreator.Close 方法
// This member is not implemented in C#
注解
未在 C# 中实现。
ImageLLMAdapterCreator.CreateAsync 方法
public static Windows.Foundation.IAsyncOperation<Microsoft.Windows.AI.Generative.ImageLLMAdapterCreator> CreateAsync ();
返回
ImageLLMAdapterCreator.GetImageLLMEmbeddings(Microsoft.Windows.SemanticSearch.EmbeddingVector) 方法
public System.Collections.Generic.IReadOnlyList<float> GetImageLLMEmbeddings (Microsoft.Windows.SemanticSearch.EmbeddingVector embeddings);
参数
嵌入
返回
ImageLLMAdapterCreator.GetImageLLMEmbeddingsAsync(Microsoft.Windows.SemanticSearch.EmbeddingVector) 方法
public Windows.Foundation.IAsyncOperation<System.Collections.Generic.IReadOnlyList<float>> GetImageLLMEmbeddingsAsync (Microsoft.Windows.SemanticSearch.EmbeddingVector embeddings);
参数
嵌入
返回
ImageLLMAdapterCreator.GetModelInputSize 方法
public uint GetModelInputSize ();
返回
ImageLLMAdapterCreator.GetModelOutputSize 方法
public uint GetModelOutputSize ();
返回
ImageLLMAdapterCreator.IsAvailable 方法
public static bool IsAvailable ();
返回
ImageLLMAdapterCreator.MakeAvailableAsync 方法
public static Windows.Foundation.IAsyncOperationWithProgress<Microsoft.Windows.Management.Deployment.PackageDeploymentResult,Microsoft.Windows.Management.Deployment.PackageDeploymentProgress> MakeAvailableAsync ();
返回
LanguageModel 类
public sealed class LanguageModel : System.IDisposable
表示可与本地语言模型交互的对象,以便为提供的提示生成响应。
LanguageModel.Close 方法
释放对象和关联的资源。
注解
未在 C# 中实现。
LanguageModel.CreateAsync 方法
public static Windows.Foundation.IAsyncOperation<Microsoft.Windows.AI.Generative.LanguageModel> CreateAsync ();
异步创建 LanguageModel 类的新实例。
返回
TextRecognizer 类的新实例。
LanguageModel.CreateContext 方法
public Microsoft.Windows.AI.Generative.LanguageModelContext CreateContext ();
返回
注解
LanguageModel.CreateContext(System.String,Microsoft.Windows.AI.ContentModeration.ContentFilterOptions) 方法
public Microsoft.Windows.AI.Generative.LanguageModelContext CreateContext (string systemPrompt, Microsoft.Windows.AI.ContentModeration.ContentFilterOptions contentFilterOptions);
参数
systemPrompt
内容过滤选项
返回
注解
LanguageModel.GenerateEmbeddingVector(System.String,Microsoft.Windows.AI.ContentModeration.ContentFilterOptions) 方法
public System.Collections.Generic.IReadOnlyList<Microsoft.Windows.SemanticSearch.EmbeddingVector> GenerateEmbeddingVector (string prompt, Microsoft.Windows.AI.ContentModeration.ContentFilterOptions contentFilterOptions);
参数
prompt
内容过滤选项
返回
注解
LanguageModel.GenerateEmbeddingVector(System.String) 方法
public System.Collections.Generic.IReadOnlyList<Microsoft.Windows.SemanticSearch.EmbeddingVector> GenerateEmbeddingVector (string prompt);
参数
prompt
返回
注解
LanguageModel.GenerateEmbeddingVectorAsync(System.String) 方法
public Windows.Foundation.IAsyncOperation<System.Collections.Generic.IReadOnlyList<Microsoft.Windows.SemanticSearch.EmbeddingVector>> GenerateEmbeddingVectorAsync (string prompt);
参数
prompt
返回
注解
LanguageModel.GenerateEmbeddingVectorAsync(System.String,Microsoft.Windows.AI.ContentModeration.ContentFilterOptions) 方法
public Windows.Foundation.IAsyncOperation<System.Collections.Generic.IReadOnlyList<Microsoft.Windows.SemanticSearch.EmbeddingVector>> GenerateEmbeddingVectorAsync (string prompt, Microsoft.Windows.AI.ContentModeration.ContentFilterOptions contentFilterOptions);
参数
prompt
内容过滤选项
返回
注解
LanguageModel.GenerateResponseAsync(Microsoft.Windows.AI.Generative.LanguageModelOptions,System.String,Microsoft.Windows.AI.ContentModeration.ContentFilterOptions)方法
public Windows.Foundation.IAsyncOperation<Microsoft.Windows.AI.Generative.LanguageModelResponse> GenerateResponseAsync (Microsoft.Windows.AI.Generative.LanguageModelOptions options, string prompt, Microsoft.Windows.AI.ContentModeration.ContentFilterOptions contentFilterOptions);
参数
选项
prompt
内容过滤选项
返回
注解
LanguageModel.GenerateResponseAsync(System.String) 方法
public Windows.Foundation.IAsyncOperation<Microsoft.Windows.AI.Generative.LanguageModelResponse> GenerateResponseAsync (string prompt);
生成并返回单个提示的完整响应。
参数
prompt
以问题形式显示的提示。
返回
响应字符串和状态。
异常
ArgumentException:指定的提示长于模型可以接受的最大 token 数。
LanguageModel.GenerateResponseAsync(Microsoft.Windows.AI.Generative.LanguageModelOptions,System.String,Microsoft.Windows.AI.ContentModeration.ContentFilterOptions,Microsoft.Windows.AI.Generative.LanguageModelContext) 方法
public Windows.Foundation.IAsyncOperation<Microsoft.Windows.AI.Generative.LanguageModelResponse> GenerateResponseAsync (Microsoft.Windows.AI.Generative.LanguageModelOptions options, string prompt, Microsoft.Windows.AI.ContentModeration.ContentFilterOptions contentFilterOptions, Microsoft.Windows.AI.Generative.LanguageModelContext context);
参数
选项
prompt
内容过滤选项
上下文
返回
注解
LanguageModel.GenerateResponseAsync(Microsoft.Windows.AI.Generative.LanguageModelOptions,System.String) 方法
public Windows.Foundation.IAsyncOperation<Microsoft.Windows.AI.Generative.LanguageModelResponse> GenerateResponseAsync (Microsoft.Windows.AI.Generative.LanguageModelOptions options, string prompt);
参数
选项
prompt
返回
注解
LanguageModel.GenerateResponseFromEmbeddingsWithProgressAsync(Microsoft.Windows.AI.Generative.LanguageModelOptions,Windows.Foundation.Collections.IVectorView{Microsoft.Windows.SemanticSearch.EmbeddingVector},Microsoft.Windows.AI.ContentModeration.ContentFilterOptions,Microsoft.Windows.AI.Generative.LanguageModelContext) 方法
public Windows.Foundation.IAsyncOperationWithProgress<Microsoft.Windows.AI.Generative.LanguageModelResponse,string> GenerateResponseFromEmbeddingsWithProgressAsync (Microsoft.Windows.AI.Generative.LanguageModelOptions options, System.Collections.Generic.IReadOnlyList<Microsoft.Windows.SemanticSearch.EmbeddingVector> promptEmbedding, Microsoft.Windows.AI.ContentModeration.ContentFilterOptions contentFilterOptions, Microsoft.Windows.AI.Generative.LanguageModelContext context);
参数
选项
promptEmbedding
内容过滤选项
上下文
返回
注解
LanguageModel.GenerateResponseFromEmbeddingsWithProgressAsync(Microsoft.Windows.AI.Generative.LanguageModelOptions,Windows.Foundation.Collections.IVectorView{Microsoft.Windows.SemanticSearch.EmbeddingVector},Microsoft.Windows.AI.ContentModeration.ContentFilterOptions) 方法
public Windows.Foundation.IAsyncOperationWithProgress<Microsoft.Windows.AI.Generative.LanguageModelResponse,string> GenerateResponseFromEmbeddingsWithProgressAsync (Microsoft.Windows.AI.Generative.LanguageModelOptions options, System.Collections.Generic.IReadOnlyList<Microsoft.Windows.SemanticSearch.EmbeddingVector> promptEmbedding, Microsoft.Windows.AI.ContentModeration.ContentFilterOptions contentFilterOptions);
参数
选项
promptEmbedding
内容过滤选项
返回
注解
LanguageModel.GenerateResponseFromEmbeddingsWithProgressAsync(Windows.Foundation.Collections.IVectorView{Microsoft.Windows.SemanticSearch.EmbeddingVector}) 方法
public Windows.Foundation.IAsyncOperationWithProgress<Microsoft.Windows.AI.Generative.LanguageModelResponse,string> GenerateResponseFromEmbeddingsWithProgressAsync (System.Collections.Generic.IReadOnlyList<Microsoft.Windows.SemanticSearch.EmbeddingVector> promptEmbedding);
参数
promptEmbedding
返回
注解
LanguageModel.GenerateResponseFromEmbeddingsWithProgressAsync(Microsoft.Windows.AI.Generative.LanguageModelOptions,Windows.Foundation.Collections.IVectorView{Microsoft.Windows.SemanticSearch.EmbeddingVector}) 方法
public Windows.Foundation.IAsyncOperationWithProgress<Microsoft.Windows.AI.Generative.LanguageModelResponse,string> GenerateResponseFromEmbeddingsWithProgressAsync (Microsoft.Windows.AI.Generative.LanguageModelOptions options, System.Collections.Generic.IReadOnlyList<Microsoft.Windows.SemanticSearch.EmbeddingVector> promptEmbedding);
参数
选项
promptEmbedding
返回
LanguageModel.GenerateResponseFromTokensWithProgressAsync(Microsoft.Windows.AI.Generative.LanguageModelOptions,Windows.Foundation.Collections.IVectorView{System.Int64}) 方法
public Windows.Foundation.IAsyncOperationWithProgress<Microsoft.Windows.AI.Generative.LanguageModelResponse,string> GenerateResponseFromTokensWithProgressAsync (Microsoft.Windows.AI.Generative.LanguageModelOptions options, System.Collections.Generic.IReadOnlyList<long> promptTokens);
参数
选项
promptTokens
返回
LanguageModel.GenerateResponseFromTokensWithProgressAsync(Microsoft.Windows.AI.Generative.LanguageModelOptions,Windows.Foundation.Collections.IVectorView{System.Int64},Microsoft.Windows.AI.ContentModeration.ContentFilterOptions,Microsoft.Windows.AI.Generative.LanguageModelContext) 方法
public Windows.Foundation.IAsyncOperationWithProgress<Microsoft.Windows.AI.Generative.LanguageModelResponse,string> GenerateResponseFromTokensWithProgressAsync (Microsoft.Windows.AI.Generative.LanguageModelOptions options, System.Collections.Generic.IReadOnlyList<long> promptTokens, Microsoft.Windows.AI.ContentModeration.ContentFilterOptions contentFilterOptions, Microsoft.Windows.AI.Generative.LanguageModelContext context);
参数
选项
promptTokens
内容过滤选项
上下文
返回
LanguageModel.GenerateResponseFromTokensWithProgressAsync(Microsoft.Windows.AI.Generative.LanguageModelOptions,Windows.Foundation.Collections.IVectorView{System.Int64},Microsoft.Windows.AI.ContentModeration.ContentFilterOptions) 方法
public Windows.Foundation.IAsyncOperationWithProgress<Microsoft.Windows.AI.Generative.LanguageModelResponse,string> GenerateResponseFromTokensWithProgressAsync (Microsoft.Windows.AI.Generative.LanguageModelOptions options, System.Collections.Generic.IReadOnlyList<long> promptTokens, Microsoft.Windows.AI.ContentModeration.ContentFilterOptions contentFilterOptions);
参数
选项
promptTokens
内容过滤选项
返回
LanguageModel.GenerateResponseWithProgressAsync(Microsoft.Windows.AI.Generative.LanguageModelOptions,System.String,Microsoft.Windows.AI.ContentModeration.ContentFilterOptions) 方法
public Windows.Foundation.IAsyncOperationWithProgress<Microsoft.Windows.AI.Generative.LanguageModelResponse,string> GenerateResponseWithProgressAsync (Microsoft.Windows.AI.Generative.LanguageModelOptions options, string prompt, Microsoft.Windows.AI.ContentModeration.ContentFilterOptions contentFilterOptions);
参数
选项
prompt
内容过滤选项
返回
LanguageModel.GenerateResponseWithProgressAsync(System.String) 方法
public Windows.Foundation.IAsyncOperationWithProgress<Microsoft.Windows.AI.Generative.LanguageModelResponse,string> GenerateResponseWithProgressAsync (string prompt);
参数
prompt
返回
LanguageModel.GenerateResponseWithProgressAsync(Microsoft.Windows.AI.Generative.LanguageModelOptions,System.String) 方法
public Windows.Foundation.IAsyncOperationWithProgress<Microsoft.Windows.AI.Generative.LanguageModelResponse,string> GenerateResponseWithProgressAsync (Microsoft.Windows.AI.Generative.LanguageModelOptions options, string prompt);
参数
选项
prompt
返回
LanguageModel.GenerateResponseWithProgressAsync(Microsoft.Windows.AI.Generative.LanguageModelOptions,System.String,Microsoft.Windows.AI.ContentModeration.ContentFilterOptions,Microsoft.Windows.AI.Generative.LanguageModelContext) 方法
public Windows.Foundation.IAsyncOperationWithProgress<Microsoft.Windows.AI.Generative.LanguageModelResponse,string> GenerateResponseWithProgressAsync (Microsoft.Windows.AI.Generative.LanguageModelOptions options, string prompt, Microsoft.Windows.AI.ContentModeration.ContentFilterOptions contentFilterOptions, Microsoft.Windows.AI.Generative.LanguageModelContext context);
参数
选项
prompt
内容过滤选项
上下文
返回
LanguageModel.GenerateTokens(System.String,Microsoft.Windows.AI.ContentModeration.ContentFilterOptions) 方法
public System.Collections.Generic.IReadOnlyList<long> GenerateTokens (string text, Microsoft.Windows.AI.ContentModeration.ContentFilterOptions contentFilterOptions);
参数
text
内容过滤选项
返回
LanguageModel.GenerateTokens(System.String,Microsoft.Windows.AI.ContentModeration.ContentFilterOptions) 方法
public System.Collections.Generic.IReadOnlyList<long> GenerateTokens (string text, Microsoft.Windows.AI.ContentModeration.ContentFilterOptions contentFilterOptions);
参数
text
内容过滤选项
返回
LanguageModel.GenerateTokensAsync(System.String) 方法
public Windows.Foundation.IAsyncOperation<System.Collections.Generic.IReadOnlyList<long>> GenerateTokensAsync (string text);
参数
text
返回
LanguageModel.GenerateTokensAsync(System.String,Microsoft.Windows.AI.ContentModeration.ContentFilterOptions) 方法
public Windows.Foundation.IAsyncOperation<System.Collections.Generic.IReadOnlyList<long>> GenerateTokensAsync (string text, Microsoft.Windows.AI.ContentModeration.ContentFilterOptions contentFilterOptions);
参数
text
内容过滤选项
返回
LanguageModel.IsAvailable 方法
public static bool IsAvailable ();
返回
LanguageModel.IsPromptLargerThanContext(Microsoft.Windows.AI.Generative.LanguageModelContext,System.String) 方法
public bool IsPromptLargerThanContext (Microsoft.Windows.AI.Generative.LanguageModelContext context, string prompt);
参数
上下文
prompt
返回
LanguageModel.IsPromptLargerThanContext(System.String) 方法
public bool IsPromptLargerThanContext (string prompt);
参数
prompt
返回
LanguageModel.MakeAvailableAsync 方法
public static Windows.Foundation.IAsyncOperationWithProgress<Microsoft.Windows.Management.Deployment.PackageDeploymentResult,Microsoft.Windows.Management.Deployment.PackageDeploymentProgress> MakeAvailableAsync ();
返回
LanguageModelContext 类
public sealed class LanguageModelContext
LanguageModelOptions 类
public sealed class LanguageModelOptions
LanguageModelOptions.#ctor 构造函数
public LanguageModelOptions ();
LanguageModelOptions.#ctor(Microsoft.Windows.AI.Generative.LanguageModelSkill,System.Single,System.Single,System.UInt32) 构造函数
public LanguageModelOptions (Microsoft.Windows.AI.Generative.LanguageModelSkill skill, float temp, float top_p, uint top_k);
参数
技能
temp
top_p
top_k
LanguageModelOptions.Skill 属性
public Microsoft.Windows.AI.Generative.LanguageModelSkill Skill { get; set; }
属性值
LanguageModelOptions.Temp 属性
public float Temp { get; set; }
属性值
LanguageModelOptions.Top_k 属性
public uint Top_k { get; set; }
属性值
LanguageModelOptions.Top_p 属性
public float Top_p { get; set; }
属性值
LanguageModelResponse 类
public sealed class LanguageModelResponse
LanguageModelResponse.#ctor(System.String,Microsoft.Windows.AI.Generative.LanguageModelResponseStatus) 构造函数
public LanguageModelResponse (string response, Microsoft.Windows.AI.Generative.LanguageModelResponseStatus status);
参数
response
status
LanguageModelResponse.Response 属性
public string Response { get; }
属性值
LanguageModelResponse.Status 属性
public Microsoft.Windows.AI.Generative.LanguageModelResponseStatus Status { get; }
属性值
LanguageModelResponseStatus 枚举
public enum LanguageModelResponseStatus
字段
Complete:0
InProgress:1
BlockedByPolicy:2
PromptLargerThanContext: 3
PromptBlockedByPolicy:4
ResponseBlockedByPolicy:5
LanguageModelSkill 枚举
public enum LanguageModelSkill
字段
常规:0
TextToTable:1
汇总:2
重写:3
相关内容
- 在 Windows 上开发负责任的生成式 AI 应用程序和功能
- Windows 应用 SDK中的 Phi 硅入门
- Windows 应用 SDK
- Windows 应用 SDK 的最新发行说明