Files
Auto-GPT/frontend/lib/views/task_queue/task_queue_view.dart
hunteraraujo bf03dd8739 Refactor runBenchmark in SkillTreeViewModel for New Report Generation Flow
This commit updates the runBenchmark method in the SkillTreeViewModel class to align with the new report generation flow. The updated method does the following:

1. Checks if a benchmark is already running to prevent overlapping runs.
2. Sets a flag to indicate that the benchmark is running and notifies the UI.
3. Reverses the selected node hierarchy for report generation.
4. Loops through each node in the reversed hierarchy to:
  - Generate a unique UUID for each test run.
  - Create a ReportRequestBody object.
  - Call the generateSingleReport method in the BenchmarkService.
  - Update the UI after each single report is generated.

5. After all single reports are generated, it calls the generateCombinedReport method in the BenchmarkService, passing in all the generated UUIDs.

6. Finally, it sets the benchmark running flag to false and notifies the UI.

This change improves the report generation flow and allows for both individual and combined reports.
2023-09-18 19:55:01 -07:00

101 lines
3.8 KiB
Dart

import 'package:auto_gpt_flutter_client/models/benchmark_service/report_request_body.dart';
import 'package:flutter/material.dart';
import 'package:auto_gpt_flutter_client/viewmodels/skill_tree_viewmodel.dart';
import 'package:provider/provider.dart';
// TODO: Add view model for task queue instead of skill tree view model
class TaskQueueView extends StatelessWidget {
@override
Widget build(BuildContext context) {
final viewModel = Provider.of<SkillTreeViewModel>(context);
// Reverse the node hierarchy
final reversedHierarchy =
viewModel.selectedNodeHierarchy?.reversed.toList() ?? [];
// Convert reversedHierarchy to a list of test names
final List<String> testNames =
reversedHierarchy.map((node) => node.data.name).toList();
return Material(
color: Colors.white,
child: Stack(
children: [
// The list of tasks (tiles)
ListView.builder(
itemCount: reversedHierarchy.length,
itemBuilder: (context, index) {
final node = reversedHierarchy[index];
return Container(
margin: EdgeInsets.fromLTRB(20, 5, 20, 5),
decoration: BoxDecoration(
color: Colors.white, // white background
border: Border.all(
color: Colors.black, width: 1), // thin black border
borderRadius: BorderRadius.circular(4), // small corner radius
),
child: ListTile(
title: Center(child: Text('${node.label}')),
subtitle:
Center(child: Text('${node.data.info.description}')),
),
);
},
),
Positioned(
bottom: 20,
left: 20,
right: 20,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8.0),
border: Border.all(color: Colors.green, width: 3),
),
child: ElevatedButton(
onPressed: viewModel.isBenchmarkRunning
? null
: () {
// Call runBenchmark method from SkillTreeViewModel
viewModel.runBenchmark();
},
child: Row(
mainAxisAlignment:
MainAxisAlignment.center, // Center the children
children: [
Text(
'Initiate test suite',
style: TextStyle(
color: Colors.green, // Text color is set to green
fontWeight: FontWeight.bold, // Make text bold
fontSize: 16, // Increase font size
),
),
SizedBox(width: 10), // Gap of 10 between text and icon
Icon(
Icons.play_arrow,
color: Colors.green, // Icon color is set to green
size: 24, // Increase icon size
),
],
),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.white),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
),
minimumSize: MaterialStateProperty.all(
Size(double.infinity, 50)), // Full width
padding: MaterialStateProperty.all(EdgeInsets.all(0)),
),
),
),
),
],
),
);
}
}