mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-19 06:54:22 +01:00
Enhanced Test Execution Flexibility (#5521)
Refactor UI and Logic for Task Queue and Test Suite Button
This commit is contained in:
@@ -18,6 +18,7 @@ import 'package:flutter/foundation.dart';
|
|||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:graphview/GraphView.dart';
|
import 'package:graphview/GraphView.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
|
import 'package:auto_gpt_flutter_client/utils/stack.dart';
|
||||||
|
|
||||||
class SkillTreeViewModel extends ChangeNotifier {
|
class SkillTreeViewModel extends ChangeNotifier {
|
||||||
// TODO: Potentially move to task queue view model when we create one
|
// TODO: Potentially move to task queue view model when we create one
|
||||||
@@ -38,6 +39,9 @@ class SkillTreeViewModel extends ChangeNotifier {
|
|||||||
// TODO: Potentially move to task queue view model when we create one
|
// TODO: Potentially move to task queue view model when we create one
|
||||||
List<SkillTreeNode>? _selectedNodeHierarchy;
|
List<SkillTreeNode>? _selectedNodeHierarchy;
|
||||||
|
|
||||||
|
String _selectedOption = 'Run single test';
|
||||||
|
String get selectedOption => _selectedOption;
|
||||||
|
|
||||||
List<SkillTreeNode> get skillTreeNodes => _skillTreeNodes;
|
List<SkillTreeNode> get skillTreeNodes => _skillTreeNodes;
|
||||||
List<SkillTreeEdge> get skillTreeEdges => _skillTreeEdges;
|
List<SkillTreeEdge> get skillTreeEdges => _skillTreeEdges;
|
||||||
SkillTreeNode? get selectedNode => _selectedNode;
|
SkillTreeNode? get selectedNode => _selectedNode;
|
||||||
@@ -101,11 +105,95 @@ class SkillTreeViewModel extends ChangeNotifier {
|
|||||||
} else {
|
} else {
|
||||||
// Select the new node
|
// Select the new node
|
||||||
_selectedNode = _skillTreeNodes.firstWhere((node) => node.id == nodeId);
|
_selectedNode = _skillTreeNodes.firstWhere((node) => node.id == nodeId);
|
||||||
populateSelectedNodeHierarchy(nodeId);
|
updateSelectedNodeHierarchyBasedOnOption(_selectedOption);
|
||||||
}
|
}
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateSelectedNodeHierarchyBasedOnOption(String selectedOption) {
|
||||||
|
_selectedOption = selectedOption;
|
||||||
|
switch (selectedOption) {
|
||||||
|
// TODO: Turn this into enum
|
||||||
|
case 'Run single test':
|
||||||
|
_selectedNodeHierarchy = _selectedNode != null ? [_selectedNode!] : [];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'Run test suite including selected node and ancestors':
|
||||||
|
if (_selectedNode != null) {
|
||||||
|
populateSelectedNodeHierarchy(_selectedNode!.id);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'Run all tests in category':
|
||||||
|
if (_selectedNode != null) {
|
||||||
|
_getAllNodesInDepthFirstOrderEnsuringParents();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _getAllNodesInDepthFirstOrderEnsuringParents() {
|
||||||
|
var nodes = <SkillTreeNode>[];
|
||||||
|
var stack = Stack<SkillTreeNode>();
|
||||||
|
var visited = <String>{};
|
||||||
|
|
||||||
|
// Identify the root node by its label
|
||||||
|
var root = _skillTreeNodes.firstWhere((node) => node.label == "WriteFile");
|
||||||
|
|
||||||
|
stack.push(root);
|
||||||
|
visited.add(root.id);
|
||||||
|
|
||||||
|
while (stack.isNotEmpty) {
|
||||||
|
var node = stack.peek(); // Peek the top node, but do not remove it yet
|
||||||
|
var parents = _getParentsOfNodeUsingEdges(node.id);
|
||||||
|
|
||||||
|
// Check if all parents are visited
|
||||||
|
if (parents.every((parent) => visited.contains(parent.id))) {
|
||||||
|
nodes.add(node);
|
||||||
|
stack.pop(); // Remove the node only when all its parents are visited
|
||||||
|
|
||||||
|
// Get the children of the current node using edges
|
||||||
|
var children = _getChildrenOfNodeUsingEdges(node.id)
|
||||||
|
.where((child) => !visited.contains(child.id));
|
||||||
|
|
||||||
|
children.forEach((child) {
|
||||||
|
visited.add(child.id);
|
||||||
|
stack.push(child);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
stack
|
||||||
|
.pop(); // Remove the node if not all parents are visited, it will be re-added when its parents are visited
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_selectedNodeHierarchy = nodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<SkillTreeNode> _getParentsOfNodeUsingEdges(String nodeId) {
|
||||||
|
var parents = <SkillTreeNode>[];
|
||||||
|
|
||||||
|
for (var edge in _skillTreeEdges) {
|
||||||
|
if (edge.to == nodeId) {
|
||||||
|
parents.add(_skillTreeNodes.firstWhere((node) => node.id == edge.from));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return parents;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<SkillTreeNode> _getChildrenOfNodeUsingEdges(String nodeId) {
|
||||||
|
var children = <SkillTreeNode>[];
|
||||||
|
|
||||||
|
for (var edge in _skillTreeEdges) {
|
||||||
|
if (edge.from == nodeId) {
|
||||||
|
children.add(_skillTreeNodes.firstWhere((node) => node.id == edge.to));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Do we want to continue testing other branches of tree if one branch side fails benchmarking?
|
// TODO: Do we want to continue testing other branches of tree if one branch side fails benchmarking?
|
||||||
void populateSelectedNodeHierarchy(String startNodeId) {
|
void populateSelectedNodeHierarchy(String startNodeId) {
|
||||||
// Initialize an empty list to hold the nodes in all hierarchies.
|
// Initialize an empty list to hold the nodes in all hierarchies.
|
||||||
|
|||||||
@@ -97,18 +97,22 @@ class TaskQueueView extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
// TestSuiteButton
|
// TestSuiteButton
|
||||||
TestSuiteButton(
|
TestSuiteButton(
|
||||||
onPressed: viewModel.isBenchmarkRunning
|
isDisabled: viewModel.isBenchmarkRunning,
|
||||||
? null
|
selectedOption: viewModel.selectedOption,
|
||||||
: () {
|
onOptionSelected: (selectedOption) {
|
||||||
final chatViewModel = Provider.of<ChatViewModel>(
|
print('Option Selected: $selectedOption');
|
||||||
context,
|
viewModel.updateSelectedNodeHierarchyBasedOnOption(
|
||||||
listen: false);
|
selectedOption);
|
||||||
final taskViewModel = Provider.of<TaskViewModel>(
|
},
|
||||||
context,
|
onPlayPressed: (selectedOption) {
|
||||||
listen: false);
|
print('Starting benchmark with option: $selectedOption');
|
||||||
chatViewModel.clearCurrentTaskAndChats();
|
final chatViewModel =
|
||||||
viewModel.runBenchmark(chatViewModel, taskViewModel);
|
Provider.of<ChatViewModel>(context, listen: false);
|
||||||
},
|
final taskViewModel =
|
||||||
|
Provider.of<TaskViewModel>(context, listen: false);
|
||||||
|
chatViewModel.clearCurrentTaskAndChats();
|
||||||
|
viewModel.runBenchmark(chatViewModel, taskViewModel);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
SizedBox(height: 8), // Gap of 8 points between buttons
|
SizedBox(height: 8), // Gap of 8 points between buttons
|
||||||
// LeaderboardSubmissionButton
|
// LeaderboardSubmissionButton
|
||||||
|
|||||||
@@ -1,47 +1,115 @@
|
|||||||
import 'package:auto_gpt_flutter_client/constants/app_colors.dart';
|
import 'package:auto_gpt_flutter_client/constants/app_colors.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class TestSuiteButton extends StatelessWidget {
|
class TestSuiteButton extends StatefulWidget {
|
||||||
final VoidCallback? onPressed;
|
|
||||||
final bool isDisabled;
|
final bool isDisabled;
|
||||||
|
final Function(String) onOptionSelected;
|
||||||
|
final Function(String) onPlayPressed;
|
||||||
|
String selectedOption;
|
||||||
|
|
||||||
TestSuiteButton({required this.onPressed, this.isDisabled = false});
|
TestSuiteButton({
|
||||||
|
this.isDisabled = false,
|
||||||
|
required this.onOptionSelected,
|
||||||
|
required this.onPlayPressed,
|
||||||
|
required this.selectedOption,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_TestSuiteButtonState createState() => _TestSuiteButtonState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TestSuiteButtonState extends State<TestSuiteButton> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SizedBox(
|
return Row(
|
||||||
height: 50,
|
children: [
|
||||||
child: ElevatedButton(
|
// Dropdown button with test options
|
||||||
style: ElevatedButton.styleFrom(
|
Expanded(
|
||||||
backgroundColor: isDisabled ? Colors.grey : AppColors.primaryLight,
|
// Added Expanded to make sure it takes the available space
|
||||||
shape: RoundedRectangleBorder(
|
child: PopupMenuButton<String>(
|
||||||
borderRadius: BorderRadius.circular(8.0),
|
enabled: !widget.isDisabled,
|
||||||
),
|
onSelected: (value) {
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
setState(() {
|
||||||
elevation: 5.0,
|
widget.selectedOption = value;
|
||||||
),
|
});
|
||||||
onPressed: isDisabled ? null : onPressed,
|
widget.onOptionSelected(widget.selectedOption);
|
||||||
child: const Row(
|
},
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
itemBuilder: (BuildContext context) {
|
||||||
children: [
|
return [
|
||||||
Text(
|
const PopupMenuItem(
|
||||||
'Initiate test suite',
|
value: 'Run single test',
|
||||||
style: TextStyle(
|
child: Text('Run single test'),
|
||||||
color: Colors.white,
|
),
|
||||||
fontSize: 12.50,
|
const PopupMenuItem(
|
||||||
fontFamily: 'Archivo',
|
value: 'Run test suite including selected node and ancestors',
|
||||||
fontWeight: FontWeight.w400,
|
child: Text(
|
||||||
|
'Run test suite including selected node and ancestors'),
|
||||||
|
),
|
||||||
|
const PopupMenuItem(
|
||||||
|
value: 'Run all tests in category',
|
||||||
|
child: Text('Run all tests in category'),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
height: 50,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: widget.isDisabled ? Colors.grey : AppColors.primaryLight,
|
||||||
|
borderRadius: BorderRadius.circular(8.0),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Flexible(
|
||||||
|
child: Text(
|
||||||
|
widget.selectedOption,
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 12.50,
|
||||||
|
fontFamily: 'Archivo',
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
maxLines: 2,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Icon(
|
||||||
|
Icons.arrow_drop_down,
|
||||||
|
color: Colors.white,
|
||||||
|
)
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(width: 10),
|
),
|
||||||
Icon(
|
),
|
||||||
|
// Play button
|
||||||
|
const SizedBox(width: 10),
|
||||||
|
SizedBox(
|
||||||
|
height: 50,
|
||||||
|
child: ElevatedButton(
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor:
|
||||||
|
widget.isDisabled ? Colors.grey : AppColors.primaryLight,
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8.0),
|
||||||
|
),
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
|
elevation: 5.0,
|
||||||
|
),
|
||||||
|
onPressed: widget.isDisabled
|
||||||
|
? null
|
||||||
|
: () {
|
||||||
|
widget.onPlayPressed(widget.selectedOption);
|
||||||
|
},
|
||||||
|
child: const Icon(
|
||||||
Icons.play_arrow,
|
Icons.play_arrow,
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
size: 24,
|
size: 24,
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user