chatStream method
Sends a streaming chat request to the provider
messages
- The conversation history as a list of chat messages
tools
- Optional list of tools to use in the chat
Returns a stream of chat events
Implementation
@override
Stream<ChatStreamEvent> chatStream(
List<ChatMessage> messages, {
List<Tool>? tools,
}) async* {
try {
final requestBody = _buildRequestBody(messages, tools, true);
if (client.logger.isLoggable(Level.FINE)) {
client.logger
.fine('Phind stream request payload: ${jsonEncode(requestBody)}');
}
// Create SSE stream
final stream = client.postStreamRaw(chatEndpoint, requestBody);
await for (final chunk in stream) {
final events = _parseStreamEvents(chunk);
for (final event in events) {
yield event;
}
}
} catch (e) {
if (e is LLMError) {
yield ErrorEvent(e);
} else {
yield ErrorEvent(GenericError('Unexpected error: $e'));
}
}
}