AI大模型优化: 1693/1 1693/head 1698/target/1
authorluozheng <1732036298@qq.com>
Wed, 19 Mar 2025 03:14:33 +0000 (11:14 +0800)
committerluozheng <1732036298@qq.com>
Wed, 19 Mar 2025 03:14:33 +0000 (11:14 +0800)
1.解决Ai大模型问题拼接问题
2.解决AI大模型在回长内容手表显示到极限时概率出现答案消失问题

code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceChatContentListItemView.cpp

index 6a393a3..f45155f 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-06-20 15:14:43
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2025-03-13 16:02:18
+ * @LastEditTime: 2025-03-19 09:44:14
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h
  */
 #ifndef AI_VOICE_MODEL_H
@@ -112,6 +112,12 @@ namespace OHOS
 
         bool CreateDirectory(const char* path);
 
+        void SetIsClickable(bool value);
+        bool GetIsClickable(void);
+
+        void SetIsLimitDisplayed(bool value);
+        bool GetIsLimitDisplayed(void);
+
     private:
         AiVoiceModel();
         ~AiVoiceModel();
@@ -137,6 +143,8 @@ namespace OHOS
         uint8_t AIResponseType;
         std::string errnote;                                                 //错误信息
         int16_t curView{0};
+        bool isClickable{false};
+        bool isLimitDisplayed{false};//AI答案是否显示到极限了
     };
 
 }
index 110c808..41216d6 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-06-20 15:14:50
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2025-03-14 09:43:46
+ * @LastEditTime: 2025-03-19 11:09:58
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp
  */
 #include "aivoice/include/AiVoiceModel.h"
@@ -32,7 +32,7 @@ namespace OHOS
 {
     // 声明定时器变量
     static osTimerId_t g_timer = nullptr;
-    static constexpr uint16_t THIRTY_TIME = 30;
+    static constexpr uint16_t THIRTY_TIME = 30 / 3;
     static int Time = THIRTY_TIME;
     static int AiModelConnectTimeout = 5;
 
@@ -387,6 +387,23 @@ namespace OHOS
     bool AiVoiceModel::UpdateAiAnswerStr()
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::UpdateAiAnswerStr");
+        #if 0
+        AiVoiceView *view_ = AiVoiceView::GetInstance();
+        if(view_!= nullptr )
+        {
+            if(view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID) && !view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID)->IsVisible())
+            {
+                return false;
+            }
+            else
+            {
+                if(!GetIsClickable())
+                {
+                    SetIsClickable(true);
+                }
+            }
+        }
+        #endif
 
         int index = GetChatContentListCount() - 1;
         if (index < 0 || index >= MaxChatContentListCount)
@@ -438,6 +455,25 @@ namespace OHOS
         return true;
     }
 
+    void AiVoiceModel::SetIsClickable(bool value)
+    {
+        isClickable = value;
+    }
+    
+    bool AiVoiceModel::GetIsClickable(void)
+    {
+        return isClickable;
+    }
+
+    void AiVoiceModel::SetIsLimitDisplayed(bool value)
+    {
+        isLimitDisplayed = value;
+    }
+    bool AiVoiceModel::GetIsLimitDisplayed(void)
+    {
+        return isLimitDisplayed;
+    }
+
     /*获取用户问题的字符串*/
     std::string AiVoiceModel::GetUserQuestionStr(void)
     {
@@ -501,9 +537,19 @@ namespace OHOS
                 return;
             }
         }
-        aiAnswerStr += str;
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "接受字的符串:%s", aiAnswerStr.c_str());
-        SendMsgToUIService(UI_UPDATE_AI_ANSWER_STR, 0, nullptr, 0);
+        AiVoiceView *view_ = AiVoiceView::GetInstance();
+        if(view_!= nullptr )
+        {
+            if(view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID)->IsVisible())
+            {
+                if(!OHOS::AiVoiceModel::GetInstance().GetIsLimitDisplayed()) //如果ai答案没有显示到极限了,就更新ai答案字符串
+                { 
+                    aiAnswerStr += str;
+                    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "接受字的符串:%s", aiAnswerStr.c_str());
+                    SendMsgToUIService(UI_UPDATE_AI_ANSWER_STR, 0, nullptr, 0);
+                }
+            }
+        }
     }
 
     /*清空上次用户问题和Ai回答字符串*/
@@ -652,6 +698,8 @@ namespace OHOS
         }
         ChatContentListCount = 0;
         entryTextViewState = false;
+        isClickable = false;
+        isLimitDisplayed = false;
         ClearQuestionAndAiAnswerStr();
         StopListenAndRecordingUserQuestion();
     }
index d22a5c1..233dbeb 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-06-20 15:11:17
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2025-03-13 11:52:43
+ * @LastEditTime: 2025-03-19 10:24:14
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp
  */
 #include "AppViewIDs.h"
@@ -264,6 +264,8 @@ namespace OHOS
 
         case AIVOICE_RETURN_RESULT_TEXT_VIEWID:
             AiVoiceModel::GetInstance().ClearQuestionAndAiAnswerStr(); // 清空上次用户问题和Ai回答字符串
+            AiVoiceModel::GetInstance().SetIsClickable(false);
+            AiVoiceModel::GetInstance().SetIsLimitDisplayed(false);
             if (showView == AIVOICE_LISTENING_VIEWID)
             {
                 model->StartListenAndRecordingUserQuestion();
@@ -316,6 +318,13 @@ namespace OHOS
         auto it = viewIdMap.find(viewId);
         if (it != viewIdMap.end())
         {
+            #if 0
+            if(!model->GetIsClickable())
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "当前还不可点击");
+                return true;
+            }
+            #endif
             if (it->first == AIVOICERETURNRESULTTEXT_CONTINUECHAT_BUTTON_VIEW_ID) // 点击继续对话按钮要发取消当前对话指令,避免AI回应中途按继续对话按钮没有取消上一次对话问题
             {
                 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CancelCurAIChat");
index 0e83e34..a5b9590 100644 (file)
@@ -2,11 +2,12 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-06-29 17:27:25
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-10-28 15:54:29
+ * @LastEditTime: 2025-03-19 10:12:45
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceChatContentListItemView.cpp
  */
 
 #include "aivoice/include/AivoiceChatContentListItemView.h"
+#include "aivoice/include/AiVoiceModel.h"
 #include "wearable_log.h"
 
 namespace OHOS
@@ -87,7 +88,11 @@ namespace OHOS
         }
         else
         {
-            chatContentLabel.SetLineBreakMode(isAiAnswerFlag ? UILabel::LINE_BREAK_ELLIPSIS : UILabel::LINE_BREAK_WRAP);//超过高度在末尾用省略号替换
+            if(!AiVoiceModel::GetInstance().GetIsLimitDisplayed())
+            {
+                AiVoiceModel::GetInstance().SetIsLimitDisplayed(true);
+                chatContentLabel.SetLineBreakMode(isAiAnswerFlag ? UILabel::LINE_BREAK_ELLIPSIS : UILabel::LINE_BREAK_WRAP);//超过高度在末尾用省略号替换
+            }
         }
     }