Custom stream that encapsulates both the response stream and the cancellation guard. Makes sure that the guard is always dropped when the stream is dropped.
These types of ChatbotErrors shouldn’t be shown to the user and are likely created
from an unrecoverable error in our code that should make the stream fail.
Creates a ChatbotChatStreamEvent::Error from the message and returns it in string form.
Either message or error should be Some.
If message is Some, use it as the StreamEvent message. Else, use ChatbotError’s message.
error is either a ResponseError received from Azure and stored in ChatbotError, or
ChatbotError’s error message, or None.
Streams and parses an LLM response from Azure that contains a text response.
Consumes the lines (stream) from Azure, because the stream ends when a text response
is finished.
Returns a stream to be consumed in the caller.
Streams and parses a LLM response from Azure that contains function calls.
Calls the functions and yields a Vec of function results to be sent to Azure.
Consumes the lines (stream), because it ends when a custom function call is made.
Returns a stream to be consumed in the caller.
For saving output items that are not text messages or function calls, i.e. that
don’t need further processing and are not streamed to the user.
Saves reasoning and Azure AI Search items.
Stream from Azure and return the stream when a text response or tool call response is detected.
Tool calls and text responses are processed later with differing logic.
Returns a stream to be consumed in the caller.
Yields the lines (stream) argument, which is the Azure stream.