mirror of
https://github.com/foss42/apidash.git
synced 2025-12-03 03:17:00 +08:00
Refactored the dashbot logic to dashbot directory
This commit is contained in:
27
lib/dashbot/services/dashbot_service.dart
Normal file
27
lib/dashbot/services/dashbot_service.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
import 'dart:convert';
|
||||
import 'package:ollama_dart/ollama_dart.dart';
|
||||
import '../features/explain.dart';
|
||||
import 'package:apidash/models/request_model.dart';
|
||||
|
||||
class DashBotService {
|
||||
final OllamaClient _client;
|
||||
late final ExplainFeature _explainFeature;
|
||||
|
||||
DashBotService() : _client = OllamaClient(baseUrl: 'http://127.0.0.1:11434/api') {
|
||||
_explainFeature = ExplainFeature(this);
|
||||
}
|
||||
|
||||
Future<String> generateResponse(String prompt) async {
|
||||
final response = await _client.generateCompletion(
|
||||
request: GenerateCompletionRequest(model: 'llama3.2:3b', prompt: prompt),
|
||||
);
|
||||
return response.response.toString();
|
||||
}
|
||||
|
||||
Future<String> handleRequest(String input, RequestModel? requestModel, dynamic responseModel) async {
|
||||
if (input == "Explain API") {
|
||||
return _explainFeature.explainLatestApi(requestModel: requestModel, responseModel: responseModel);
|
||||
}
|
||||
return generateResponse(input);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user