From 1eb751efe917419fea95a4a9439f1695b2dab5ac Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Thu, 1 Aug 2024 17:42:30 +0800 Subject: [PATCH] =?utf8?q?AI=E8=AF=AD=E9=9F=B3=E6=B7=BB=E5=8A=A0=E6=9F=A5?= =?utf8?q?=E8=AF=A2=E9=80=89=E6=8B=A9=E7=9A=84=E6=A8=A1=E5=9E=8B=E6=98=AF?= =?utf8?q?=E5=90=A6=E5=8F=AF=E7=94=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/aivoice/include/AiVoiceModel.h | 5 ++- .../nativeui/aivoice/src/AiVoiceModel.cpp | 32 +++++++++++++--- .../nativeui/aivoice/src/AiVoicePresenter.cpp | 37 +++++++++++++------ .../service/ble_service/blemoder/bletest.cpp | 2 +- .../peripheral/config/include/ConfigModel.h | 2 +- .../peripheral/config/src/ConfigModel.cpp | 2 +- 6 files changed, 59 insertions(+), 21 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h index a0279934a..034254842 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h @@ -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> selectAiModelToTextId; + bool AiVoiceConnectStatus{false}; //与AI模型的连接状态 }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp index a5b18d200..ea95c967f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp @@ -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); diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp index 0cfa13ee9..95c8ed63e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp @@ -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) // 如果点击的是说话完毕按钮 diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp index db2cccbec..14404c16b 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -78,7 +78,7 @@ extern "C" { //在此处实现,给UI回复消息。 void ble_app_reply(bool data) { - + OHOS::AiVoiceModel::GetInstance().SetAiVoiceConnectStatus(data); } diff --git a/code/sdk/drivers/peripheral/config/include/ConfigModel.h b/code/sdk/drivers/peripheral/config/include/ConfigModel.h index 99059edf7..e0281d1e3 100644 --- a/code/sdk/drivers/peripheral/config/include/ConfigModel.h +++ b/code/sdk/drivers/peripheral/config/include/ConfigModel.h @@ -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); diff --git a/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp b/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp index 60c0fcdd7..6f93fc085 100644 --- a/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp +++ b/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp @@ -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); } -- 2.17.1