From ebe4bdba2d5001ba9fc5c7b040cbdf7832641e12 Mon Sep 17 00:00:00 2001 From: siddu015 <116783967+siddu015@users.noreply.github.com> Date: Wed, 5 Mar 2025 23:12:32 +0530 Subject: [PATCH] FEAT: Debug API prompt for clear analysis --- lib/dashbot/features/debug.dart | 49 ++++++++++++++--------- lib/dashbot/features/explain.dart | 43 ++++++++++---------- lib/dashbot/services/dashbot_service.dart | 3 +- 3 files changed, 55 insertions(+), 40 deletions(-) diff --git a/lib/dashbot/features/debug.dart b/lib/dashbot/features/debug.dart index 5f269299..8e0041d0 100644 --- a/lib/dashbot/features/debug.dart +++ b/lib/dashbot/features/debug.dart @@ -1,5 +1,6 @@ -import '../../models/request_model.dart'; +import 'dart:convert'; import '../services/dashbot_service.dart'; +import 'package:apidash/models/request_model.dart'; class DebugFeature { final DashBotService _service; @@ -10,35 +11,47 @@ class DebugFeature { required RequestModel? requestModel, required dynamic responseModel, }) async { - // Handle case where no request or response is available if (requestModel == null || responseModel == null) { return "No recent API requests found."; } - // Extract status code and error message from the response + final method = requestModel.httpRequestModel?.method.toString().split('.').last.toUpperCase() ?? "GET"; + final endpoint = requestModel.httpRequestModel?.url ?? "Unknown Endpoint"; + final headers = requestModel.httpRequestModel?.enabledHeadersMap ?? {}; + final parameters = requestModel.httpRequestModel?.enabledParamsMap ?? {}; + final body = requestModel.httpRequestModel?.body; + final rawResponse = responseModel.body; + final responseBody = rawResponse is String ? rawResponse : jsonEncode(rawResponse); final statusCode = responseModel.statusCode ?? 0; - final errorMessage = responseModel.body ?? "No error message available."; - // Create a prompt for the AI to analyze the request and response final prompt = ''' -Debug this API request based on the status code and error message: +URGENT API DEBUG ANALYSIS -**API Request:** -- Endpoint: `${requestModel.httpRequestModel?.url ?? "unknown"}` -- Method: `${requestModel.httpRequestModel?.method.toString().split('.').last.toUpperCase() ?? "GET"}` - -**API Response:** +**Request Overview:** +- Endpoint: $endpoint +- Method: $method - Status Code: $statusCode -- Error Message: $errorMessage -**Instructions:** -- Explain what the status code $statusCode typically means. -- Suggest possible reasons for the error based on the status code and error message. -- Provide actionable steps to resolve the issue. -- Use Markdown for formatting with headings and bullet points. +**Debugging Instructions:** +Provide a PRECISE, TEXT-ONLY explanation that: +1. Identifies the EXACT problem +2. Explains WHY the request failed +3. Describes SPECIFIC steps to resolve the issue +4. NO CODE SNIPPETS ALLOWED + +**Request Details:** +- Headers: ${headers.isNotEmpty ? jsonEncode(headers) : "No headers"} +- Parameters: ${parameters.isNotEmpty ? jsonEncode(parameters) : "No parameters"} +- Request Body: ${body ?? "Empty body"} + +**Response Context:** +\`\`\` +$responseBody +\`\`\` + +Provide a CLEAR, ACTIONABLE solution in the SIMPLEST possible language. '''; - // Use DashBotService to generate the AI response return _service.generateResponse(prompt); } } diff --git a/lib/dashbot/features/explain.dart b/lib/dashbot/features/explain.dart index c9e9b39a..e2bacbfa 100644 --- a/lib/dashbot/features/explain.dart +++ b/lib/dashbot/features/explain.dart @@ -29,31 +29,32 @@ class ExplainFeature { final statusCode = responseModel.statusCode ?? 0; final prompt = ''' -Analyze this API interaction and **identify discrepancies**: +FOCUSED API INTERACTION BREAKDOWN -**API Request:** -- Endpoint: `$endpoint` -- Method: `$method` -- Headers: ${headers.isNotEmpty ? jsonEncode(headers) : "None"} -- Parameters: ${parameters.isNotEmpty ? jsonEncode(parameters) : "None"} -- Body: ${body ?? "None"} +**Essential Request Details:** +- Endpoint Purpose: What is this API endpoint designed to do? +- Interaction Type: Describe the core purpose of this specific request -**API Response:** -- Status Code: $statusCode -- Body: -\`\`\`json -$responseBody -\`\`\` +**Request Mechanics:** +- Exact Endpoint: $endpoint +- HTTP Method: $method +- Key Parameters: ${parameters.isNotEmpty ? 'Specific inputs driving the request' : 'No custom parameters'} -**Instructions:** -1. Start with a **summary** of the API interaction. -2. List **validation issues** (e.g., missing headers, invalid parameters). -3. Highlight **request/response mismatches** (e.g., unexpected data types, missing fields). -4. Suggest **concrete improvements** (e.g., fix parameters, add error handling). +**Response CORE Insights:** +- Status: Success or Failure? +- Key Data Extracted: What CRITICAL information does the response contain? -**Format:** -- Use Markdown with headings (`##`, `###`). -- Include bullet points for clarity. +**Precise Analysis Requirements:** +1. Explain the API's PRIMARY function in ONE clear sentence +2. Identify the MOST IMPORTANT piece of information returned +3. Describe the PRACTICAL significance of this API call + +AVOID: +- Technical jargon +- Unnecessary details +- Verbose explanations + +Deliver a CRYSTAL CLEAR, CONCISE explanation that anyone can understand. '''; return _service.generateResponse(prompt); diff --git a/lib/dashbot/services/dashbot_service.dart b/lib/dashbot/services/dashbot_service.dart index f8151c4b..f9911afa 100644 --- a/lib/dashbot/services/dashbot_service.dart +++ b/lib/dashbot/services/dashbot_service.dart @@ -24,8 +24,9 @@ class DashBotService { if (input == "Explain API") { return _explainFeature.explainLatestApi(requestModel: requestModel, responseModel: responseModel); } else if(input == "Debug API") { - _debugFeature.debugApi(requestModel: requestModel, responseModel: responseModel); + return _debugFeature.debugApi(requestModel: requestModel, responseModel: responseModel); } + return generateResponse(input); } }