mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 10:49:49 +08:00
fix formatting and imports
This commit is contained in:
5
lib/dashbot/features/features.dart
Normal file
5
lib/dashbot/features/features.dart
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export 'debug.dart';
|
||||||
|
export 'documentation.dart';
|
||||||
|
export 'explain.dart';
|
||||||
|
export 'general_query.dart';
|
||||||
|
export 'test_generator.dart';
|
||||||
@@ -6,11 +6,17 @@ class GeneralQueryFeature {
|
|||||||
|
|
||||||
GeneralQueryFeature(this._client);
|
GeneralQueryFeature(this._client);
|
||||||
|
|
||||||
Future<String> generateResponse(String prompt, {RequestModel? requestModel, dynamic responseModel}) async {
|
Future<String> generateResponse(String prompt,
|
||||||
|
{RequestModel? requestModel, dynamic responseModel}) async {
|
||||||
String enhancedPrompt = prompt;
|
String enhancedPrompt = prompt;
|
||||||
|
|
||||||
if (requestModel != null && responseModel != null) {
|
if (requestModel != null && responseModel != null) {
|
||||||
final method = requestModel.httpRequestModel?.method.toString().split('.').last.toUpperCase() ?? "GET";
|
final method = requestModel.httpRequestModel?.method
|
||||||
|
.toString()
|
||||||
|
.split('.')
|
||||||
|
.last
|
||||||
|
.toUpperCase() ??
|
||||||
|
"GET";
|
||||||
final endpoint = requestModel.httpRequestModel?.url ?? "Unknown Endpoint";
|
final endpoint = requestModel.httpRequestModel?.url ?? "Unknown Endpoint";
|
||||||
final statusCode = responseModel.statusCode ?? 0;
|
final statusCode = responseModel.statusCode ?? 0;
|
||||||
|
|
||||||
@@ -37,7 +43,10 @@ Respond in a helpful, direct manner that specifically answers what was asked.
|
|||||||
}
|
}
|
||||||
|
|
||||||
final response = await _client.generateCompletion(
|
final response = await _client.generateCompletion(
|
||||||
request: GenerateCompletionRequest(model: 'llama3.2:3b', prompt: enhancedPrompt),
|
request: GenerateCompletionRequest(
|
||||||
|
model: 'llama3.2:3b',
|
||||||
|
prompt: enhancedPrompt,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
return response.response.toString();
|
return response.response.toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,9 +75,11 @@ Focus on creating realistic test values based on the API context (e.g., for a co
|
|||||||
|
|
||||||
parameters.forEach((key, value) {
|
parameters.forEach((key, value) {
|
||||||
if (RegExp(r'^[A-Z]{3}$').hasMatch(value)) {
|
if (RegExp(r'^[A-Z]{3}$').hasMatch(value)) {
|
||||||
analysis[key] = "Appears to be a 3-letter country code (ISO 3166-1 alpha-3)";
|
analysis[key] =
|
||||||
|
"Appears to be a 3-letter country code (ISO 3166-1 alpha-3)";
|
||||||
} else if (RegExp(r'^[A-Z]{2}$').hasMatch(value)) {
|
} else if (RegExp(r'^[A-Z]{2}$').hasMatch(value)) {
|
||||||
analysis[key] = "Appears to be a 2-letter country code (ISO 3166-1 alpha-2)";
|
analysis[key] =
|
||||||
|
"Appears to be a 2-letter country code (ISO 3166-1 alpha-2)";
|
||||||
} else if (RegExp(r'^\d+$').hasMatch(value)) {
|
} else if (RegExp(r'^\d+$').hasMatch(value)) {
|
||||||
analysis[key] = "Numeric value";
|
analysis[key] = "Numeric value";
|
||||||
} else if (RegExp(r'^[a-zA-Z]+$').hasMatch(value)) {
|
} else if (RegExp(r'^[a-zA-Z]+$').hasMatch(value)) {
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
import 'package:apidash/dashbot/features/debug.dart';
|
|
||||||
import 'package:apidash/dashbot/features/documentation.dart';
|
|
||||||
import 'package:ollama_dart/ollama_dart.dart';
|
import 'package:ollama_dart/ollama_dart.dart';
|
||||||
import 'package:apidash/dashbot/features/explain.dart';
|
|
||||||
import 'package:apidash/dashbot/features/test_generator.dart';
|
|
||||||
import 'package:apidash/models/request_model.dart';
|
import 'package:apidash/models/request_model.dart';
|
||||||
import 'package:apidash/dashbot/features/general_query.dart';
|
import '../features/features.dart';
|
||||||
|
|
||||||
class DashBotService {
|
class DashBotService {
|
||||||
final OllamaClient _client;
|
final OllamaClient _client;
|
||||||
@@ -16,7 +12,8 @@ class DashBotService {
|
|||||||
|
|
||||||
DashBotService()
|
DashBotService()
|
||||||
: _client = OllamaClient(baseUrl: 'http://127.0.0.1:11434/api'),
|
: _client = OllamaClient(baseUrl: 'http://127.0.0.1:11434/api'),
|
||||||
_generalQueryFeature = GeneralQueryFeature(OllamaClient(baseUrl: 'http://127.0.0.1:11434/api')) {
|
_generalQueryFeature = GeneralQueryFeature(
|
||||||
|
OllamaClient(baseUrl: 'http://127.0.0.1:11434/api')) {
|
||||||
_explainFeature = ExplainFeature(this);
|
_explainFeature = ExplainFeature(this);
|
||||||
_debugFeature = DebugFeature(this);
|
_debugFeature = DebugFeature(this);
|
||||||
_documentationFeature = DocumentationFeature(this);
|
_documentationFeature = DocumentationFeature(this);
|
||||||
@@ -28,21 +25,36 @@ class DashBotService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<String> handleRequest(
|
Future<String> handleRequest(
|
||||||
String input, RequestModel? requestModel, dynamic responseModel) async {
|
String input,
|
||||||
|
RequestModel? requestModel,
|
||||||
|
dynamic responseModel,
|
||||||
|
) async {
|
||||||
if (input == "Explain API") {
|
if (input == "Explain API") {
|
||||||
return _explainFeature.explainLatestApi(
|
return _explainFeature.explainLatestApi(
|
||||||
requestModel: requestModel, responseModel: responseModel);
|
requestModel: requestModel,
|
||||||
|
responseModel: responseModel,
|
||||||
|
);
|
||||||
} else if (input == "Debug API") {
|
} else if (input == "Debug API") {
|
||||||
return _debugFeature.debugApi(
|
return _debugFeature.debugApi(
|
||||||
requestModel: requestModel, responseModel: responseModel);
|
requestModel: requestModel,
|
||||||
|
responseModel: responseModel,
|
||||||
|
);
|
||||||
} else if (input == "Document API") {
|
} else if (input == "Document API") {
|
||||||
return _documentationFeature.generateApiDocumentation(
|
return _documentationFeature.generateApiDocumentation(
|
||||||
requestModel: requestModel, responseModel: responseModel);
|
requestModel: requestModel,
|
||||||
|
responseModel: responseModel,
|
||||||
|
);
|
||||||
} else if (input == "Test API") {
|
} else if (input == "Test API") {
|
||||||
return _testGeneratorFeature.generateApiTests(
|
return _testGeneratorFeature.generateApiTests(
|
||||||
requestModel: requestModel, responseModel: responseModel);
|
requestModel: requestModel,
|
||||||
|
responseModel: responseModel,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _generalQueryFeature.generateResponse(input, requestModel: requestModel, responseModel: responseModel);
|
return _generalQueryFeature.generateResponse(
|
||||||
|
input,
|
||||||
|
requestModel: requestModel,
|
||||||
|
responseModel: responseModel,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,11 @@ class ChatBubble extends StatelessWidget {
|
|||||||
final String message;
|
final String message;
|
||||||
final bool isUser;
|
final bool isUser;
|
||||||
|
|
||||||
const ChatBubble({super.key, required this.message, this.isUser = false});
|
const ChatBubble({
|
||||||
|
super.key,
|
||||||
|
required this.message,
|
||||||
|
this.isUser = false,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|||||||
@@ -5,12 +5,18 @@ import 'package:flutter_highlighter/flutter_highlighter.dart';
|
|||||||
import 'package:flutter_highlighter/themes/monokai-sublime.dart';
|
import 'package:flutter_highlighter/themes/monokai-sublime.dart';
|
||||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||||
|
|
||||||
Widget renderContent(BuildContext context, String text) {
|
Widget renderContent(
|
||||||
|
BuildContext context,
|
||||||
|
String text,
|
||||||
|
) {
|
||||||
if (text.isEmpty) {
|
if (text.isEmpty) {
|
||||||
return const Text("No content to display.");
|
return const Text("No content to display.");
|
||||||
}
|
}
|
||||||
|
|
||||||
final codeBlockPattern = RegExp(r'```(\w+)?\n([\s\S]*?)```', multiLine: true);
|
final codeBlockPattern = RegExp(
|
||||||
|
r'```(\w+)?\n([\s\S]*?)```',
|
||||||
|
multiLine: true,
|
||||||
|
);
|
||||||
final matches = codeBlockPattern.allMatches(text);
|
final matches = codeBlockPattern.allMatches(text);
|
||||||
|
|
||||||
if (matches.isEmpty) {
|
if (matches.isEmpty) {
|
||||||
@@ -22,8 +28,10 @@ Widget renderContent(BuildContext context, String text) {
|
|||||||
|
|
||||||
for (var match in matches) {
|
for (var match in matches) {
|
||||||
if (match.start > lastEnd) {
|
if (match.start > lastEnd) {
|
||||||
children
|
children.add(_renderMarkdown(
|
||||||
.add(_renderMarkdown(context, text.substring(lastEnd, match.start)));
|
context,
|
||||||
|
text.substring(lastEnd, match.start),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
final language = match.group(1) ?? 'text';
|
final language = match.group(1) ?? 'text';
|
||||||
@@ -43,7 +51,10 @@ Widget renderContent(BuildContext context, String text) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _renderMarkdown(BuildContext context, String markdown) {
|
Widget _renderMarkdown(
|
||||||
|
BuildContext context,
|
||||||
|
String markdown,
|
||||||
|
) {
|
||||||
return MarkdownBody(
|
return MarkdownBody(
|
||||||
data: markdown,
|
data: markdown,
|
||||||
selectable: true,
|
selectable: true,
|
||||||
@@ -53,7 +64,11 @@ Widget _renderMarkdown(BuildContext context, String markdown) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _renderCodeBlock(BuildContext context, String language, String code) {
|
Widget _renderCodeBlock(
|
||||||
|
BuildContext context,
|
||||||
|
String language,
|
||||||
|
String code,
|
||||||
|
) {
|
||||||
if (language == 'json') {
|
if (language == 'json') {
|
||||||
try {
|
try {
|
||||||
final prettyJson =
|
final prettyJson =
|
||||||
@@ -63,7 +78,10 @@ Widget _renderCodeBlock(BuildContext context, String language, String code) {
|
|||||||
color: Theme.of(context).colorScheme.surfaceContainerLow,
|
color: Theme.of(context).colorScheme.surfaceContainerLow,
|
||||||
child: SelectableText(
|
child: SelectableText(
|
||||||
prettyJson,
|
prettyJson,
|
||||||
style: const TextStyle(fontFamily: 'monospace', fontSize: 12),
|
style: const TextStyle(
|
||||||
|
fontFamily: 'monospace',
|
||||||
|
fontSize: 12,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -78,7 +96,10 @@ Widget _renderCodeBlock(BuildContext context, String language, String code) {
|
|||||||
code,
|
code,
|
||||||
language: language,
|
language: language,
|
||||||
theme: monokaiSublimeTheme,
|
theme: monokaiSublimeTheme,
|
||||||
textStyle: const TextStyle(fontFamily: 'monospace', fontSize: 12),
|
textStyle: const TextStyle(
|
||||||
|
fontFamily: 'monospace',
|
||||||
|
fontSize: 12,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -87,14 +108,20 @@ Widget _renderCodeBlock(BuildContext context, String language, String code) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _renderFallbackCode(BuildContext context, String code) {
|
Widget _renderFallbackCode(
|
||||||
|
BuildContext context,
|
||||||
|
String code,
|
||||||
|
) {
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.all(8),
|
padding: const EdgeInsets.all(8),
|
||||||
color: Theme.of(context).colorScheme.surfaceContainerLow,
|
color: Theme.of(context).colorScheme.surfaceContainerLow,
|
||||||
child: SelectableText(
|
child: SelectableText(
|
||||||
code,
|
code,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontFamily: 'monospace', fontSize: 12, color: Colors.red),
|
fontFamily: 'monospace',
|
||||||
|
fontSize: 12,
|
||||||
|
color: Colors.red,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,8 @@ class _DashBotWidgetState extends ConsumerState<DashBotWidget> {
|
|||||||
final testCases = response.replaceFirst("TEST_CASES_HIDDEN\n", "");
|
final testCases = response.replaceFirst("TEST_CASES_HIDDEN\n", "");
|
||||||
ref.read(chatMessagesProvider.notifier).addMessage({
|
ref.read(chatMessagesProvider.notifier).addMessage({
|
||||||
'role': 'bot',
|
'role': 'bot',
|
||||||
'message': "Test cases generated successfully. Click the button below to run them.",
|
'message':
|
||||||
|
"Test cases generated successfully. Click the button below to run them.",
|
||||||
'testCases': testCases,
|
'testCases': testCases,
|
||||||
'showTestButton': true,
|
'showTestButton': true,
|
||||||
});
|
});
|
||||||
@@ -150,7 +151,8 @@ class _DashBotWidgetState extends ConsumerState<DashBotWidget> {
|
|||||||
),
|
),
|
||||||
tooltip: isMinimized ? 'Maximize' : 'Minimize',
|
tooltip: isMinimized ? 'Maximize' : 'Minimize',
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
ref.read(dashBotMinimizedProvider.notifier).state = !isMinimized;
|
ref.read(dashBotMinimizedProvider.notifier).state =
|
||||||
|
!isMinimized;
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
@@ -214,7 +216,8 @@ class _DashBotWidgetState extends ConsumerState<DashBotWidget> {
|
|||||||
icon: const Icon(Icons.bug_report_outlined, size: 16),
|
icon: const Icon(Icons.bug_report_outlined, size: 16),
|
||||||
label: const Text("Debug"),
|
label: const Text("Debug"),
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
padding:
|
||||||
|
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||||
visualDensity: VisualDensity.compact,
|
visualDensity: VisualDensity.compact,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -8,7 +8,10 @@ import 'content_renderer.dart';
|
|||||||
class TestRunnerWidget extends ConsumerStatefulWidget {
|
class TestRunnerWidget extends ConsumerStatefulWidget {
|
||||||
final String testCases;
|
final String testCases;
|
||||||
|
|
||||||
const TestRunnerWidget({Key? key, required this.testCases}) : super(key: key);
|
const TestRunnerWidget({
|
||||||
|
Key? key,
|
||||||
|
required this.testCases,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ConsumerState<TestRunnerWidget> createState() => _TestRunnerWidgetState();
|
ConsumerState<TestRunnerWidget> createState() => _TestRunnerWidgetState();
|
||||||
@@ -78,7 +81,8 @@ class _TestRunnerWidgetState extends ConsumerState<TestRunnerWidget> {
|
|||||||
String method = "GET";
|
String method = "GET";
|
||||||
if (command.contains("-X POST") || command.contains("--request POST")) {
|
if (command.contains("-X POST") || command.contains("--request POST")) {
|
||||||
method = "POST";
|
method = "POST";
|
||||||
} else if (command.contains("-X PUT") || command.contains("--request PUT")) {
|
} else if (command.contains("-X PUT") ||
|
||||||
|
command.contains("--request PUT")) {
|
||||||
method = "PUT";
|
method = "PUT";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,9 +193,8 @@ class _TestRunnerWidgetState extends ConsumerState<TestRunnerWidget> {
|
|||||||
test['description'] ?? "Test case ${index + 1}",
|
test['description'] ?? "Test case ${index + 1}",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
color: hasResult
|
color:
|
||||||
? (isSuccess ? Colors.green : Colors.red)
|
hasResult ? (isSuccess ? Colors.green : Colors.red) : null,
|
||||||
: null,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
subtitle: Text('Test ${index + 1} of ${_parsedTests.length}'),
|
subtitle: Text('Test ${index + 1} of ${_parsedTests.length}'),
|
||||||
@@ -241,7 +244,8 @@ class _TestRunnerWidgetState extends ConsumerState<TestRunnerWidget> {
|
|||||||
padding: const EdgeInsets.all(8),
|
padding: const EdgeInsets.all(8),
|
||||||
margin: const EdgeInsets.only(top: 4, bottom: 16),
|
margin: const EdgeInsets.only(top: 4, bottom: 16),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Theme.of(context).colorScheme.surfaceContainerLow,
|
color:
|
||||||
|
Theme.of(context).colorScheme.surfaceContainerLow,
|
||||||
borderRadius: BorderRadius.circular(4),
|
borderRadius: BorderRadius.circular(4),
|
||||||
),
|
),
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
|
|||||||
Reference in New Issue
Block a user