mirror of
https://github.com/foss42/apidash.git
synced 2025-07-04 15:28:20 +08:00
Feat: Added DebugApi
This commit is contained in:
@ -39,4 +39,35 @@ class OllamaService {
|
||||
''';
|
||||
return generateResponse(prompt);
|
||||
}
|
||||
|
||||
Future<String> debugApi({required dynamic requestModel, required dynamic responseModel}) async {
|
||||
if (requestModel == null || responseModel == null) {
|
||||
return "There are no recent API Requests to debug.";
|
||||
}
|
||||
|
||||
final requestJson = jsonEncode(requestModel.toJson());
|
||||
final responseJson = jsonEncode(responseModel.toJson());
|
||||
final statusCode = responseModel.statusCode;
|
||||
|
||||
final prompt = '''
|
||||
Provide detailed debugging steps for this failed API request:
|
||||
|
||||
**Status Code:** $statusCode
|
||||
**Request Details:**
|
||||
$requestJson
|
||||
|
||||
**Response Details:**
|
||||
$responseJson
|
||||
|
||||
Provide a step-by-step debugging guide including:
|
||||
1. Common causes for this status code
|
||||
2. Specific issues in the request
|
||||
3. Potential fixes
|
||||
4. Recommended next steps
|
||||
|
||||
Format the response with clear headings and bullet points.
|
||||
''';
|
||||
|
||||
return generateResponse(prompt);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,11 @@ class _ChatbotWidgetState extends ConsumerState<ChatbotWidget> {
|
||||
requestModel: requestModel,
|
||||
responseModel: responseModel,
|
||||
);
|
||||
} else if (message == "Debug API") {
|
||||
response = await ollamaService.debugApi(
|
||||
requestModel: requestModel,
|
||||
responseModel: responseModel,
|
||||
);
|
||||
} else {
|
||||
response = await ollamaService.generateResponse(message);
|
||||
}
|
||||
@ -51,6 +56,10 @@ class _ChatbotWidgetState extends ConsumerState<ChatbotWidget> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final requestModel = ref.watch(selectedRequestModelProvider);
|
||||
final statusCode = requestModel?.httpResponseModel?.statusCode;
|
||||
final showDebugButton = statusCode != null && statusCode >= 400;
|
||||
|
||||
return Container(
|
||||
height: 400,
|
||||
padding: const EdgeInsets.all(16),
|
||||
@ -70,6 +79,17 @@ class _ChatbotWidgetState extends ConsumerState<ChatbotWidget> {
|
||||
icon: const Icon(Icons.info_outline),
|
||||
label: const Text("Explain API"),
|
||||
),
|
||||
if (showDebugButton) ...[
|
||||
const SizedBox(width: 8),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () => _sendMessage("Debug API"),
|
||||
icon: const Icon(Icons.bug_report),
|
||||
label: const Text("Debug"),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.redAccent,
|
||||
),
|
||||
),
|
||||
],
|
||||
const Spacer(),
|
||||
],
|
||||
),
|
||||
|
Reference in New Issue
Block a user