Bläddra i källkod

[feat]亲密度分析,截图回复-对话分析,对接获取对话分析配置接口

hezihao 7 månader sedan
förälder
incheckning
a538905a18

+ 3 - 0
assets/string/base/string.xml

@@ -313,6 +313,9 @@
 
     <string name="intimacy_analyse_report_preview_bubble_text">报告还有2565字未显示,点击按钮查看完整报告</string>
 
+    <string name="for_ta">对于TA</string>
+    <string name="for_me">对于我</string>
+
     <string name="preview">预览</string>
 
     <string name="retry">再试试</string>

+ 6 - 1
lib/data/api/atmob_api.dart

@@ -38,6 +38,7 @@ import 'package:keyboard/data/api/response/chat_prologue_response.dart';
 import 'package:keyboard/data/api/response/chat_super_reply_response.dart';
 import 'package:keyboard/data/api/response/chat_super_speak_response.dart';
 import 'package:keyboard/data/api/response/config_response.dart';
+import 'package:keyboard/data/api/response/intimacy_analyze_chat_config_response.dart';
 import 'package:keyboard/data/api/response/intimacy_analyze_config_response.dart';
 import 'package:keyboard/data/api/response/intimacy_analyze_response.dart';
 import 'package:keyboard/data/api/response/item_list_response.dart';
@@ -101,7 +102,6 @@ abstract class AtmobApi {
     @Body() AppBaseRequest request,
   );
 
-
   // 获取人设主题
   @POST("/project/keyboard/v1/character/group")
   Future<BaseResponse<CharacterGroupResponse>> getCharactersGroup(
@@ -270,6 +270,11 @@ abstract class AtmobApi {
     @Body() IntimacyAnalyzeRequest request,
   );
 
+  /// 获取对话分析配置
+  @POST("/project/keyboard/v1/intimacy/chat/config")
+  Future<BaseResponse<IntimacyAnalyzeChatConfigResponse>>
+  getIntimacyAnalyzeChatConfig(@Body() AppBaseRequest request);
+
   // 获取星座梗语与解读
   @POST("/project/keyboard/v1/keyboard/memeExplain")
   Future<BaseResponse<KeyboardMemeExplainResponse>> getKeyboardMemeExplain(

+ 37 - 0
lib/data/api/atmob_api.g.dart

@@ -1238,6 +1238,43 @@ class _AtmobApi implements AtmobApi {
   }
 
   @override
+  Future<BaseResponse<IntimacyAnalyzeChatConfigResponse>>
+  getIntimacyAnalyzeChatConfig(AppBaseRequest request) async {
+    final _extra = <String, dynamic>{};
+    final queryParameters = <String, dynamic>{};
+    final _headers = <String, dynamic>{};
+    final _data = <String, dynamic>{};
+    _data.addAll(request.toJson());
+    final _options =
+        _setStreamType<BaseResponse<IntimacyAnalyzeChatConfigResponse>>(
+          Options(method: 'POST', headers: _headers, extra: _extra)
+              .compose(
+                _dio.options,
+                '/project/keyboard/v1/intimacy/chat/config',
+                queryParameters: queryParameters,
+                data: _data,
+              )
+              .copyWith(
+                baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl),
+              ),
+        );
+    final _result = await _dio.fetch<Map<String, dynamic>>(_options);
+    late BaseResponse<IntimacyAnalyzeChatConfigResponse> _value;
+    try {
+      _value = BaseResponse<IntimacyAnalyzeChatConfigResponse>.fromJson(
+        _result.data!,
+        (json) => IntimacyAnalyzeChatConfigResponse.fromJson(
+          json as Map<String, dynamic>,
+        ),
+      );
+    } on Object catch (e, s) {
+      errorLogger?.logError(e, s, _options);
+      rethrow;
+    }
+    return _value;
+  }
+
+  @override
   Future<BaseResponse<KeyboardMemeExplainResponse>> getKeyboardMemeExplain(
     KeyboardMemeExplainRequest request,
   ) async {

+ 18 - 0
lib/data/api/response/for_me_bean.dart

@@ -0,0 +1,18 @@
+import 'package:json_annotation/json_annotation.dart';
+
+part 'for_me_bean.g.dart';
+
+/// 对于他
+@JsonSerializable()
+class ForMeBean {
+  /// 标题
+  @JsonKey(name: "title")
+  String title;
+
+  ForMeBean(this.title);
+
+  factory ForMeBean.fromJson(Map<String, dynamic> json) =>
+      _$ForMeBeanFromJson(json);
+
+  Map<String, dynamic> toJson() => _$ForMeBeanToJson(this);
+}

+ 14 - 0
lib/data/api/response/for_me_bean.g.dart

@@ -0,0 +1,14 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'for_me_bean.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+ForMeBean _$ForMeBeanFromJson(Map<String, dynamic> json) =>
+    ForMeBean(json['title'] as String);
+
+Map<String, dynamic> _$ForMeBeanToJson(ForMeBean instance) => <String, dynamic>{
+  'title': instance.title,
+};

+ 18 - 0
lib/data/api/response/for_ta_bean.dart

@@ -0,0 +1,18 @@
+import 'package:json_annotation/json_annotation.dart';
+
+part 'for_ta_bean.g.dart';
+
+/// 对于他
+@JsonSerializable()
+class ForTaBean {
+  /// 标题
+  @JsonKey(name: "title")
+  String title;
+
+  ForTaBean(this.title);
+
+  factory ForTaBean.fromJson(Map<String, dynamic> json) =>
+      _$ForTaBeanFromJson(json);
+
+  Map<String, dynamic> toJson() => _$ForTaBeanToJson(this);
+}

+ 14 - 0
lib/data/api/response/for_ta_bean.g.dart

@@ -0,0 +1,14 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'for_ta_bean.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+ForTaBean _$ForTaBeanFromJson(Map<String, dynamic> json) =>
+    ForTaBean(json['title'] as String);
+
+Map<String, dynamic> _$ForTaBeanToJson(ForTaBean instance) => <String, dynamic>{
+  'title': instance.title,
+};

+ 29 - 0
lib/data/api/response/intimacy_analyze_chat_config_response.dart

@@ -0,0 +1,29 @@
+import 'package:json_annotation/json_annotation.dart';
+import 'package:keyboard/data/api/response/for_me_bean.dart';
+import 'package:keyboard/data/api/response/for_ta_bean.dart';
+
+import '../../bean/ai_model.dart';
+import '../../bean/intimacy_analyze_direction.dart';
+
+part 'intimacy_analyze_chat_config_response.g.dart';
+
+/// 亲密度-对话分析配置
+@JsonSerializable()
+class IntimacyAnalyzeChatConfigResponse {
+  /// 对于他
+  @JsonKey(name: 'forTa')
+  List<ForTaBean>? forTa;
+
+  /// 对于我
+  @JsonKey(name: 'forMe')
+  List<ForMeBean>? forMe;
+
+  IntimacyAnalyzeChatConfigResponse(this.forTa, this.forMe);
+
+  factory IntimacyAnalyzeChatConfigResponse.fromJson(
+    Map<String, dynamic> json,
+  ) => _$IntimacyAnalyzeChatConfigResponseFromJson(json);
+
+  Map<String, dynamic> toJson() =>
+      _$IntimacyAnalyzeChatConfigResponseToJson(this);
+}

+ 22 - 0
lib/data/api/response/intimacy_analyze_chat_config_response.g.dart

@@ -0,0 +1,22 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'intimacy_analyze_chat_config_response.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+IntimacyAnalyzeChatConfigResponse _$IntimacyAnalyzeChatConfigResponseFromJson(
+  Map<String, dynamic> json,
+) => IntimacyAnalyzeChatConfigResponse(
+  (json['forTa'] as List<dynamic>?)
+      ?.map((e) => ForTaBean.fromJson(e as Map<String, dynamic>))
+      .toList(),
+  (json['forMe'] as List<dynamic>?)
+      ?.map((e) => ForMeBean.fromJson(e as Map<String, dynamic>))
+      .toList(),
+);
+
+Map<String, dynamic> _$IntimacyAnalyzeChatConfigResponseToJson(
+  IntimacyAnalyzeChatConfigResponse instance,
+) => <String, dynamic>{'forTa': instance.forTa, 'forMe': instance.forMe};

+ 27 - 2
lib/data/repository/intimacy_analyze_repository.dart

@@ -10,6 +10,7 @@ import '../../utils/atmob_log.dart';
 import '../../utils/http_handler.dart';
 import '../api/atmob_api.dart';
 import '../api/request/intimacy_analyze_request.dart';
+import '../api/response/intimacy_analyze_chat_config_response.dart';
 import '../api/response/intimacy_analyze_config_response.dart';
 import '../api/response/intimacy_analyze_response.dart';
 
@@ -24,10 +25,15 @@ class IntimacyAnalyzeRepository {
   Rxn<IntimacyAnalyzeConfigResponse> intimacyAnalyzeConfig =
       Rxn<IntimacyAnalyzeConfigResponse>();
 
+  /// 对话分析配置
+  Rxn<IntimacyAnalyzeChatConfigResponse> intimacyAnalyzeChatConfig =
+      Rxn<IntimacyAnalyzeChatConfigResponse>();
+
   IntimacyAnalyzeRepository(this.atmobApi) {
     AtmobLog.d(tag, '$tag...init');
     // 初始化时,刷新配置
-    refreshIntimacyAnalyzeConfig();
+    _refreshIntimacyAnalyzeConfig();
+    _refreshIntimacyAnalyzeChatConfig();
   }
 
   /// 从Getx的依赖注入中,获取实例,适合在没有依赖注入上下文的地方使用
@@ -36,7 +42,7 @@ class IntimacyAnalyzeRepository {
   }
 
   /// 刷新亲密度配置
-  void refreshIntimacyAnalyzeConfig() {
+  void _refreshIntimacyAnalyzeConfig() {
     AsyncUtil.retry(
       () => requestIntimacyAnalyzeConfig(),
       Duration(seconds: 3),
@@ -47,6 +53,18 @@ class IntimacyAnalyzeRepository {
     });
   }
 
+  /// 刷新对话分析配置
+  void _refreshIntimacyAnalyzeChatConfig() {
+    AsyncUtil.retry(
+      () => requestIntimacyAnalyzeChatConfig(),
+      Duration(seconds: 3),
+      maxRetry: 100,
+    ).then((IntimacyAnalyzeChatConfigResponse configResponse) {
+      AtmobLog.d(tag, "获取对话分析配置成功: ${configResponse.toJson()}");
+      intimacyAnalyzeChatConfig.value = configResponse;
+    });
+  }
+
   /// 获取亲密度配置
   Future<IntimacyAnalyzeConfigResponse> requestIntimacyAnalyzeConfig() {
     return atmobApi
@@ -54,6 +72,13 @@ class IntimacyAnalyzeRepository {
         .then(HttpHandler.handle(true));
   }
 
+  /// 获取对话分析配置
+  Future<IntimacyAnalyzeChatConfigResponse> requestIntimacyAnalyzeChatConfig() {
+    return atmobApi
+        .getIntimacyAnalyzeChatConfig(AppBaseRequest())
+        .then(HttpHandler.handle(true));
+  }
+
   /// 分析亲密度
   Future<IntimacyAnalyzeResponse> getIntimacyAnalyze(
     IntimacyAnalyzeRequest request,

+ 29 - 14
lib/module/intimacy_analyse/screenshot_reply/conversation_analysis/conversation_analysis_controller.dart

@@ -4,6 +4,7 @@ import 'package:flutter/cupertino.dart';
 import 'package:get/get.dart';
 import 'package:injectable/injectable.dart';
 import 'package:keyboard/base/base_controller.dart';
+import 'package:keyboard/resource/string.gen.dart';
 import 'package:wechat_assets_picker/wechat_assets_picker.dart';
 
 import '../../../../data/bean/option_select_config.dart';
@@ -82,20 +83,34 @@ class ConversationAnalysisController extends BaseController {
 
   /// 初始化选项列表
   void _initOptionSelectConfigList() {
-    optionSelectConfigList.add(
-      OptionSelectConfig("对于TA", "", [
-        OptionSelectItem("现在的需求"),
-        OptionSelectItem("真实想法"),
-        OptionSelectItem("渣渣鉴定"),
-      ]),
-    );
-    optionSelectConfigList.add(
-      OptionSelectConfig("对于我", "", [
-        OptionSelectItem("帮回"),
-        OptionSelectItem("告白"),
-        OptionSelectItem("复合"),
-      ]),
-    );
+    optionSelectConfigList.clear();
+
+    // 对于Ta
+    var forTaConfig =
+        intimacyAnalyzeConfigHelper.intimacyAnalyzeChatConfig.value?.forTa;
+    if (forTaConfig != null && forTaConfig.isNotEmpty) {
+      var itemList =
+          forTaConfig.map((item) {
+            return OptionSelectItem(item.title);
+          }).toList();
+      optionSelectConfigList.add(
+        OptionSelectConfig(StringName.forTa, "", itemList),
+      );
+    }
+    // 对于我
+    var forMeConfig =
+        intimacyAnalyzeConfigHelper.intimacyAnalyzeChatConfig.value?.forMe;
+    if (forMeConfig != null) {
+      var itemList =
+          forMeConfig.map((item) {
+            return OptionSelectItem(item.title);
+          }).toList();
+      optionSelectConfigList.add(
+        OptionSelectConfig(StringName.forMe, "", itemList),
+      );
+    }
+
+    optionSelectConfigList.refresh();
   }
 
   /// 选中选项

+ 4 - 0
lib/resource/string.gen.dart

@@ -224,6 +224,8 @@ class StringName {
   static final String intimacyAnalyseGetReply = 'intimacy_analyse_get_reply'.tr; // 获取回复
   static final String intimacyAnalyseReplyTone = 'intimacy_analyse_reply_tone'.tr; // 回复语气:
   static final String intimacyAnalyseReportPreviewBubbleText = 'intimacy_analyse_report_preview_bubble_text'.tr; // 报告还有2565字未显示,点击按钮查看完整报告
+  static final String forTa = 'for_ta'.tr; // 对于TA
+  static final String forMe = 'for_me'.tr; // 对于我
   static final String preview = 'preview'.tr; // 预览
   static final String retry = 'retry'.tr; // 再试试
   static final String nextStep = 'next_step'.tr; // 下一步
@@ -490,6 +492,8 @@ class StringMultiSource {
       'intimacy_analyse_get_reply': '获取回复',
       'intimacy_analyse_reply_tone': '回复语气:',
       'intimacy_analyse_report_preview_bubble_text': '报告还有2565字未显示,点击按钮查看完整报告',
+      'for_ta': '对于TA',
+      'for_me': '对于我',
       'preview': '预览',
       'retry': '再试试',
       'next_step': '下一步',

+ 6 - 1
lib/utils/intimacy_analyze_config_helper.dart

@@ -1,10 +1,11 @@
 import 'package:get/get_rx/src/rx_types/rx_types.dart';
 import 'package:injectable/injectable.dart';
 
+import '../data/api/response/intimacy_analyze_chat_config_response.dart';
 import '../data/api/response/intimacy_analyze_config_response.dart';
 import '../data/repository/intimacy_analyze_repository.dart';
 
-/// 亲密度配置的帮助类
+/// 亲密度分析模块的配置的帮助类
 @injectable
 class IntimacyAnalyzeConfigHelper {
   /// 亲密度分析Repository
@@ -14,6 +15,10 @@ class IntimacyAnalyzeConfigHelper {
   Rxn<IntimacyAnalyzeConfigResponse> get intimacyAnalyzeConfig =>
       intimacyAnalyzeRepository.intimacyAnalyzeConfig;
 
+  /// 对话分析配置
+  Rxn<IntimacyAnalyzeChatConfigResponse> get intimacyAnalyzeChatConfig =>
+      intimacyAnalyzeRepository.intimacyAnalyzeChatConfig;
+
   IntimacyAnalyzeConfigHelper(this.intimacyAnalyzeRepository);
 
   /// 是否可以自定义预测方向