diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b0daf62..14fb4ab 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -25,11 +25,6 @@ jobs: pip install build; continue-on-error: false - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: 20 - - name: Build the module env: PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} diff --git a/guardrails_api/app.py b/guardrails_api/app.py index 366096c..088d172 100644 --- a/guardrails_api/app.py +++ b/guardrails_api/app.py @@ -47,7 +47,7 @@ def register_config(config: Optional[str] = None): SourceFileLoader("config", config_file_path).load_module() -def create_app(env: Optional[str] = None, config: Optional[str] = None): +def create_app(env: Optional[str] = None, config: Optional[str] = None, port: Optional[int] = None): if os.environ.get("APP_ENVIRONMENT") != "production": from dotenv import load_dotenv @@ -56,6 +56,11 @@ def create_app(env: Optional[str] = None, config: Optional[str] = None): env_file_path = os.path.abspath(env_file) load_dotenv(env_file_path) + set_port = port or os.environ.get("PORT", 8000) + host = os.environ.get("HOST", "http://localhost") + self_endpoint = os.environ.get("SELF_ENDPOINT", f"{host}:{set_port}") + os.environ["SELF_ENDPOINT"] = self_endpoint + register_config(config) app = Flask(__name__) diff --git a/guardrails_api/cli/start.py b/guardrails_api/cli/start.py index d686621..0fe995c 100644 --- a/guardrails_api/cli/start.py +++ b/guardrails_api/cli/start.py @@ -29,12 +29,22 @@ def start( env: Optional[str] = typer.Option( default="", help="An env file to load environment variables from.", - prompt=".env file (optional)", ), config: Optional[str] = typer.Option( default="", help="A config file to load Guards from.", - prompt="config file (optional)", + ), + timeout: Optional[int] = typer.Option( + default=5, + help="Gunicorn worker timeout.", + ), + threads: Optional[int] = typer.Option( + default=10, + help="Number of Gunicorn worker threads.", + ), + port: Optional[int] = typer.Option( + default=8000, + help="The port to run the server on.", ), ): # TODO: If these are empty, @@ -43,8 +53,8 @@ def start( config = config or None options = { - "bind": "0.0.0.0:8000", - "timeout": 5, - "threads": 10, + "bind": f"0.0.0.0:{port}", + "timeout": timeout, + "threads": threads, } - StandaloneApplication(create_app(env, config), options).run() + StandaloneApplication(create_app(env, config, port), options).run() diff --git a/guardrails_api/clients/cache_client.py b/guardrails_api/clients/cache_client.py index f910834..e24bcb5 100644 --- a/guardrails_api/clients/cache_client.py +++ b/guardrails_api/clients/cache_client.py @@ -15,9 +15,8 @@ def initialize(self, app): self.cache = Cache( app, config={ - "CACHE_TYPE": "simple", + "CACHE_TYPE": "SimpleCache", "CACHE_DEFAULT_TIMEOUT": 300, - "CACHE_NO_NULL_WARNING": True, "CACHE_THRESHOLD": 50 } ) diff --git a/guardrails_api/default.env b/guardrails_api/default.env index 674906a..6e37d0b 100644 --- a/guardrails_api/default.env +++ b/guardrails_api/default.env @@ -3,5 +3,6 @@ PYTHONUNBUFFERED=1 LOGLEVEL="INFO" GUARDRAILS_LOG_LEVEL="INFO" GUARDRAILS_PROCESS_COUNT=1 -SELF_ENDPOINT=http://localhost:8000 +HOST=http://localhost +PORT=8000 OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES \ No newline at end of file