StreamingResponse class
A helper class for streaming responses to the client.
Remarks
This class is used to send a series of updates to the client in a single response. The expected sequence of calls is:
sendInformativeUpdate()
, sendTextChunk()
, sendTextChunk()
, ..., endStream()
.
Once endStream()
is called, the stream is considered ended and no further updates can be sent.
Constructors
Streaming |
Creates a new StreamingResponse instance. |
Properties
citations | Gets the citations of the current response. |
stream |
Gets the stream ID of the current response. |
updates |
Gets the number of updates sent for the stream. |
Methods
end |
Ends the stream by sending the final message to the client. |
get |
Returns the most recently streamed message. |
queue |
Queues an informative update to be sent to the client. |
queue |
Queues a chunk of partial message text to be sent to the client |
set |
Sets the attachments to attach to the final chunk. |
set |
Sets the citations for the full message. |
set |
Sets the Feedback Loop in Teams that allows a user to
give thumbs up or down to a response.
Default is |
set |
Sets the type of UI to use for the feedback loop. |
set |
Sets the the Generated by AI label in Teams
Default is |
set |
Sets the sensitivity label to attach to the final chunk. |
wait |
Waits for the outgoing activity queue to be empty. |
Constructor Details
StreamingResponse(TurnContext)
Creates a new StreamingResponse instance.
new StreamingResponse(context: TurnContext)
Parameters
- context
-
TurnContext
Context for the current turn of conversation with the user.
Property Details
citations
Gets the citations of the current response.
undefined | ClientCitation[] citations
Property Value
undefined | ClientCitation[]
streamId
Gets the stream ID of the current response.
undefined | string streamId
Property Value
undefined | string
- The stream ID of the current response.
updatesSent
Gets the number of updates sent for the stream.
number updatesSent
Property Value
number
- The number of updates sent for the stream.
Method Details
endStream()
Ends the stream by sending the final message to the client.
function endStream(): Promise<void>
Returns
Promise<void>
- A promise representing the async operation
getMessage()
Returns the most recently streamed message.
function getMessage(): string
Returns
string
The streamed message.
queueInformativeUpdate(string)
Queues an informative update to be sent to the client.
function queueInformativeUpdate(text: string)
Parameters
- text
-
string
Text of the update to send.
queueTextChunk(string, Citation[])
Queues a chunk of partial message text to be sent to the client
function queueTextChunk(text: string, citations?: Citation[])
Parameters
- text
-
string
Partial text of the message to send.
- citations
-
Citation[]
Citations to be included in the message.
Remarks
The text we be sent as quickly as possible to the client. Chunks may be combined before delivery to the client.
setAttachments(Attachment[])
Sets the attachments to attach to the final chunk.
function setAttachments(attachments: Attachment[])
Parameters
- attachments
-
Attachment[]
List of attachments.
setCitations(Citation[])
Sets the citations for the full message.
function setCitations(citations: Citation[])
Parameters
- citations
-
Citation[]
Citations to be included in the message.
setFeedbackLoop(boolean)
Sets the Feedback Loop in Teams that allows a user to
give thumbs up or down to a response.
Default is false
.
function setFeedbackLoop(enableFeedbackLoop: boolean)
Parameters
- enableFeedbackLoop
-
boolean
If true, the feedback loop is enabled.
setFeedbackLoopType("default" | "custom")
Sets the type of UI to use for the feedback loop.
function setFeedbackLoopType(feedbackLoopType: "default" | "custom")
Parameters
- feedbackLoopType
-
"default" | "custom"
The type of the feedback loop.
setGeneratedByAILabel(boolean)
Sets the the Generated by AI label in Teams
Default is false
.
function setGeneratedByAILabel(enableGeneratedByAILabel: boolean)
Parameters
- enableGeneratedByAILabel
-
boolean
If true, the label is added.
setSensitivityLabel(SensitivityUsageInfo)
Sets the sensitivity label to attach to the final chunk.
function setSensitivityLabel(sensitivityLabel: SensitivityUsageInfo)
Parameters
- sensitivityLabel
-
SensitivityUsageInfo
The sensitivty label.
waitForQueue()
Waits for the outgoing activity queue to be empty.
function waitForQueue(): Promise<void>
Returns
Promise<void>
- A promise representing the async operation.