getResponse method
Implementation
@override
Future<String> getResponse() async {
_assertNotClosed();
final text = _queryBuffer.toString();
_queryBuffer.clear();
// Capture and clear pending media BEFORE making the call
// This prevents stale media from being reused if the call fails
final audio = _pendingAudio;
final image = _pendingImage;
_pendingAudio = null;
_pendingImage = null;
final buffer = StringBuffer();
if (audio != null) {
await for (final token in grpcClient.chatWithAudio(text, audio)) {
buffer.write(token);
}
} else if (image != null) {
await for (final token in grpcClient.chatWithImage(text, image)) {
buffer.write(token);
}
} else {
await for (final token in grpcClient.chat(text)) {
buffer.write(token);
}
}
return buffer.toString();
}