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_request.dart';
|
||||||
import 'package:scribe/scribe/ai/data/model/ai_api_response.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/model/ai_message.dart';
|
||||||
import 'package:scribe/scribe/ai/data/network/ai_api_exception.dart';
|
|
||||||
|
|
||||||
class AIApi {
|
class AIApi {
|
||||||
final DioClient _dioClient;
|
final DioClient _dioClient;
|
||||||
@@ -19,17 +18,7 @@ class AIApi {
|
|||||||
useJMAPHeader: false,
|
useJMAPHeader: false,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
return AIApiResponse.fromJson(response);
|
||||||
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,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AIAPIRequest _generateRequest(String prompt) {
|
AIAPIRequest _generateRequest(String prompt) {
|
||||||
|
|||||||
@@ -20,3 +20,7 @@ class AIApiNotAvailableException extends AIApiException {
|
|||||||
class AIApiEmptyResponseException extends AIApiException {
|
class AIApiEmptyResponseException extends AIApiException {
|
||||||
AIApiEmptyResponseException() : super('AI API returned empty response');
|
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() {
|
void _bindingsAPI() {
|
||||||
Get.lazyPut<AIApi>(() => AIApi(Get.find<DioClient>(), aiEndpoint));
|
Get.put(AIApi(Get.find<DioClient>(), aiEndpoint));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _bindingsDataSourceImpl() {
|
void _bindingsDataSourceImpl() {
|
||||||
Get.lazyPut<AIDataSourceImpl>(() => AIDataSourceImpl(Get.find<AIApi>()));
|
Get.put(AIDataSourceImpl(Get.find<AIApi>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _bindingsDataSource() {
|
void _bindingsDataSource() {
|
||||||
Get.lazyPut<AIDataSource>(() => Get.find<AIDataSourceImpl>());
|
Get.put<AIDataSource>(Get.find<AIDataSourceImpl>());
|
||||||
}
|
}
|
||||||
|
|
||||||
void _bindingsRepositoryImpl() {
|
void _bindingsRepositoryImpl() {
|
||||||
Get.lazyPut<AIScribeRepositoryImpl>(
|
Get.put(AIScribeRepositoryImpl(Get.find<AIDataSource>()));
|
||||||
() => AIScribeRepositoryImpl(Get.find<AIDataSource>()),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _bindingsRepository() {
|
void _bindingsRepository() {
|
||||||
Get.lazyPut<AIScribeRepository>(() => Get.find<AIScribeRepositoryImpl>());
|
Get.put<AIScribeRepository>(Get.find<AIScribeRepositoryImpl>());
|
||||||
}
|
}
|
||||||
|
|
||||||
void _bindingsInteractor() {
|
void _bindingsInteractor() {
|
||||||
Get.lazyPut<GenerateAITextInteractor>(
|
Get.put(GenerateAITextInteractor(Get.find<AIScribeRepository>()));
|
||||||
() => GenerateAITextInteractor(Get.find<AIScribeRepository>()),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:pointer_interceptor/pointer_interceptor.dart';
|
import 'package:pointer_interceptor/pointer_interceptor.dart';
|
||||||
import 'package:scribe/scribe.dart';
|
import 'package:scribe/scribe.dart';
|
||||||
|
import 'package:scribe/scribe/ai/data/network/ai_api_exception.dart';
|
||||||
|
|
||||||
class AiScribeSuggestionWidget extends StatefulWidget {
|
class AiScribeSuggestionWidget extends StatefulWidget {
|
||||||
final AIAction aiAction;
|
final AIAction aiAction;
|
||||||
@@ -50,6 +51,12 @@ class _AiScribeSuggestionWidgetModalState
|
|||||||
widget.aiAction,
|
widget.aiAction,
|
||||||
widget.content,
|
widget.content,
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
_valueNotifier.value = dartz.Left(
|
||||||
|
GenerateAITextFailure(
|
||||||
|
GenerateAITextInteractorIsNotRegisteredException(),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user