stopGeneration method
Implementation
Stream<dynamic> stopGeneration({
required String baseDataUrl,
required String mentor,
required String generation_id,
required String token,
required String username,
String tenant = 'main', // Optional prompt
}) {
var channel = WebSocketChannel.connect(
Uri.parse('wss://$baseDataUrl/ws/langflow-stop-generation/'),
);
// Initial data without the prompt
final dataWithoutPrompt = {
"generation_id": generation_id,
"name": mentor,
"tenant": tenant,
"username": username,
"token": token
};
// Send initial data without prompt
channel.sink.add(json.encode(dataWithoutPrompt));
// Return a stream that handles incoming messages
return channel.stream.map((message) {
var partialResponse = jsonDecode(message);
if ((partialResponse.containsKey('error')) ||
(partialResponse.containsKey('eos') &&
partialResponse['eos'] == true)) {
channel.sink.close();
}
return partialResponse;
}).handleError((error) {
print('Error connecting to server: $error');
channel.sink.close();
});
}