AI语音添加查询选择的模型是否可用接口 628/1
authorluozheng <1732036298@qq.com>
Thu, 1 Aug 2024 09:42:30 +0000 (17:42 +0800)
committerluozheng <1732036298@qq.com>
Thu, 1 Aug 2024 09:42:30 +0000 (17:42 +0800)
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/service/ble_service/blemoder/bletest.cpp
code/sdk/drivers/peripheral/config/include/ConfigModel.h
code/sdk/drivers/peripheral/config/src/ConfigModel.cpp

index a027993..0342548 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-06-20 15:14:43
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-07-31 16:53:36
+ * @LastEditTime: 2024-08-01 15:01:20
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h
  */
 #ifndef AI_VOICE_MODEL_H
@@ -38,6 +38,8 @@ namespace OHOS
         bool GetAPPBluetoothIsConnect(void);
         bool GetMobileDataIsOpen(void);
         bool GetAiVoiceConnectStatus(void);
+        void SetAiVoiceConnectStatus(bool state);
+        void QuerySelectedAiModelIsConnect();
 
         // 聊天内容管理
         bool InitchatContentItems(void);
@@ -100,6 +102,7 @@ namespace OHOS
         ChatContentItem chatTtems[MaxChatContentListCount] = {0, "", false}; // 对话项数组
         bool entryTextViewState{false};                                      // 进入返回结果界面的标志
         std::map<int, std::pair<int, int>> selectAiModelToTextId;
+        bool AiVoiceConnectStatus{false};                                    //与AI模型的连接状态
     };
 
 }
index a5b18d2..ea95c96 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-06-20 15:14:50
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-07-31 18:07:20
+ * @LastEditTime: 2024-08-01 16:01:59
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp
  */
 #include "aivoice/include/AiVoiceModel.h"
@@ -118,7 +118,25 @@ namespace OHOS
     // 获取与AI模型的连接状态
     bool AiVoiceModel::GetAiVoiceConnectStatus(void)
     {
-        return true;
+        return AiVoiceConnectStatus;
+    }
+
+    // 设置与AI模型的连接状态
+    void AiVoiceModel::SetAiVoiceConnectStatus(bool state)
+    {
+        AiVoiceConnectStatus = state;
+    }
+
+    /*查询用户选择的AI模型是否已经连接*/
+    void AiVoiceModel::QuerySelectedAiModelIsConnect()
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::QuerySelectedAiModelIsConnect");
+        auto it = selectAiModelToTextId.find(GetSelectAiModel());
+        if (it != selectAiModelToTextId.end())
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SelectAiModel = %d", it->second.second);
+            inquire_AI_is_ready(it->second.second);
+        }
     }
 
     /*列表数量*/
@@ -399,6 +417,7 @@ namespace OHOS
         aiAnswerStr = "";
     }
 
+    /*获取AI音频路径*/
     std::string AiVoiceModel::GetAIAudioPath(void)
     {
         // CreateIfNotExists();
@@ -477,11 +496,14 @@ namespace OHOS
                 auto it = selectAiModelToTextId.find(GetSelectAiModel());
                 if (it != selectAiModelToTextId.end())
                 {
-                    size, it->second.second;
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "filesize = %ld,SelectAiModel = %d", size, it->second.second);
+                    send_AI_is_ready(it->second.second);
+                }
+                else
+                {
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetSelectAiModel fail!!", size, it->second.second);
                 }
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "filesize = %ld,SelectAiModel = %d", size, it->second.second);
 
-                send_AI_is_ready(it->second.second);
                 ClearQuestionAndAiAnswerStr(); // 清空上次用户问题和Ai回答字符串
             }
             fclose(file);
index 0cfa13e..95c8ed6 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-06-20 15:11:17
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-07-31 16:14:11
+ * @LastEditTime: 2024-08-01 15:55:48
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp
  */
 #include "AppViewIDs.h"
@@ -201,6 +201,9 @@ namespace OHOS
         }
         else if (viewId == AIVOICE_START_CHAT_BUTTON_VIEW_ID) // 如果点击的是开始对话按钮
         {
+            /* ------------------------ 如果点击的是开始对话按钮,先查询AI模型是否可用 ------------------------ */
+            model->QuerySelectedAiModelIsConnect();
+            /* -------------------------------------------------------------------------- */
             /*
              * 进入对话流程:
              *   1.当手表4G网络正常+与app连接正常 -> 通过4G调用大模型
@@ -210,27 +213,37 @@ namespace OHOS
              */
             bool netWork4GState = model->GetMobileDataIsOpen();
             bool appBluetoothConnectState = model->GetAPPBluetoothIsConnect();
+            bool aivoiceConnectState = model->GetAiVoiceConnectStatus();
 
-            if (netWork4GState && appBluetoothConnectState) // 1.当手表4G网络正常+与app连接正常
+            if (netWork4GState) // 1.手表4G网络正常
             {
-                // 通过4G调用大模型
+                if (aivoiceConnectState) /*如果模型是连接成功的*/
+                {
+                    // 通过4G调用大模型
+                }
+                else
+                {
+                    ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID);
+                }
             }
-            else if (netWork4GState && !appBluetoothConnectState) // 2.只有手表4G网络正常
+            else if (appBluetoothConnectState) // 3.只有与APP蓝牙连接正常
             {
-                // 通过4G调用大模型
+                if (aivoiceConnectState) /*如果模型是连接成功的*/
+                {
+                    // 通过蓝牙连接APP调用大模型
+                    ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_LISTENING_VIEWID);
+                }
+                else
+                {
+                    ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID);
+                }
             }
-            else if (!netWork4GState && appBluetoothConnectState) // 3.只有与APP蓝牙连接正常
-            {
-                // 通过蓝牙连接APP调用大模型
-                ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_LISTENING_VIEWID);
-            }
-            else if (!netWork4GState && !appBluetoothConnectState) // 4.两者连接都异常
+            else // 4.两者连接都异常
             {
                 // 返回错误
                 ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_ALERT_APPBLUETOOTH_AND_4GNETWORK_VIEWID);
                 // ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID);
             }
-
             return true;
         }
         else if (viewId == FINISH_SPEAKING_BUTTON_VIEW_ID) // 如果点击的是说话完毕按钮
index db2cccb..14404c1 100644 (file)
@@ -78,7 +78,7 @@ extern "C" {
 //在此处实现,给UI回复消息。
 void ble_app_reply(bool data)
 {
-
+    OHOS::AiVoiceModel::GetInstance().SetAiVoiceConnectStatus(data);
 }
 
 
index 99059ed..e0281d1 100644 (file)
@@ -278,7 +278,7 @@ namespace OHOS
         void SetisFirstTimeStart(bool value);
         bool GetisFirstTimeStart(void);
         /* ---------------------------- 设置OpenAI APIKeys ---------------------------- */
-        void SetOpenAIAPIKeys(char * value);
+        void SetOpenAIAPIKeys(const char * value);
         std::string GetOpenAIAPIKeys(void);
         /* --------------------------------- 用户配置信息 --------------------------------- */
         void SetUserAge(int age);
index 60c0fcd..6f93fc0 100644 (file)
@@ -1196,7 +1196,7 @@ namespace OHOS
     }
 
     /*设置API Keys*/
-    void ConfigModel::SetOpenAIAPIKeys(char * value)
+    void ConfigModel::SetOpenAIAPIKeys(const char * value)
     {
         set_condigData_String(CONFIGMODEL_ITEM_OPEN_AI_API_KEYS,value);
     }