intimacy_analyze_repository.dart 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import 'dart:io';
  2. import 'package:get/get_rx/src/rx_types/rx_types.dart';
  3. import 'package:injectable/injectable.dart';
  4. import 'package:keyboard/base/app_base_request.dart';
  5. import '../../di/get_it.dart';
  6. import '../../utils/async_util.dart';
  7. import '../../utils/atmob_log.dart';
  8. import '../../utils/http_handler.dart';
  9. import '../api/atmob_api.dart';
  10. import '../api/request/intimacy_analyze_request.dart';
  11. import '../api/request/intimacy_reply_analyze_request.dart';
  12. import '../api/response/intimacy_analyze_chat_config_response.dart';
  13. import '../api/response/intimacy_analyze_config_response.dart';
  14. import '../api/response/intimacy_analyze_reply_config_response.dart';
  15. import '../api/response/intimacy_analyze_response.dart';
  16. /// 亲密度分析Repository层
  17. @LazySingleton()
  18. class IntimacyAnalyzeRepository {
  19. final String tag = "IntimacyAnalyzeRepository";
  20. final AtmobApi atmobApi;
  21. /// 亲密度配置
  22. Rxn<IntimacyAnalyzeConfigResponse> intimacyAnalyzeConfig =
  23. Rxn<IntimacyAnalyzeConfigResponse>();
  24. /// 对话分析配置
  25. Rxn<IntimacyAnalyzeChatConfigResponse> intimacyAnalyzeChatConfig =
  26. Rxn<IntimacyAnalyzeChatConfigResponse>();
  27. /// 识图回复配置
  28. Rxn<IntimacyAnalyzeReplyConfigResponse> intimacyAnalyzeReplyConfig =
  29. Rxn<IntimacyAnalyzeReplyConfigResponse>();
  30. IntimacyAnalyzeRepository(this.atmobApi) {
  31. AtmobLog.d(tag, '$tag...init');
  32. // 初始化时,刷新配置
  33. _refreshIntimacyAnalyzeConfig();
  34. _refreshIntimacyAnalyzeChatConfig();
  35. _refreshIntimacyAnalyzeReplyConfig();
  36. }
  37. /// 从Getx的依赖注入中,获取实例,适合在没有依赖注入上下文的地方使用
  38. IntimacyAnalyzeRepository getInstance() {
  39. return getIt.get<IntimacyAnalyzeRepository>();
  40. }
  41. /// 刷新亲密度配置
  42. void _refreshIntimacyAnalyzeConfig() {
  43. AsyncUtil.retry(
  44. () => requestIntimacyAnalyzeConfig(),
  45. Duration(seconds: 3),
  46. maxRetry: 100,
  47. ).then((IntimacyAnalyzeConfigResponse configResponse) {
  48. AtmobLog.d(tag, "获取亲密度配置成功: ${configResponse.toJson()}");
  49. intimacyAnalyzeConfig.value = configResponse;
  50. });
  51. }
  52. /// 刷新对话分析配置
  53. void _refreshIntimacyAnalyzeChatConfig() {
  54. AsyncUtil.retry(
  55. () => requestIntimacyAnalyzeChatConfig(),
  56. Duration(seconds: 3),
  57. maxRetry: 100,
  58. ).then((IntimacyAnalyzeChatConfigResponse configResponse) {
  59. AtmobLog.d(tag, "获取对话分析配置成功: ${configResponse.toJson()}");
  60. intimacyAnalyzeChatConfig.value = configResponse;
  61. });
  62. }
  63. /// 刷新识图回复配置
  64. void _refreshIntimacyAnalyzeReplyConfig() {
  65. AsyncUtil.retry(
  66. () => requestIntimacyAnalyzeReplyConfig(),
  67. Duration(seconds: 3),
  68. maxRetry: 100,
  69. ).then((IntimacyAnalyzeReplyConfigResponse configResponse) {
  70. AtmobLog.d(tag, "获取识图回复配置成功: ${configResponse.toJson()}");
  71. intimacyAnalyzeReplyConfig.value = configResponse;
  72. });
  73. }
  74. /// 获取亲密度配置
  75. Future<IntimacyAnalyzeConfigResponse> requestIntimacyAnalyzeConfig() {
  76. return atmobApi
  77. .getIntimacyAnalyzeConfig(AppBaseRequest())
  78. .then(HttpHandler.handle(true));
  79. }
  80. /// 获取对话分析配置
  81. Future<IntimacyAnalyzeChatConfigResponse> requestIntimacyAnalyzeChatConfig() {
  82. return atmobApi
  83. .getIntimacyAnalyzeChatConfig(AppBaseRequest())
  84. .then(HttpHandler.handle(true));
  85. }
  86. /// 获取识图回复配置
  87. Future<IntimacyAnalyzeReplyConfigResponse>
  88. requestIntimacyAnalyzeReplyConfig() {
  89. return atmobApi
  90. .getIntimacyAnalyzeReplyConfig(AppBaseRequest())
  91. .then(HttpHandler.handle(true));
  92. }
  93. /// 分析亲密度
  94. Future<IntimacyAnalyzeResponse> getIntimacyAnalyze(
  95. IntimacyAnalyzeRequest request,
  96. ) {
  97. return atmobApi.getIntimacyAnalyze(request).then(HttpHandler.handle(true));
  98. }
  99. // /// 识图回复
  100. // Future<Object> intimacyReplyAnalyze(
  101. // IntimacyReplyAnalyzeRequest request,
  102. // ) {
  103. // return atmobApi
  104. // .intimacyReplyAnalyze(request)
  105. // .then(HttpHandler.handle(true));
  106. // }
  107. }