| 1 | /* |
| 2 | * Copyright 2024 KylinSoft Co., Ltd. |
| 3 | * |
| 4 | * This program is free software: you can redistribute it and/or modify it under |
| 5 | * the terms of the GNU General Public License as published by the Free Software |
| 6 | * Foundation, either version 3 of the License, or (at your option) any later |
| 7 | * version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 11 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 12 | * details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
| 18 | #ifndef XUNFEINLPENGINE_P_H |
| 19 | #define XUNFEINLPENGINE_P_Hcxx . . $ `xunfei/nlp/xunfeinlpengine_p.h:19:9`! |
| 20 | |
| 21 | #include <atomic> |
| 22 | #include <cstdint> |
| 23 | #include <mutex> |
| 24 | #include <curl/curl.h> |
| 25 | #include <jsoncpp/json/json.h> |
| 26 | #include <kylin-ai/ai-engine/aiengineerror.h> |
| 27 | #include <kylin-ai/ai-engine/textgenerationengine.h> |
| 28 | |
| 29 | class XunfeiNlpEnginePrivatecxx . . $ XunfeiNlpEnginePrivate# { |
| 30 | public: |
| 31 | XunfeiNlpEnginePrivatecxx . . $ XunfeiNlpEnginePrivate#XunfeiNlpEnginePrivate(49f6e7a06ebc5aa8).(); |
| 32 | ~cxx . . $ XunfeiNlpEnginePrivate#`~XunfeiNlpEnginePrivate`(ced63f7c635d850d).XunfeiNlpEnginePrivatecxx . . $ XunfeiNlpEnginePrivate#(); |
| 33 | stdcxx . . $ std/::stringcxx . . $ std/string# engineNamecxx . . $ XunfeiNlpEnginePrivate#engineName(219584694fe2b248).() const; |
| 34 | bool isCloudcxx . . $ XunfeiNlpEnginePrivate#isCloud(50ce9a9e25b4a850).() const { return true; } |
| 35 | bool isBuiltInEnginecxx . . $ XunfeiNlpEnginePrivate#isBuiltInEngine(50ce9a9e25b4a850).() const { return false; } |
| 36 | bool isCustomModelEnginecxx . . $ XunfeiNlpEnginePrivate#isCustomModelEngine(50ce9a9e25b4a850).() const { return false; } |
| 37 | |
| 38 | void setConfigcxx . . $ XunfeiNlpEnginePrivate#setConfig(9c546c94e5fcce4e).(const stdcxx . . $ std/::stringcxx . . $ std/string# &config); |
| 39 | bool setCurrentModelcxx . . $ XunfeiNlpEnginePrivate#setCurrentModel(7c222eea44a24d43).(const stdcxx . . $ std/::stringcxx . . $ std/string# &model); |
| 40 | stdcxx . . $ std/::stringcxx . . $ std/string# currentModelcxx . . $ XunfeiNlpEnginePrivate#currentModel(219584694fe2b248).() const { return currentModel_cxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).; } |
| 41 | stdcxx . . $ std/::stringcxx . . $ std/string# currentModelNamecxx . . $ XunfeiNlpEnginePrivate#currentModelName(219584694fe2b248).() const { return currentModelName_cxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).; } |
| 42 | stdcxx . . $ std/::stringcxx . . $ std/string# modelInfocxx . . $ XunfeiNlpEnginePrivate#modelInfo(219584694fe2b248).() const; |
| 43 | |
| 44 | void setTextGenerationResultCallbackcxx . . $ XunfeiNlpEnginePrivate#setTextGenerationResultCallback(fa79cbe2cad9eeeb).(const ai_enginecxx . . $ ai_engine/::gen_aicxx . . $ ai_engine/gen_ai/::nlpcxx . . $ ai_engine/gen_ai/nlp/::TextGenerationResultCallbackcxx . . $ ai_engine/gen_ai/nlp/TextGenerationResultCallback# &callback); |
| 45 | |
| 46 | ai_enginecxx . . $ ai_engine/::resultcxx . . $ ai_engine/result/::AiEngineBaseResultcxx . . $ ai_engine/result/AiEngineBaseResult# generateContentcxx . . $ XunfeiNlpEnginePrivate#generateContent(5ca096d5e05eb23e).(const stdcxx . . $ std/::stringcxx . . $ std/string# &input); |
| 47 | ai_enginecxx . . $ ai_engine/::resultcxx . . $ ai_engine/result/::AiEngineBaseResultcxx . . $ ai_engine/result/AiEngineBaseResult# chatcxx . . $ XunfeiNlpEnginePrivate#chat(5ca096d5e05eb23e).(const stdcxx . . $ std/::stringcxx . . $ std/string# &message); |
| 48 | void stopGenerateContentcxx . . $ XunfeiNlpEnginePrivate#stopGenerateContent(49f6e7a06ebc5aa8).(); |
| 49 | void stopChatcxx . . $ XunfeiNlpEnginePrivate#stopChat(49f6e7a06ebc5aa8).(); |
| 50 | |
| 51 | ai_enginecxx . . $ ai_engine/::resultcxx . . $ ai_engine/result/::AiEngineBaseResultcxx . . $ ai_engine/result/AiEngineBaseResult# initcxx . . $ XunfeiNlpEnginePrivate#init(970480d1225e20c7).(); |
| 52 | ai_enginecxx . . $ ai_engine/::resultcxx . . $ ai_engine/result/::AiEngineBaseResultcxx . . $ ai_engine/result/AiEngineBaseResult# destroycxx . . $ XunfeiNlpEnginePrivate#destroy(970480d1225e20c7).(); |
| 53 | |
| 54 | private: |
| 55 | void threadSafeCallChatResultCallbackcxx . . $ XunfeiNlpEnginePrivate#threadSafeCallChatResultCallback(ba46d6147aa4396f).(const ai_enginecxx . . $ ai_engine/::gen_aicxx . . $ ai_engine/gen_ai/::nlpcxx . . $ ai_engine/gen_ai/nlp/::TextGenerationResultcxx . . $ ai_engine/gen_ai/nlp/TextGenerationResult# &result) const; |
| 56 | |
| 57 | void handleReceiveDatacxx . . $ XunfeiNlpEnginePrivate#handleReceiveData(49f6e7a06ebc5aa8).(); |
| 58 | stdcxx . . $ std/::stringcxx . . $ std/string# receiveChatDatacxx . . $ XunfeiNlpEnginePrivate#receiveChatData(10b19e2b93eb7af2).(int *retCode) const; |
| 59 | bool isNetworkErrorcxx . . $ XunfeiNlpEnginePrivate#isNetworkError(4a668f6de69bf818).(int retCode) const; |
| 60 | bool isChatDataReadycxx . . $ XunfeiNlpEnginePrivate#isChatDataReady(4a668f6de69bf818).(int retCode) const; |
| 61 | bool needReReceiveDatacxx . . $ XunfeiNlpEnginePrivate#needReReceiveData(4a668f6de69bf818).(int retCode) const; |
| 62 | |
| 63 | void handleNetworkErrorcxx . . $ XunfeiNlpEnginePrivate#handleNetworkError(d4f767463ce0a6b3).(int retCode); |
| 64 | void handleServerErrorcxx . . $ XunfeiNlpEnginePrivate#handleServerError(448e1223d74ef93).(int errorCode, const stdcxx . . $ std/::stringcxx . . $ std/string# &errorMessage); |
| 65 | void handleChatDatacxx . . $ XunfeiNlpEnginePrivate#handleChatData(3ac5d33af3717a67).(const stdcxx . . $ std/::stringcxx . . $ std/string# &chatData, bool *isFinished); |
| 66 | |
| 67 | void decreaseChatCountercxx . . $ XunfeiNlpEnginePrivate#decreaseChatCounter(49f6e7a06ebc5aa8).(); |
| 68 | void increaseChatCountercxx . . $ XunfeiNlpEnginePrivate#increaseChatCounter(49f6e7a06ebc5aa8).(); |
| 69 | bool isChatRunningcxx . . $ XunfeiNlpEnginePrivate#isChatRunning(50ce9a9e25b4a850).() const; |
| 70 | |
| 71 | CURLcode testConnectToServercxx . . $ XunfeiNlpEnginePrivate#testConnectToServer(111a7e8334dc76b4).(); |
| 72 | void addContextcxx . . $ XunfeiNlpEnginePrivate#addContext(c3ca1c130ce09c52).(const stdcxx . . $ std/::stringcxx . . $ std/string# &role, const stdcxx . . $ std/::stringcxx . . $ std/string# &content); |
| 73 | ai_enginecxx . . $ ai_engine/::resultcxx . . $ ai_engine/result/::AiEngineBaseResultcxx . . $ ai_engine/result/AiEngineBaseResult# buildChatMessagecxx . . $ XunfeiNlpEnginePrivate#buildChatMessage(5ca096d5e05eb23e).(const stdcxx . . $ std/::stringcxx . . $ std/string# &message); |
| 74 | |
| 75 | private: |
| 76 | stdcxx . . $ std/::stringcxx . . $ std/string# appId_cxx . . $ XunfeiNlpEnginePrivate#appId_.; |
| 77 | stdcxx . . $ std/::stringcxx . . $ std/string# apiKey_cxx . . $ XunfeiNlpEnginePrivate#apiKey_.; |
| 78 | stdcxx . . $ std/::stringcxx . . $ std/string# secretKey_cxx . . $ XunfeiNlpEnginePrivate#secretKey_.; |
| 79 | stdcxx . . $ std/::stringcxx . . $ std/string# currentModel_cxx . . $ XunfeiNlpEnginePrivate#currentModel_.{cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)."generalv3.5"}; |
| 80 | stdcxx . . $ std/::stringcxx . . $ std/string# currentModelName_cxx . . $ XunfeiNlpEnginePrivate#currentModelName_.{cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)."讯飞-Spark Max"}; |
| 81 | stdcxx . . $ std/::stringcxx . . $ std/string# hostUrl_cxx . . $ XunfeiNlpEnginePrivate#hostUrl_.{cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)."wss://spark-api.xf-yun.com/v3.5/chat"}; |
| 82 | int maxTokens_cxx . . $ XunfeiNlpEnginePrivate#maxTokens_.; |
| 83 | |
| 84 | mutable stdcxx . . $ std/::mutexcxx . . $ std/mutex# mutex_cxx . . $ XunfeiNlpEnginePrivate#mutex_.; |
| 85 | ai_enginecxx . . $ ai_engine/::gen_aicxx . . $ ai_engine/gen_ai/::nlpcxx . . $ ai_engine/gen_ai/nlp/::TextGenerationResultCallbackcxx . . $ ai_engine/gen_ai/nlp/TextGenerationResultCallback# textGenerationResultCallback_cxx . . $ XunfeiNlpEnginePrivate#textGenerationResultCallback_.{cxx . . $ std/function#function(6d988fd07f070dfc).nullptr}; |
| 86 | |
| 87 | Jsoncxx . . $ Json/::Valuecxx . . $ Json/Value# context_cxx . . $ XunfeiNlpEnginePrivate#context_.; |
| 88 | void clearContextcxx . . $ XunfeiNlpEnginePrivate#clearContext(49f6e7a06ebc5aa8).(); |
| 89 | void removeLastContextcxx . . $ XunfeiNlpEnginePrivate#removeLastContext(49f6e7a06ebc5aa8).(); |
| 90 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<Jsoncxx . . $ Json/::Valuecxx . . $ Json/Value#> streamChatData_cxx . . $ XunfeiNlpEnginePrivate#streamChatData_.; |
| 91 | |
| 92 | bool connectWebsocketcxx . . $ XunfeiNlpEnginePrivate#connectWebsocket(7c222eea44a24d43).(const stdcxx . . $ std/::stringcxx . . $ std/string# &hostUrl); |
| 93 | void closeWebsocketcxx . . $ XunfeiNlpEnginePrivate#closeWebsocket(49f6e7a06ebc5aa8).(); |
| 94 | |
| 95 | CURL *currentCurl_cxx . . $ XunfeiNlpEnginePrivate#currentCurl_.{nullptr}; |
| 96 | ai_enginecxx . . $ ai_engine/::EngineErrorcxx . . $ ai_engine/EngineError# currentError_cxx . . $ XunfeiNlpEnginePrivate#currentError_.; |
| 97 | |
| 98 | bool initResourcescxx . . $ XunfeiNlpEnginePrivate#initResources(c9857a73d68e59ba).(); |
| 99 | void releaseResourcescxx . . $ XunfeiNlpEnginePrivate#releaseResources(49f6e7a06ebc5aa8).(); |
| 100 | |
| 101 | bool doSendDatacxx . . $ XunfeiNlpEnginePrivate#doSendData(7516fa0aaae73faa).(const char *data, int dataLength, int type); |
| 102 | int getMaxTokenscxx . . $ XunfeiNlpEnginePrivate#getMaxTokens(7787e0c995c81e02).(const stdcxx . . $ std/::stringcxx . . $ std/string# &model); |
| 103 | |
| 104 | bool waitForStoppedcxx . . $ XunfeiNlpEnginePrivate#waitForStopped(c9857a73d68e59ba).(); |
| 105 | stdcxx . . $ std/::atomiccxx . . $ std/atomic#<bool> isStopped_cxx . . $ XunfeiNlpEnginePrivate#isStopped_.{cxx . . $ std/atomic#atomic(9f0ba574c1c44ffc).false}; |
| 106 | stdcxx . . $ std/::atomiccxx . . $ std/atomic#<int> chatCounter_cxx . . $ XunfeiNlpEnginePrivate#chatCounter_.{cxx . . $ std/atomic#atomic(f349c77f591a7878).0}; |
| 107 | }; |
| 108 | |
| 109 | #endif // XUNFEINLPENGINE_P_H |