mirror of
https://github.com/foss42/apidash.git
synced 2025-12-03 03:17:00 +08:00
NO_DEFAULT_LLM Exception scenario addressed in UI
This commit is contained in:
@@ -80,60 +80,75 @@ class _GenerateToolDialogState extends ConsumerState<GenerateToolDialog> {
|
|||||||
String? generatedToolCode = '';
|
String? generatedToolCode = '';
|
||||||
|
|
||||||
generateAPITool() async {
|
generateAPITool() async {
|
||||||
setState(() {
|
try {
|
||||||
generatedToolCode = null;
|
|
||||||
});
|
|
||||||
final toolfuncRes = await APIDashAgentCaller.instance.call(
|
|
||||||
APIToolFunctionGenerator(),
|
|
||||||
ref: ref,
|
|
||||||
input: AgentInputs(variables: {
|
|
||||||
'REQDATA': widget.requestDesc.generateREQDATA,
|
|
||||||
'TARGET_LANGUAGE': selectedLanguage,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
if (toolfuncRes == null) {
|
|
||||||
setState(() {
|
setState(() {
|
||||||
generatedToolCode = '';
|
generatedToolCode = null;
|
||||||
});
|
});
|
||||||
|
final toolfuncRes = await APIDashAgentCaller.instance.call(
|
||||||
|
APIToolFunctionGenerator(),
|
||||||
|
ref: ref,
|
||||||
|
input: AgentInputs(variables: {
|
||||||
|
'REQDATA': widget.requestDesc.generateREQDATA,
|
||||||
|
'TARGET_LANGUAGE': selectedLanguage,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
if (toolfuncRes == null) {
|
||||||
|
setState(() {
|
||||||
|
generatedToolCode = '';
|
||||||
|
});
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
|
content: Text(
|
||||||
|
"API Tool generation failed!",
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
backgroundColor: Colors.redAccent,
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String toolCode = toolfuncRes!['FUNC'];
|
||||||
|
|
||||||
|
final toolres = await APIDashAgentCaller.instance.call(
|
||||||
|
ApiToolBodyGen(),
|
||||||
|
ref: ref,
|
||||||
|
input: AgentInputs(variables: {
|
||||||
|
'TEMPLATE': APIToolGenTemplateSelector.getTemplate(
|
||||||
|
selectedLanguage, selectedAgent)
|
||||||
|
.substitutePromptVariable('FUNC', toolCode),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
if (toolres == null) {
|
||||||
|
setState(() {
|
||||||
|
generatedToolCode = '';
|
||||||
|
});
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
|
content: Text(
|
||||||
|
"API Tool generation failed!",
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
backgroundColor: Colors.redAccent,
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String toolDefinition = toolres!['TOOL'];
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
generatedToolCode = toolDefinition;
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
String errMsg = 'Unexpected Error Occured';
|
||||||
|
if (e.toString().contains('NO_DEFAULT_LLM')) {
|
||||||
|
errMsg = "Please Select Default AI Model in Settings";
|
||||||
|
}
|
||||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
content: Text(
|
content: Text(
|
||||||
"API Tool generation failed!",
|
errMsg,
|
||||||
style: TextStyle(color: Colors.white),
|
style: TextStyle(color: Colors.white),
|
||||||
),
|
),
|
||||||
backgroundColor: Colors.redAccent,
|
backgroundColor: Colors.redAccent,
|
||||||
));
|
));
|
||||||
return;
|
Navigator.pop(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
String toolCode = toolfuncRes!['FUNC'];
|
|
||||||
|
|
||||||
final toolres = await APIDashAgentCaller.instance.call(
|
|
||||||
ApiToolBodyGen(),
|
|
||||||
ref: ref,
|
|
||||||
input: AgentInputs(variables: {
|
|
||||||
'TEMPLATE': APIToolGenTemplateSelector.getTemplate(
|
|
||||||
selectedLanguage, selectedAgent)
|
|
||||||
.substitutePromptVariable('FUNC', toolCode),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
if (toolres == null) {
|
|
||||||
setState(() {
|
|
||||||
generatedToolCode = '';
|
|
||||||
});
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
|
||||||
content: Text(
|
|
||||||
"API Tool generation failed!",
|
|
||||||
style: TextStyle(color: Colors.white),
|
|
||||||
),
|
|
||||||
backgroundColor: Colors.redAccent,
|
|
||||||
));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String toolDefinition = toolres!['TOOL'];
|
|
||||||
|
|
||||||
setState(() {
|
|
||||||
generatedToolCode = toolDefinition;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -42,70 +42,85 @@ class _GenerateUIDialogState extends ConsumerState<GenerateUIDialog> {
|
|||||||
String generatedSDUI = '{}';
|
String generatedSDUI = '{}';
|
||||||
|
|
||||||
Future<String?> generateSDUICode(String apiResponse) async {
|
Future<String?> generateSDUICode(String apiResponse) async {
|
||||||
setState(() {
|
try {
|
||||||
index = 1; //Induce Loading
|
setState(() {
|
||||||
});
|
index = 1; //Induce Loading
|
||||||
//STEP 1: RESPONSE_ANALYSER (call the Semantic Analysis & IRGen Bots in parallel)
|
});
|
||||||
final step1Res = await Future.wait([
|
//STEP 1: RESPONSE_ANALYSER (call the Semantic Analysis & IRGen Bots in parallel)
|
||||||
APIDashAgentCaller.instance.call(
|
final step1Res = await Future.wait([
|
||||||
ResponseSemanticAnalyser(),
|
APIDashAgentCaller.instance.call(
|
||||||
ref: ref,
|
ResponseSemanticAnalyser(),
|
||||||
input: AgentInputs(query: apiResponse),
|
ref: ref,
|
||||||
),
|
input: AgentInputs(query: apiResponse),
|
||||||
APIDashAgentCaller.instance.call(
|
),
|
||||||
IntermediateRepresentationGen(),
|
APIDashAgentCaller.instance.call(
|
||||||
|
IntermediateRepresentationGen(),
|
||||||
|
ref: ref,
|
||||||
|
input: AgentInputs(variables: {
|
||||||
|
'VAR_API_RESPONSE': apiResponse,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
final SA = step1Res[0]?['SEMANTIC_ANALYSIS'];
|
||||||
|
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("Intermediate Representation: $IR");
|
||||||
|
|
||||||
|
//STEP 2: STAC_GEN (Generate the SDUI Code)
|
||||||
|
|
||||||
|
final sduiCode = await APIDashAgentCaller.instance.call(
|
||||||
|
StacGenBot(),
|
||||||
ref: ref,
|
ref: ref,
|
||||||
input: AgentInputs(variables: {
|
input: AgentInputs(variables: {
|
||||||
'VAR_API_RESPONSE': apiResponse,
|
'VAR_RAW_API_RESPONSE': apiResponse,
|
||||||
|
'VAR_INTERMEDIATE_REPR': IR,
|
||||||
|
'VAR_SEMANTIC_ANALYSIS': SA,
|
||||||
}),
|
}),
|
||||||
),
|
);
|
||||||
]);
|
final stacCode = sduiCode?['STAC']?.toString();
|
||||||
final SA = step1Res[0]?['SEMANTIC_ANALYSIS'];
|
if (stacCode == null) {
|
||||||
final IR = step1Res[1]?['INTERMEDIATE_REPRESENTATION'];
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
|
content: Text(
|
||||||
if (SA == null || IR == null) {
|
"Preview Generation Failed!",
|
||||||
setState(() {
|
style: TextStyle(color: Colors.white),
|
||||||
index = 0;
|
),
|
||||||
});
|
backgroundColor: Colors.redAccent,
|
||||||
|
));
|
||||||
|
setState(() {
|
||||||
|
index = 0;
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return sduiCode['STAC'].toString();
|
||||||
|
} catch (e) {
|
||||||
|
String errMsg = 'Unexpected Error Occured';
|
||||||
|
if (e.toString().contains('NO_DEFAULT_LLM')) {
|
||||||
|
errMsg = "Please Select Default AI Model in Settings";
|
||||||
|
}
|
||||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
content: Text(
|
content: Text(
|
||||||
"Preview Generation Failed!",
|
errMsg,
|
||||||
style: TextStyle(color: Colors.white),
|
style: TextStyle(color: Colors.white),
|
||||||
),
|
),
|
||||||
backgroundColor: Colors.redAccent,
|
backgroundColor: Colors.redAccent,
|
||||||
));
|
));
|
||||||
return null;
|
Navigator.pop(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
print("Semantic Analysis: $SA");
|
|
||||||
print("Intermediate Representation: $IR");
|
|
||||||
|
|
||||||
//STEP 2: STAC_GEN (Generate the SDUI Code)
|
|
||||||
|
|
||||||
final sduiCode = await APIDashAgentCaller.instance.call(
|
|
||||||
StacGenBot(),
|
|
||||||
ref: ref,
|
|
||||||
input: AgentInputs(variables: {
|
|
||||||
'VAR_RAW_API_RESPONSE': apiResponse,
|
|
||||||
'VAR_INTERMEDIATE_REPR': IR,
|
|
||||||
'VAR_SEMANTIC_ANALYSIS': SA,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user