1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef I_AIP_CORE_MANAGER_H 16 #define I_AIP_CORE_MANAGER_H 17 18 #include <cstdint> 19 #include <functional> 20 #include <map> 21 #include <memory> 22 #include <string> 23 #include <variant> 24 #include <vector> 25 26 namespace OHOS { 27 namespace DataIntelligence { 28 struct ModelConfigData { 29 int32_t versionValue; 30 bool isNPUAvailableValue; 31 std::string cachePathValue; 32 }; 33 34 class IAipCoreManager { 35 public: 36 IAipCoreManager() = default; 37 virtual ~IAipCoreManager() = default; 38 39 virtual int32_t InitTextModel(const ModelConfigData &config) = 0; 40 virtual int32_t InitImageModel(const ModelConfigData &config) = 0; 41 virtual int32_t LoadTextModel() = 0; 42 virtual int32_t ReleaseTextModel() = 0; 43 virtual int32_t GetTextEmbedding(std::string file, std::vector<float> &results) = 0; 44 virtual int32_t GetTextEmbedding(const std::vector<std::string> &files, 45 std::vector<std::vector<float>> &results) = 0; 46 virtual int32_t LoadImageModel() = 0; 47 virtual int32_t ReleaseImageModel() = 0; 48 virtual int32_t GetImageEmbedding(std::string uri, std::vector<float> &results) = 0; 49 virtual int32_t SplitText(std::string text, int32_t size, float overlap, std::vector<std::string> &results) = 0; 50 virtual bool CheckDeviceType() = 0; 51 }; 52 53 struct AipCoreManagerHandle { 54 void *handle; 55 IAipCoreManager *(*create)(); 56 void (*destroy)(const IAipCoreManager *); 57 IAipCoreManager *pAipManager; AipCoreManagerHandleAipCoreManagerHandle58 AipCoreManagerHandle() : handle(nullptr), create(nullptr), destroy(nullptr), pAipManager(nullptr) {} ~AipCoreManagerHandleAipCoreManagerHandle59 ~AipCoreManagerHandle() {} ClearAipCoreManagerHandle60 void Clear() 61 { 62 handle = nullptr; 63 create = nullptr; 64 destroy = nullptr; 65 pAipManager = nullptr; 66 } 67 }; 68 } // namespace DataIntelligence 69 } // namespace OHOS 70 71 #endif // I_AIP_CORE_MANAGER_H