From e40ea3e2a9f205c2815b881b6afd2f391c1164ff Mon Sep 17 00:00:00 2001 From: Luca Beurer-Kellner Date: Tue, 11 Mar 2025 17:38:41 +0100 Subject: [PATCH] instructions + port configuration option --- README.md | 27 +++++++++++++++++++++++++-- gateway/.env | 4 ++++ gateway/common/config_manager.py | 2 +- gateway/run.sh | 7 +++++-- gateway/validate_config.py | 2 +- 5 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 gateway/.env diff --git a/README.md b/README.md index 36fd212..8816f52 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ To add Gateway to your agentic system, follow one of the integration guides belo ## **Integration Guides** ### **🔹 OpenAI Integration** + Gateway supports the OpenAI Chat Completions API (`/v1/chat/completions` endpoint). 1. Follow [these steps](https://platform.openai.com/docs/quickstart#create-and-export-an-api-key) to obtain an OpenAI API key. @@ -62,6 +63,7 @@ Gateway supports the OpenAI Chat Completions API (`/v1/chat/completions` endpoin > **Note:** Do not include the curly braces `{}`. If the dataset does not exist in Invariant Explorer, it will be created before adding traces. ### **🔹 Anthropic Integration** + Gateway supports the Anthropic Messages API (`/v1/messages` endpoint). 1. Follow [these steps](https://docs.anthropic.com/en/docs/initial-setup#set-your-api-key) to obtain an Anthropic API key. @@ -84,6 +86,7 @@ Gateway supports the Anthropic Messages API (`/v1/messages` endpoint). > **Note:** Do not include the curly braces `{}`. If the dataset does not exist in Invariant Explorer, it will be created before adding traces. ### **🔹 Gemini Integration** + Gateway supports the Gemini `generateContent` and `streamGenerateContent` methods. 1. Follow [these steps](https://ai.google.dev/gemini-api/docs/api-key) to obtain a Gemini API key. @@ -91,7 +94,7 @@ Gateway supports the Gemini `generateContent` and `streamGenerateContent` method ```python import os - + from google import genai client = genai.Client( @@ -249,14 +252,34 @@ This setup ensures that SWE-agent works seamlessly with Invariant Gateway, maint You can also operate your own instance of the Gateway, to ensure privacy and security. -First, clone this repository. To start the Invariant Gateway, run: +To run Gateway locally, you have two options: + +### 1. Run gateway from the repository + +1. Clone this repository. + +2. To start the Invariant Gateway, then run the following commands. Note that you need to have Docker installed. ```bash +cd invariant-gateway bash run.sh build && bash run.sh up ``` This will launch Gateway at [http://localhost:8005/api/v1/gateway/](http://localhost:8005/api/v1/gateway/docs/). +### 2. Run the Gateway using the published Docker image + +You can also run the Gateway using the published Docker image. This is a good option if you want to run the Gateway in a cloud environment. + +```bash +# pull the latest image +docker pull ghcr.io/invariantlabs-ai/invariant-gateway:latest +# run Gateway on localhost:8002 +docker run -p 8002:8002 -e PORT=8002 ghcr.io/invariantlabs-ai/invariant-gateway:latest +``` + +This will launch Gateway at [http://localhost:8002/api/v1/gateway/](http://localhost:8002/api/v1/gateway/docs/). + ### **Set Up an Invariant API Key** 1. Follow the instructions [here](https://explorer.invariantlabs.ai/docs/explorer/api/client-setup/) to obtain an API key. This allows the gateway to push traces to [Invariant Explorer](https://explorer.invariantlabs.ai). diff --git a/gateway/.env b/gateway/.env new file mode 100644 index 0000000..78d3391 --- /dev/null +++ b/gateway/.env @@ -0,0 +1,4 @@ +POSTGRES_USER=postgres + POSTGRES_PASSWORD=postgres + POSTGRES_DB=invariantmonitor + POSTGRES_HOST=database \ No newline at end of file diff --git a/gateway/common/config_manager.py b/gateway/common/config_manager.py index 09c5904..7bdb3e2 100644 --- a/gateway/common/config_manager.py +++ b/gateway/common/config_manager.py @@ -20,7 +20,7 @@ class GatewayConfig: policies_file = os.getenv("POLICIES_FILE_PATH", "") if not policies_file: - print("Warning: POLICIES_FILE_PATH is not set. Using empty policies.") + print("[warning: POLICIES_FILE_PATH is not set. Using empty policies]") return "" try: diff --git a/gateway/run.sh b/gateway/run.sh index fe6570a..ebc4b1b 100755 --- a/gateway/run.sh +++ b/gateway/run.sh @@ -9,10 +9,13 @@ if [ $? -ne 0 ]; then exit 1 fi +# check if PORT environment variable is set +UVICORN_PORT=${PORT:-8000} + # using 'exec' belows ensures that signals like SIGTERM are passed to the child process # and not the shell script itself (important when running in a container) if [ "$DEV_MODE" = "true" ]; then - exec uvicorn serve:app --host 0.0.0.0 --port 8000 --reload + exec uvicorn serve:app --host 0.0.0.0 --port $UVICORN_PORT --reload else - exec uvicorn serve:app --host 0.0.0.0 --port 8000 + exec uvicorn serve:app --host 0.0.0.0 --port $UVICORN_PORT fi \ No newline at end of file diff --git a/gateway/validate_config.py b/gateway/validate_config.py index 4d13c89..99a24bb 100644 --- a/gateway/validate_config.py +++ b/gateway/validate_config.py @@ -6,7 +6,7 @@ from common.config_manager import GatewayConfigManager try: _ = GatewayConfigManager.get_config() - print("GatewayConfig validated successfully.") + print("[gateway config validated successfully]") sys.exit(0) except Exception as e: print(f"Error loading GatewayConfig error: {e}")