feat(ai-scribe): Fix generate ai text is failed
This commit is contained in:
@@ -2,7 +2,6 @@ import 'package:core/data/network/dio_client.dart';
|
||||
import 'package:scribe/scribe/ai/data/model/ai_api_request.dart';
|
||||
import 'package:scribe/scribe/ai/data/model/ai_api_response.dart';
|
||||
import 'package:scribe/scribe/ai/data/model/ai_message.dart';
|
||||
import 'package:scribe/scribe/ai/data/network/ai_api_exception.dart';
|
||||
|
||||
class AIApi {
|
||||
final DioClient _dioClient;
|
||||
@@ -19,17 +18,7 @@ class AIApi {
|
||||
useJMAPHeader: false,
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
if (response.data == null || response.data.isEmpty) {
|
||||
throw AIApiEmptyResponseException();
|
||||
}
|
||||
return AIApiResponse.fromJson(response.data);
|
||||
} else {
|
||||
throw AIApiException(
|
||||
'AI API returned status code: ${response.statusCode}',
|
||||
statusCode: response.statusCode,
|
||||
);
|
||||
}
|
||||
return AIApiResponse.fromJson(response);
|
||||
}
|
||||
|
||||
AIAPIRequest _generateRequest(String prompt) {
|
||||
|
||||
@@ -20,3 +20,7 @@ class AIApiNotAvailableException extends AIApiException {
|
||||
class AIApiEmptyResponseException extends AIApiException {
|
||||
AIApiEmptyResponseException() : super('AI API returned empty response');
|
||||
}
|
||||
|
||||
class GenerateAITextInteractorIsNotRegisteredException extends AIApiException {
|
||||
GenerateAITextInteractorIsNotRegisteredException() : super('GenerateAITextInteractor is not registered');
|
||||
}
|
||||
@@ -20,30 +20,26 @@ class AIScribeBindings extends Bindings {
|
||||
}
|
||||
|
||||
void _bindingsAPI() {
|
||||
Get.lazyPut<AIApi>(() => AIApi(Get.find<DioClient>(), aiEndpoint));
|
||||
Get.put(AIApi(Get.find<DioClient>(), aiEndpoint));
|
||||
}
|
||||
|
||||
void _bindingsDataSourceImpl() {
|
||||
Get.lazyPut<AIDataSourceImpl>(() => AIDataSourceImpl(Get.find<AIApi>()));
|
||||
Get.put(AIDataSourceImpl(Get.find<AIApi>()));
|
||||
}
|
||||
|
||||
void _bindingsDataSource() {
|
||||
Get.lazyPut<AIDataSource>(() => Get.find<AIDataSourceImpl>());
|
||||
Get.put<AIDataSource>(Get.find<AIDataSourceImpl>());
|
||||
}
|
||||
|
||||
void _bindingsRepositoryImpl() {
|
||||
Get.lazyPut<AIScribeRepositoryImpl>(
|
||||
() => AIScribeRepositoryImpl(Get.find<AIDataSource>()),
|
||||
);
|
||||
Get.put(AIScribeRepositoryImpl(Get.find<AIDataSource>()));
|
||||
}
|
||||
|
||||
void _bindingsRepository() {
|
||||
Get.lazyPut<AIScribeRepository>(() => Get.find<AIScribeRepositoryImpl>());
|
||||
Get.put<AIScribeRepository>(Get.find<AIScribeRepositoryImpl>());
|
||||
}
|
||||
|
||||
void _bindingsInteractor() {
|
||||
Get.lazyPut<GenerateAITextInteractor>(
|
||||
() => GenerateAITextInteractor(Get.find<AIScribeRepository>()),
|
||||
);
|
||||
Get.put(GenerateAITextInteractor(Get.find<AIScribeRepository>()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:pointer_interceptor/pointer_interceptor.dart';
|
||||
import 'package:scribe/scribe.dart';
|
||||
import 'package:scribe/scribe/ai/data/network/ai_api_exception.dart';
|
||||
|
||||
class AiScribeSuggestionWidget extends StatefulWidget {
|
||||
final AIAction aiAction;
|
||||
@@ -50,6 +51,12 @@ class _AiScribeSuggestionWidgetModalState
|
||||
widget.aiAction,
|
||||
widget.content,
|
||||
);
|
||||
} else {
|
||||
_valueNotifier.value = dartz.Left(
|
||||
GenerateAITextFailure(
|
||||
GenerateAITextInteractorIsNotRegisteredException(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user