mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 02:39:19 +08:00
104 lines
2.7 KiB
Dart
104 lines
2.7 KiB
Dart
import 'package:apidash/apitoolgen/tool_templates.dart';
|
|
import 'package:apidash/services/agentic_services/agent_caller.dart';
|
|
import 'package:apidash/services/agentic_services/agents/agents.dart';
|
|
import 'package:apidash_core/apidash_core.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
Future<String?> generateSDUICodeFromResponse({
|
|
required WidgetRef ref,
|
|
required String apiResponse,
|
|
}) async {
|
|
final step1Res = await Future.wait([
|
|
APIDashAgentCaller.instance.call(
|
|
ResponseSemanticAnalyser(),
|
|
ref: ref,
|
|
input: AgentInputs(query: apiResponse),
|
|
),
|
|
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) {
|
|
return null;
|
|
}
|
|
|
|
print("Semantic Analysis: $SA");
|
|
print("Intermediate Representation: $IR");
|
|
|
|
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) {
|
|
return null;
|
|
}
|
|
|
|
return sduiCode['STAC'].toString();
|
|
}
|
|
|
|
Future<String?> modifySDUICodeUsingPrompt({
|
|
required WidgetRef ref,
|
|
required String generatedSDUI,
|
|
required String modificationRequest,
|
|
}) async {
|
|
final res = await APIDashAgentCaller.instance.call(
|
|
StacModifierBot(),
|
|
ref: ref,
|
|
input: AgentInputs(variables: {
|
|
'VAR_CODE': generatedSDUI,
|
|
'VAR_CLIENT_REQUEST': modificationRequest,
|
|
}),
|
|
);
|
|
final SDUI = res?['STAC'];
|
|
return SDUI;
|
|
}
|
|
|
|
Future<String?> generateAPIToolUsingRequestData({
|
|
required WidgetRef ref,
|
|
required String requestData,
|
|
required String targetLanguage,
|
|
required String selectedAgent,
|
|
}) async {
|
|
final toolfuncRes = await APIDashAgentCaller.instance.call(
|
|
APIToolFunctionGenerator(),
|
|
ref: ref,
|
|
input: AgentInputs(variables: {
|
|
'REQDATA': requestData,
|
|
'TARGET_LANGUAGE': targetLanguage,
|
|
}),
|
|
);
|
|
if (toolfuncRes == null) {
|
|
return null;
|
|
}
|
|
|
|
String toolCode = toolfuncRes!['FUNC'];
|
|
|
|
final toolres = await APIDashAgentCaller.instance.call(
|
|
ApiToolBodyGen(),
|
|
ref: ref,
|
|
input: AgentInputs(variables: {
|
|
'TEMPLATE':
|
|
APIToolGenTemplateSelector.getTemplate(targetLanguage, selectedAgent)
|
|
.substitutePromptVariable('FUNC', toolCode),
|
|
}),
|
|
);
|
|
if (toolres == null) {
|
|
return null;
|
|
}
|
|
String toolDefinition = toolres!['TOOL'];
|
|
return toolDefinition;
|
|
}
|