Spaces:
Build error
Build error
File size: 5,315 Bytes
3382f47 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
import 'package:auto_gpt_flutter_client/models/benchmark/benchmark_task_status.dart';
import 'package:auto_gpt_flutter_client/models/test_option.dart';
import 'package:auto_gpt_flutter_client/viewmodels/chat_viewmodel.dart';
import 'package:auto_gpt_flutter_client/viewmodels/skill_tree_viewmodel.dart';
import 'package:auto_gpt_flutter_client/viewmodels/task_queue_viewmodel.dart';
import 'package:auto_gpt_flutter_client/viewmodels/task_viewmodel.dart';
import 'package:auto_gpt_flutter_client/views/task_queue/test_suite_button.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class TaskQueueView extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: This should be injected instead
final viewModel = Provider.of<TaskQueueViewModel>(context);
// Node hierarchy
final nodeHierarchy = viewModel.selectedNodeHierarchy ?? [];
return Material(
color: Colors.white,
child: Column(
children: [
// The list of tasks (tiles)
Expanded(
child: ListView.builder(
itemCount: nodeHierarchy.length,
itemBuilder: (context, index) {
final node = nodeHierarchy[index];
// Choose the appropriate leading widget based on the task status
Widget leadingWidget;
switch (viewModel.benchmarkStatusMap[node]) {
case null:
case BenchmarkTaskStatus.notStarted:
leadingWidget = CircleAvatar(
radius: 12,
backgroundColor: Colors.grey,
child: CircleAvatar(
radius: 6,
backgroundColor: Colors.white,
),
);
break;
case BenchmarkTaskStatus.inProgress:
leadingWidget = SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(
strokeWidth: 2,
),
);
break;
case BenchmarkTaskStatus.success:
leadingWidget = CircleAvatar(
radius: 12,
backgroundColor: Colors.green,
child: CircleAvatar(
radius: 6,
backgroundColor: Colors.white,
),
);
break;
case BenchmarkTaskStatus.failure:
leadingWidget = CircleAvatar(
radius: 12,
backgroundColor: Colors.red,
child: CircleAvatar(
radius: 6,
backgroundColor: Colors.white,
),
);
break;
}
return Container(
margin: EdgeInsets.fromLTRB(20, 5, 20, 5),
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.black, width: 1),
borderRadius: BorderRadius.circular(4),
),
child: ListTile(
leading: leadingWidget,
title: Center(child: Text('${node.label}')),
subtitle:
Center(child: Text('${node.data.info.description}')),
),
);
},
),
),
// Buttons at the bottom
Padding(
padding: EdgeInsets.all(20),
child: Column(
children: [
// TestSuiteButton
TestSuiteButton(
isDisabled: viewModel.isBenchmarkRunning,
selectedOptionString: viewModel.selectedOption.description,
onOptionSelected: (selectedOption) {
print('Option Selected: $selectedOption');
final skillTreeViewModel =
Provider.of<SkillTreeViewModel>(context, listen: false);
viewModel.updateSelectedNodeHierarchyBasedOnOption(
TestOptionExtension.fromDescription(selectedOption)!,
skillTreeViewModel.selectedNode,
skillTreeViewModel.skillTreeNodes,
skillTreeViewModel.skillTreeEdges);
},
onPlayPressed: (selectedOption) {
print('Starting benchmark with option: $selectedOption');
final chatViewModel =
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
],
),
),
],
),
);
}
}
|