diff --git a/base/cortex-common/cortexpythoni.h b/base/cortex-common/cortexpythoni.h new file mode 100644 index 0000000..377cbd9 --- /dev/null +++ b/base/cortex-common/cortexpythoni.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include + +#include "json/value.h" + +class CortexPythonEngineI { + public: + virtual ~CortexPythonEngineI() {} + + virtual bool IsSupported(const std::string& f) { + if (f == "ExecutePythonFile" || f == "HandlePythonFileExecutionRequest") { + return true; + } + return false; + } + + virtual void ExecutePythonFile(std::string binary_execute_path, + std::string file_execution_path, + std::string python_library_path) = 0; + + virtual void HandlePythonFileExecutionRequest( + std::shared_ptr json_body, + std::function&& callback) = 0; +}; diff --git a/base/cortex-common/enginei.h b/base/cortex-common/enginei.h deleted file mode 100644 index 9fc10a3..0000000 --- a/base/cortex-common/enginei.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include -#include - -#include "json/value.h" - -class EngineI { - public: - virtual ~EngineI() {} - - virtual void HandleChatCompletion( - std::shared_ptr json_body, - std::function&& callback) {} - virtual void HandleEmbedding( - std::shared_ptr json_body, - std::function&& callback) {} - virtual void LoadModel( - std::shared_ptr json_body, - std::function&& callback) {} - virtual void UnloadModel( - std::shared_ptr json_body, - std::function&& callback) {} - virtual void GetModelStatus( - std::shared_ptr json_body, - std::function&& callback) {} - - virtual void ExecutePythonFile(std::string binary_execute_path, - std::string file_execution_path, - std::string python_library_path) = 0; - - virtual void HandlePythonFileExecutionRequest( - std::shared_ptr json_body, - std::function&& callback) = 0; - - virtual bool IsSupported(const std::string& f) { - if (f == "ExecutePythonFile" || f == "HandlePythonFileExecutionRequest") { - return true; - } - return false; - } -}; diff --git a/examples/server/server.cc b/examples/server/server.cc index 65b206c..4219be8 100644 --- a/examples/server/server.cc +++ b/examples/server/server.cc @@ -9,14 +9,14 @@ #include "httplib.h" #include "json/reader.h" #include "json/forwards.h" -#include "base/cortex-common/enginei.h" +#include "base/cortex-common/cortexpythoni.h" #include "trantor/utils/Logger.h" class Server { public: Server() { dylib_ = std::make_unique("./engines/cortex.python", "engine"); - auto func = dylib_->get_function("get_engine"); + auto func = dylib_->get_function("get_engine"); engine_ = func(); } @@ -26,7 +26,7 @@ class Server { } } - EngineI* GetEngine() const { + CortexPythonEngineI* GetEngine() const { return engine_; } @@ -53,7 +53,7 @@ class Server { private: std::unique_ptr dylib_; - EngineI* engine_; + CortexPythonEngineI* engine_; }; diff --git a/src/python_engine.cc b/src/python_engine.cc index aed22a3..fb1cbdd 100644 --- a/src/python_engine.cc +++ b/src/python_engine.cc @@ -112,7 +112,7 @@ void PythonEngine::HandlePythonFileExecutionRequestImpl( }; extern "C" { -EngineI* get_engine() { +CortexPythonEngineI* get_engine() { return new PythonEngine(); } } // extern C diff --git a/src/python_engine.h b/src/python_engine.h index 3434482..0aa5c1d 100644 --- a/src/python_engine.h +++ b/src/python_engine.h @@ -2,11 +2,11 @@ #include #include -#include "base/cortex-common/enginei.h" +#include "base/cortex-common/cortexpythoni.h" #include "json/forwards.h" #include "src/python_file_execution_request.h" -class PythonEngine : public EngineI { +class PythonEngine : public CortexPythonEngineI { public: ~PythonEngine() final;