Share via


KernelExtensions.InvokePromptStreamingAsync Method

Definition

Overloads

InvokePromptStreamingAsync(Kernel, String, KernelArguments, String, IPromptTemplateFactory, CancellationToken)

Invokes a prompt specified via a prompt template and streams its results.

InvokePromptStreamingAsync<T>(Kernel, String, KernelArguments, String, IPromptTemplateFactory, CancellationToken)

Invokes a prompt specified via a prompt template and streams its results of type T.

InvokePromptStreamingAsync(Kernel, String, KernelArguments, String, IPromptTemplateFactory, CancellationToken)

Invokes a prompt specified via a prompt template and streams its results.

public static System.Collections.Generic.IAsyncEnumerable<Microsoft.SemanticKernel.StreamingKernelContent> InvokePromptStreamingAsync (this Microsoft.SemanticKernel.Kernel kernel, string promptTemplate, Microsoft.SemanticKernel.KernelArguments? arguments = default, string? templateFormat = default, Microsoft.SemanticKernel.IPromptTemplateFactory? promptTemplateFactory = default, System.Threading.CancellationToken cancellationToken = default);
static member InvokePromptStreamingAsync : Microsoft.SemanticKernel.Kernel * string * Microsoft.SemanticKernel.KernelArguments * string * Microsoft.SemanticKernel.IPromptTemplateFactory * System.Threading.CancellationToken -> System.Collections.Generic.IAsyncEnumerable<Microsoft.SemanticKernel.StreamingKernelContent>
<Extension()>
Public Function InvokePromptStreamingAsync (kernel As Kernel, promptTemplate As String, Optional arguments As KernelArguments = Nothing, Optional templateFormat As String = Nothing, Optional promptTemplateFactory As IPromptTemplateFactory = Nothing, Optional cancellationToken As CancellationToken = Nothing) As IAsyncEnumerable(Of StreamingKernelContent)

Parameters

kernel
Kernel

The Kernel containing services, plugins, and other state for use throughout the operation.

promptTemplate
String

Prompt template for the function.

arguments
KernelArguments

The arguments to pass to the function's invocation, including any PromptExecutionSettings.

templateFormat
String

The template format of promptTemplate. This must be provided if promptTemplateFactory is not null.

promptTemplateFactory
IPromptTemplateFactory

The IPromptTemplateFactory to use when interpreting the promptTemplate into a IPromptTemplate. If null, a default factory will be used.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

An IAsyncEnumerable<T> for streaming the results of the function's invocation.

Exceptions

promptTemplate is null.

promptTemplate is empty or composed entirely of whitespace.

Remarks

The function will not be invoked until an enumerator is retrieved from the returned IAsyncEnumerable<T> and its iteration initiated via an initial call to MoveNextAsync().

Applies to

InvokePromptStreamingAsync<T>(Kernel, String, KernelArguments, String, IPromptTemplateFactory, CancellationToken)

Invokes a prompt specified via a prompt template and streams its results of type T.

public static System.Collections.Generic.IAsyncEnumerable<T> InvokePromptStreamingAsync<T> (this Microsoft.SemanticKernel.Kernel kernel, string promptTemplate, Microsoft.SemanticKernel.KernelArguments? arguments = default, string? templateFormat = default, Microsoft.SemanticKernel.IPromptTemplateFactory? promptTemplateFactory = default, System.Threading.CancellationToken cancellationToken = default);
static member InvokePromptStreamingAsync : Microsoft.SemanticKernel.Kernel * string * Microsoft.SemanticKernel.KernelArguments * string * Microsoft.SemanticKernel.IPromptTemplateFactory * System.Threading.CancellationToken -> System.Collections.Generic.IAsyncEnumerable<'T>
<Extension()>
Public Function InvokePromptStreamingAsync(Of T) (kernel As Kernel, promptTemplate As String, Optional arguments As KernelArguments = Nothing, Optional templateFormat As String = Nothing, Optional promptTemplateFactory As IPromptTemplateFactory = Nothing, Optional cancellationToken As CancellationToken = Nothing) As IAsyncEnumerable(Of T)

Type Parameters

T

Parameters

kernel
Kernel

The Kernel containing services, plugins, and other state for use throughout the operation.

promptTemplate
String

Prompt template for the function.

arguments
KernelArguments

The arguments to pass to the function's invocation, including any PromptExecutionSettings.

templateFormat
String

The template format of promptTemplate. This must be provided if promptTemplateFactory is not null.

promptTemplateFactory
IPromptTemplateFactory

The IPromptTemplateFactory to use when interpreting the promptTemplate into a IPromptTemplate. If null, a default factory will be used.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

An IAsyncEnumerable<T> for streaming the results of the function's invocation.

Exceptions

promptTemplate is null.

promptTemplate is empty or composed entirely of whitespace.

Remarks

The function will not be invoked until an enumerator is retrieved from the returned IAsyncEnumerable<T> and its iteration initiated via an initial call to MoveNextAsync().

Applies to