mirror of
https://github.com/foss42/apidash.git
synced 2025-12-01 10:17:47 +08:00
feat: add generate documentation functionality
This commit is contained in:
@@ -234,6 +234,66 @@ OUTPUT FORMAT (STRICT)
|
||||
REFUSAL TEMPLATE (when off-topic), JSON only:
|
||||
{"explnation":"I am Dashbot, an AI assistant focused specifically on API development tasks within API Dash. My capabilities are limited to explaining API responses, debugging requests, generating documentation, creating tests, visualizing API data, and generating integration code. Therefore, I cannot answer questions outside of this scope. How can I assist you with an API-related task?","action":null}
|
||||
|
||||
RETURN THE JSON ONLY.
|
||||
</system_prompt>
|
||||
""";
|
||||
}
|
||||
|
||||
String generateDocumentationPrompt({
|
||||
String? url,
|
||||
String? method,
|
||||
int? responseStatus,
|
||||
String? bodyContentType,
|
||||
String? message,
|
||||
Map<String, String>? headersMap,
|
||||
String? body,
|
||||
}) {
|
||||
return """
|
||||
<system_prompt>
|
||||
YOU ARE Dashbot, a specialized API Documentation Generator for API Dash.
|
||||
|
||||
STRICT OFF-TOPIC POLICY
|
||||
- If a request is unrelated to API tasks, refuse. Do not answer off-topic questions.
|
||||
- Refusal MUST still return JSON with only the "explnation" field and "action": null.
|
||||
|
||||
CONTEXT
|
||||
- API URL: ${url ?? 'N/A'}
|
||||
- HTTP Method: ${method ?? 'N/A'}
|
||||
- Status Code: ${responseStatus ?? 'N/A'}
|
||||
- Request Content Type: ${bodyContentType ?? 'N/A'}
|
||||
- Request Headers: ${headersMap?.toString() ?? 'No request headers provided'}
|
||||
- Request Body: ${body ?? 'No request body provided'}
|
||||
- Response Body: ${message ?? 'No response body provided'}
|
||||
|
||||
TASK
|
||||
- Generate comprehensive API documentation in Markdown format.
|
||||
- Structure must include:
|
||||
1. Relevant title and description
|
||||
2. Detailed request information (method, URL, headers, parameters)
|
||||
3. Response details and status codes
|
||||
4. Explanation of all body parameters and their types
|
||||
5. Example response with proper formatting
|
||||
6. Summary section with key takeaways
|
||||
|
||||
OUTPUT FORMAT (STRICT)
|
||||
- Return ONLY a single JSON object. No markdown wrapper, no extra text.
|
||||
- The JSON MUST contain both keys:
|
||||
{
|
||||
"explnation": string, // the COMPLETE Markdown documentation as a single string
|
||||
"action": null
|
||||
}
|
||||
|
||||
MARKDOWN FORMATTING REQUIREMENTS
|
||||
- Use proper headers (# ## ###)
|
||||
- Use code blocks with language specification
|
||||
- Use tables for parameter descriptions
|
||||
- Use bullet points for lists
|
||||
- Format JSON examples with proper indentation
|
||||
- Include relevant badges or status indicators
|
||||
|
||||
REFUSAL TEMPLATE (when off-topic), JSON only:
|
||||
{"explnation":"I am Dashbot, an AI assistant focused specifically on API development tasks within API Dash. My capabilities are limited to explaining API responses, debugging requests, generating documentation, creating tests, visualizing API data, and generating integration code. Therefore, I cannot answer questions outside of this scope. How can I assist you with an API-related task?","action":null}
|
||||
|
||||
RETURN THE JSON ONLY.
|
||||
</system_prompt>
|
||||
""";
|
||||
|
||||
@@ -84,7 +84,13 @@ class ChatResponse {
|
||||
}
|
||||
}
|
||||
|
||||
enum ChatMessageType { explainResponse, debugError, generateTest, general }
|
||||
enum ChatMessageType {
|
||||
explainResponse,
|
||||
debugError,
|
||||
generateTest,
|
||||
generateDoc,
|
||||
general
|
||||
}
|
||||
|
||||
// Action model for auto-fix functionality
|
||||
class ChatAction {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'package:apidash/providers/collection_providers.dart';
|
||||
|
||||
import '../../models/chat_models.dart';
|
||||
import '../widgets/chat_bubble.dart';
|
||||
import '../../viewmodel/chat_viewmodel.dart';
|
||||
@@ -34,14 +32,14 @@ class _ChatScreenState extends ConsumerState<ChatScreen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
ref.listen(
|
||||
selectedRequestModelProvider,
|
||||
(current, next) {
|
||||
if (current?.id != next?.id) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
);
|
||||
// ref.listen(
|
||||
// selectedRequestModelProvider,
|
||||
// (current, next) {
|
||||
// if (current?.id != next?.id) {
|
||||
// Navigator.pop(context);
|
||||
// }
|
||||
// },
|
||||
// );
|
||||
return Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
|
||||
@@ -444,6 +444,16 @@ class ChatViewmodel extends StateNotifier<ChatState> {
|
||||
headersMap: http?.headersMap,
|
||||
body: http?.body,
|
||||
);
|
||||
case ChatMessageType.generateDoc:
|
||||
return prompts.generateDocumentationPrompt(
|
||||
url: http?.url,
|
||||
method: http?.method.name.toUpperCase(),
|
||||
responseStatus: req.responseStatus,
|
||||
bodyContentType: http?.bodyContentType.name,
|
||||
message: resp?.body,
|
||||
headersMap: http?.headersMap,
|
||||
body: http?.body,
|
||||
);
|
||||
case ChatMessageType.general:
|
||||
return prompts.generalInteractionPrompt();
|
||||
}
|
||||
|
||||
@@ -23,14 +23,14 @@ class _DashbotHomePageState extends ConsumerState<DashbotHomePage> {
|
||||
Widget build(BuildContext context) {
|
||||
final currentRequest = ref.watch(selectedRequestModelProvider);
|
||||
|
||||
ref.listen(
|
||||
selectedRequestModelProvider,
|
||||
(current, next) {
|
||||
if (current?.id != next?.id) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
);
|
||||
// ref.listen(
|
||||
// selectedRequestModelProvider,
|
||||
// (current, next) {
|
||||
// if (current?.id != next?.id) {
|
||||
// Navigator.pop(context);
|
||||
// }
|
||||
// },
|
||||
// );
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
@@ -80,7 +80,7 @@ class _DashbotHomePageState extends ConsumerState<DashbotHomePage> {
|
||||
onPressed: () {
|
||||
Navigator.of(context).pushNamed(
|
||||
DashbotRoutes.dashbotChat,
|
||||
arguments: ChatMessageType.general,
|
||||
arguments: ChatMessageType.generateDoc,
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user