in frontend/frontend-flutter/lib/screens/bot.dart [785:1005]
Widget customMessageBuilder(types.CustomMessage customMessage,
{required int messageWidth}) {
print('Bot : customMessageBuilder(): START');
String inputString = "";
return Container(
//width: 500,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
//Display the firstname and lastname
Container(
padding: const EdgeInsets.only(top: 20, left: 20),
width: screenSize!.width,
child: Text(_user1.firstName! + " " + _user1.lastName! + "\n",
style: TextStyle(
fontSize: 12,
color: Colors.green,
fontWeight: FontWeight.bold),
textAlign: TextAlign.left)),
//Display answer
!customMessage.metadata!.containsKey('stream') ||
customMessage.metadata!['textSummary'] != "firstChunck"
? Container(
padding: const EdgeInsets.only(top: 20, left: 20),
width: screenSize!.width,
child: Text(customMessage.metadata!['textSummary'],
textAlign: TextAlign.start, style: TextStyle(fontSize: 16)),
)
: StreamBuilder<BaseChunk<Object>>(
stream: customMessage.metadata!['stream'],
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
print(
'Bot : customMessageBuilder(): StreamBuilder : snapshot.connectionState : WAITING');
streamingText = "";
return SizedBox(
width: 100,
height: 100,
child: CircularProgressIndicator(
strokeWidth: 6,
),
); // Display a loading indicator when waiting for data.
} else if (snapshot.hasError) {
print(
'Bot : customMessageBuilder(): StreamBuilder : snapshot.hasError : ERROR');
return Text(
'Error: ${snapshot.error}'); // Display an error message if an error occurs.
} else if (!snapshot.hasData) {
print(
'Bot : customMessageBuilder(): StreamBuilder : !snapshot.hasData : No data available');
return Text(
'No data available'); // Display a message when no data is available.
} else {
print(
'Bot : customMessageBuilder(): StreamBuilder : snapshot.hasData');
var answerPlainTextChunck = pickFromJson(
snapshot.data!.chunk.toString(), 'response')
.asStringOrNull();
if (answerPlainTextChunck != "end_stream") {
//streamingText = streamingText + answerPlainTextChunck!;
inputString = inputString + answerPlainTextChunck!;
print(
'Bot : customMessageBuilder(): StreamBuilder : snapshot.hasData : answerPlainTextChunck != end_stream');
//customMessage.metadata!['eventSource'].close();
} else {
customMessage.metadata!['textSummary'] = inputString;
print(
'Bot : customMessageBuilder(): StreamBuilder : snapshot.hasData : answerPlainTextChunck == end_stream');
Stopwatch stopwatchStreaming =
customMessage.metadata!['stopWatch'] as Stopwatch;
stopwatchStreaming.stop();
//Update stepper state to get_text_summary
BlocProvider.of<UpdateStepperCubit>(context)
.updateStepperStatusUploaded(
status: StepperStatus.get_text_summary,
message: "NL answer received in",
stateStepper: StepState.complete,
isActiveStepper: true,
debugInfo: StepperExpertInfo(
uri:
"https://colab-cloudrun-template-ra1-uz6w7mqrka-uc.a.run.app/generate_streaming",
body: '{"N/A": "N/A"}',
header: '{"Content-Type": "app/json}',
response: responsePalMBody,
summary: inputString,
statusCode: 200,
stepDuration: stopwatchStreaming.elapsed
.inMilliseconds, //stopwatchtextToDoc.elapsed.inMilliseconds,
));
}
return Container(
padding: const EdgeInsets.only(top: 20, left: 20),
width: screenSize!.width,
child: Text(inputString, //streamingText,
textAlign: TextAlign.start,
style: TextStyle(fontSize: 16)),
);
}
}),
if (customMessage.metadata!['dataSource'] != null &&
!customMessage.metadata!['textSummary']
.contains("The request did not return meaningful information"))
Container(
child: TabbedContainer(
initialIndex: customMessage.metadata!['graph'] != null ? 1 : 0,
controller: _tabController,
tabs: const [
Tab(text: "Table", icon: Icon(Icons.table_rows_sharp)),
Tab(text: "Graph", icon: Icon(Icons.bar_chart)),
],
tabViews: [
Center(
child: SingleChildScrollView(child: Container(width: screenSize!.width ,child: customMessage.metadata!['dataSource'] ?? Text('No Data')))),
Center(
child: getGoogleGraph(customMessage.metadata!['graph']) ?? Text('No Graph')),
],
),
),
SizedBox(height: 40),
//Add feedback
Container(
width: screenSize!.width / 10,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: Colors.black12, // Adjust the radius as needed
),
child: Padding(
padding: const EdgeInsets.all(8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
InkWell(
onTap: () {
showFeedbackDialog();
},
onHover: (value) {
setState(() {
_isThumbsUpHovered = value;
});
},
child: Tooltip(
message: "Provide your feedback on the generated answer",
child: new Image(
image: new AssetImage("assets/images/thumbs_up1.png"),
width: 20,
height: 20,
color: _isThumbsUpHovered
? Colors.grey.withOpacity(0.5)
: null,
colorBlendMode:
_isThumbsUpHovered ? BlendMode.modulate : null,
fit: BoxFit.scaleDown,
alignment: Alignment.center,
),
),
),
InkWell(
onTap: () {
showFeedbackDialog();
},
onHover: (value) {
setState(() {
_isThumbsDownHovered = value;
});
},
child: Tooltip(
message: "Provide your feedback on the generated answer",
child: new Image(
image: new AssetImage("assets/images/thumbs_down1.png"),
width: 20,
height: 20,
color: _isThumbsDownHovered
? Colors.grey.withOpacity(0.5)
: null,
colorBlendMode:
_isThumbsDownHovered ? BlendMode.modulate : null,
fit: BoxFit.scaleDown,
alignment: Alignment.center,
),
),
),
InkWell(
onTap: () {
print("Bot: copy : onTap : START");
print('Bot : customMessageBuilder() : copy : onTap: () : START');
copyGraphToClipBoard(customMessage.metadata!['imageId'],
customMessage.metadata!['textSummary']);
},
onHover: (value) {
setState(() {
_isCopyHovered = value;
});
},
child: Tooltip(
message: "Copy the answer",
child: new Image(
image: new AssetImage("assets/images/copy1.png"),
width: 20,
height: 20,
color:
_isCopyHovered ? Colors.grey.withOpacity(0.5) : null,
colorBlendMode:
_isCopyHovered ? BlendMode.modulate : null,
fit: BoxFit.scaleDown,
alignment: Alignment.center,
),
),
),
],
),
),
)
//customMessage.metadata!['graph'],
],
));
}