mirror of
https://github.com/foss42/apidash.git
synced 2025-12-01 18:28:25 +08:00
AI UI-Designer & ToolGenerator: Added ErrorHandling
This commit is contained in:
@@ -224,7 +224,7 @@ circleAvatar has a field backgroundImage which takes the image url directly. no
|
|||||||
|
|
||||||
DO NOT START OR END THE RESPONSE WITH ANYTHING ELSE. I WANT PURE FLutter-SDUI OUTPUT
|
DO NOT START OR END THE RESPONSE WITH ANYTHING ELSE. I WANT PURE FLutter-SDUI OUTPUT
|
||||||
|
|
||||||
Generally wrap the whole thing with a SingleChildScrollView so that the whole thing is scrollable
|
Generally wrap the whole thing with a SingleChildScrollView so that the whole thing is scrollable and wrap the SingleChildScrollView with a container so that colors and stuff can be changed
|
||||||
|
|
||||||
""";
|
""";
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class _GenerateToolDialogState extends ConsumerState<GenerateToolDialog> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
generatedToolCode = null;
|
generatedToolCode = null;
|
||||||
});
|
});
|
||||||
final x = await APIDashAgentCaller.instance.call(
|
final toolfuncRes = await APIDashAgentCaller.instance.call(
|
||||||
APIToolFunctionGenerator(),
|
APIToolFunctionGenerator(),
|
||||||
ref: ref,
|
ref: ref,
|
||||||
input: AgentInputs(variables: {
|
input: AgentInputs(variables: {
|
||||||
@@ -45,19 +45,22 @@ class _GenerateToolDialogState extends ConsumerState<GenerateToolDialog> {
|
|||||||
'TARGET_LANGUAGE': selectedLanguage,
|
'TARGET_LANGUAGE': selectedLanguage,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
if (x == null) {
|
if (toolfuncRes == null) {
|
||||||
setState(() {
|
setState(() {
|
||||||
generatedToolCode = '';
|
generatedToolCode = '';
|
||||||
});
|
});
|
||||||
print("ToolGeneration Failed"); //TODO: Make Alert
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
|
content: Text(
|
||||||
|
"API Tool generation failed!",
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
backgroundColor: Colors.redAccent,
|
||||||
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String toolCode = x!['FUNC'];
|
String toolCode = toolfuncRes!['FUNC'];
|
||||||
|
|
||||||
print(toolCode);
|
|
||||||
|
|
||||||
//TODO: Integrate into tool
|
|
||||||
final toolres = await APIDashAgentCaller.instance.call(
|
final toolres = await APIDashAgentCaller.instance.call(
|
||||||
ApiToolBodyGen(),
|
ApiToolBodyGen(),
|
||||||
ref: ref,
|
ref: ref,
|
||||||
@@ -71,7 +74,13 @@ class _GenerateToolDialogState extends ConsumerState<GenerateToolDialog> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
generatedToolCode = '';
|
generatedToolCode = '';
|
||||||
});
|
});
|
||||||
print("ToolGeneration Failed"); //TODO: Make Alert
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
|
content: Text(
|
||||||
|
"API Tool generation failed!",
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
backgroundColor: Colors.redAccent,
|
||||||
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String toolDefinition = toolres!['TOOL'];
|
String toolDefinition = toolres!['TOOL'];
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class _GenerateUIDialogState extends ConsumerState<GenerateUIDialog> {
|
|||||||
|
|
||||||
String generatedSDUI = '{}';
|
String generatedSDUI = '{}';
|
||||||
|
|
||||||
Future<String> generateSDUICode(String apiResponse) async {
|
Future<String?> generateSDUICode(String apiResponse) async {
|
||||||
setState(() {
|
setState(() {
|
||||||
index = 1; //Induce Loading
|
index = 1; //Induce Loading
|
||||||
});
|
});
|
||||||
@@ -61,9 +61,23 @@ class _GenerateUIDialogState extends ConsumerState<GenerateUIDialog> {
|
|||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
final SA = step1Res[0]?['SEMANTIC_ANALYSIS'];
|
final SA = step1Res[0]?['SEMANTIC_ANALYSIS'];
|
||||||
final IR = step1Res[1]?['INTERMEDIATE_REPRESENTATION'];
|
final IR = step1Res[1]?['INTERMEDIATE_REPRESENTATION'];
|
||||||
|
|
||||||
|
if (SA == null || IR == null) {
|
||||||
|
setState(() {
|
||||||
|
index = 0;
|
||||||
|
});
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
|
content: Text(
|
||||||
|
"Preview Generation Failed!",
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
backgroundColor: Colors.redAccent,
|
||||||
|
));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
print("Semantic Analysis: $SA");
|
print("Semantic Analysis: $SA");
|
||||||
print("Intermediate Representation: $IR");
|
print("Intermediate Representation: $IR");
|
||||||
|
|
||||||
@@ -78,7 +92,21 @@ class _GenerateUIDialogState extends ConsumerState<GenerateUIDialog> {
|
|||||||
'VAR_SEMANTIC_ANALYSIS': SA,
|
'VAR_SEMANTIC_ANALYSIS': SA,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
return sduiCode?['STAC']?.toString() ?? "<NONE>";
|
final stacCode = sduiCode?['STAC']?.toString();
|
||||||
|
if (stacCode == null) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
|
content: Text(
|
||||||
|
"Preview Generation Failed!",
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
backgroundColor: Colors.redAccent,
|
||||||
|
));
|
||||||
|
setState(() {
|
||||||
|
index = 0;
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return sduiCode['STAC'].toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> modifySDUICode(String modificationRequest) async {
|
Future<void> modifySDUICode(String modificationRequest) async {
|
||||||
@@ -95,7 +123,21 @@ class _GenerateUIDialogState extends ConsumerState<GenerateUIDialog> {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
final SDUI = res['STAC'];
|
final SDUI = res?['STAC'];
|
||||||
|
|
||||||
|
if (SDUI == null) {
|
||||||
|
setState(() {
|
||||||
|
index = 2;
|
||||||
|
});
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
|
content: Text(
|
||||||
|
"Modification Request Failed!",
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
backgroundColor: Colors.redAccent,
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
}
|
||||||
setState(() {
|
setState(() {
|
||||||
generatedSDUI = SDUI;
|
generatedSDUI = SDUI;
|
||||||
index = 2;
|
index = 2;
|
||||||
@@ -112,6 +154,7 @@ class _GenerateUIDialogState extends ConsumerState<GenerateUIDialog> {
|
|||||||
onNext: (apiResponse, targetLanguage) async {
|
onNext: (apiResponse, targetLanguage) async {
|
||||||
print("Generating SDUI Code");
|
print("Generating SDUI Code");
|
||||||
final sdui = await generateSDUICode(apiResponse);
|
final sdui = await generateSDUICode(apiResponse);
|
||||||
|
if (sdui == null) return;
|
||||||
setState(() {
|
setState(() {
|
||||||
index = 2;
|
index = 2;
|
||||||
generatedSDUI = sdui;
|
generatedSDUI = sdui;
|
||||||
@@ -276,6 +319,42 @@ class _SDUIPreviewPageState extends ConsumerState<SDUIPreviewPage> {
|
|||||||
bool exportingCode = false;
|
bool exportingCode = false;
|
||||||
String modificationRequest = "";
|
String modificationRequest = "";
|
||||||
|
|
||||||
|
exportCode() async {
|
||||||
|
setState(() {
|
||||||
|
exportingCode = true;
|
||||||
|
});
|
||||||
|
final ans = await APIDashAgentCaller.instance.call(
|
||||||
|
StacToFlutterBot(),
|
||||||
|
ref: ref,
|
||||||
|
input: AgentInputs(
|
||||||
|
variables: {'VAR_CODE': widget.sduiCode},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final exportedCode = ans?['CODE'];
|
||||||
|
|
||||||
|
if (exportedCode == null) {
|
||||||
|
setState(() {
|
||||||
|
exportingCode = false;
|
||||||
|
});
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
|
content: Text(
|
||||||
|
"Export Failed",
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
backgroundColor: Colors.redAccent,
|
||||||
|
));
|
||||||
|
print("exportCode: Failed; ABORTING");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Clipboard.setData(ClipboardData(text: ans['CODE']));
|
||||||
|
ScaffoldMessenger.of(context)
|
||||||
|
.showSnackBar(SnackBar(content: Text("Copied to clipboard!")));
|
||||||
|
setState(() {
|
||||||
|
exportingCode = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
@@ -354,24 +433,7 @@ class _SDUIPreviewPageState extends ConsumerState<SDUIPreviewPage> {
|
|||||||
padding: kPh12,
|
padding: kPh12,
|
||||||
minimumSize: const Size(44, 44),
|
minimumSize: const Size(44, 44),
|
||||||
),
|
),
|
||||||
onPressed: () async {
|
onPressed: exportCode,
|
||||||
setState(() {
|
|
||||||
exportingCode = true;
|
|
||||||
});
|
|
||||||
final ans = await APIDashAgentCaller.instance.call(
|
|
||||||
StacToFlutterBot(),
|
|
||||||
ref: ref,
|
|
||||||
input: AgentInputs(
|
|
||||||
variables: {'VAR_CODE': widget.sduiCode}),
|
|
||||||
);
|
|
||||||
final exportedCode = ans['CODE'];
|
|
||||||
Clipboard.setData(ClipboardData(text: ans['CODE']));
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(content: Text("Copied to clipboard!")));
|
|
||||||
setState(() {
|
|
||||||
exportingCode = false;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
Icons.download,
|
Icons.download,
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user