diff --git a/.gitignore b/.gitignore index 287785ec4b82a12994e0c36f9e233585c6dc6f64..efe751045549f04a9aca2e6bb84361ea4806c188 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,9 @@ .vscode/ !build -config.yaml .DS_Store topology/pkg/ -topology/build \ No newline at end of file +topology/build +*.yaml +# python build cache +__pycache__ \ No newline at end of file diff --git a/llmops/app_factory.py b/llmops/app_factory.py new file mode 100644 index 0000000000000000000000000000000000000000..9d8eeff59ac61023564888dedaf7c5639503e9c6 --- /dev/null +++ b/llmops/app_factory.py @@ -0,0 +1,27 @@ +from flask import Flask +from config.config import init_config + + +def create_app() -> Flask: + app = Flask(__name__) + + # 初始化http服务 + config = init_config() + app.config["SERVER"] = config.app_conf.server + app.config["PORT"] = config.app_conf.port + app.config["DEBUG"] = config.app_conf.debug + + return app + + +def run_app(): + app = create_app() + try: + app.run( + host=app.config["SERVER"], + port=int(app.config["PORT"]), + debug=app.config["DEBUG"], + ) + except ValueError as e: + app.logger.error(f"Invalid app config: {e}") + exit(1) diff --git a/llmops/config/config.py b/llmops/config/config.py new file mode 100644 index 0000000000000000000000000000000000000000..7b8e00c5677dd8ae7fc9a95cfc7ebd9aadc81d2b --- /dev/null +++ b/llmops/config/config.py @@ -0,0 +1,35 @@ +import os +import yaml +from dataclasses import dataclass + + +@dataclass +class AppConf: + server: str + port: str + debug: bool + + +class Config: + filename = "../llm-ops.yaml" + + def __init__(self): + self.app_conf: AppConf = None + + def load_config(self): + current_dir = os.path.dirname(os.path.abspath(__file__)) + config_path = os.path.join(current_dir, self.filename) + + try: + with open(config_path, "r") as f: + conf = yaml.safe_load(f) + except IOError as e: + raise ValueError("Load llm-ops config file failed") from e + + self.app_conf = AppConf(**conf["app"]) + + +def init_config() -> Config: + conf = Config() + conf.load_config() + return conf diff --git a/llmops/llm-ops.yaml.template b/llmops/llm-ops.yaml.template new file mode 100644 index 0000000000000000000000000000000000000000..4dc7944da36dbb068ff56998ca6a0065397b9e11 --- /dev/null +++ b/llmops/llm-ops.yaml.template @@ -0,0 +1,4 @@ +app: + server: localhost + port: 5000 + debug: true \ No newline at end of file diff --git a/llmops/main.py b/llmops/main.py new file mode 100644 index 0000000000000000000000000000000000000000..f2a0ca047ac629f4172edc8c8ae7699c93089763 --- /dev/null +++ b/llmops/main.py @@ -0,0 +1,4 @@ +from app_factory import run_app + +if __name__ == "__main__": + run_app()