diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ca847f0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,51 @@ +FROM public.ecr.aws/docker/library/python:3.12-slim + +# Accept a build arg for the Guardrails token +# We'll add this to the config using the configure command below +# ARG GUARDRAILS_TOKEN + +# Create app directory +WORKDIR /app + +# print the version just to verify +RUN python3 --version +# start the virtual environment +RUN python3 -m venv /opt/venv + +# Enable venv +ENV PATH="/opt/venv/bin:$PATH" + +# Install some utilities; you may not need all of these +RUN apt-get update +RUN apt-get install -y git + +# Copy the requirements file +COPY requirements*.txt . + +# Install app dependencies +# If you use Poetry this step might be different +RUN pip install -r requirements-lock.txt + +# Set the directory for nltk data +ENV NLTK_DATA=/opt/nltk_data + +# Download punkt data +RUN python -m nltk.downloader -d /opt/nltk_data punkt + +# Run the Guardrails configure command to create a .guardrailsrc file +# RUN guardrails configure --enable-metrics --enable-remote-inferencing --token $GUARDRAILS_TOKEN + +# Install any validators from the hub you want +RUN guardrails hub install hub://guardrails/valid_length + +# Copy the rest over +# We use a .dockerignore to keep unwanted files exluded +COPY . . + +EXPOSE 8000 + +# This is our start command; yours might be different. +# The guardrails-api is a standard Flask application. +# You can use whatever production server you want that support Flask. +# Here we use gunicorn +CMD gunicorn --bind 0.0.0.0:8000 --timeout=90 --workers=2 'guardrails_api.app:create_app(".env", "sample-config.py")' \ No newline at end of file diff --git a/Makefile b/Makefile index 73a27b9..280ed28 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ install-dev: pip install ".[dev]"; lock: - pip freeze --exclude guardrails-api-client > requirements-lock.txt + pip freeze --exclude guardrails-api > requirements-lock.txt install-lock: pip install -r requirements-lock.txt diff --git a/compose.yml b/compose.yml index 0166940..b445876 100644 --- a/compose.yml +++ b/compose.yml @@ -33,29 +33,29 @@ services: image: guardrails-api:latest build: context: . - dockerfile: Dockerfile.dev + dockerfile: Dockerfile args: PORT: "8000" ports: - "8000:8000" environment: - APP_ENVIRONMENT: local - AWS_PROFILE: dev - AWS_DEFAULT_REGION: us-east-1 - PGPORT: 5432 - PGDATABASE: postgres - PGHOST: postgres - PGUSER: ${PGUSER:-postgres} - PGPASSWORD: ${PGPASSWORD:-changeme} + # APP_ENVIRONMENT: local + # AWS_PROFILE: dev + # AWS_DEFAULT_REGION: us-east-1 + # PGPORT: 5432 + # PGDATABASE: postgres + # PGHOST: postgres + # PGUSER: ${PGUSER:-postgres} + # PGPASSWORD: ${PGPASSWORD:-changeme} NLTK_DATA: /opt/nltk_data - OTEL_PYTHON_TRACER_PROVIDER: sdk_tracer_provider - OTEL_SERVICE_NAME: guardrails-api - OTEL_EXPORTER_OTLP_ENDPOINT: http://otel-collector:4317 - OTEL_TRACES_EXPORTER: otlp #,console - OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST: "Accept-Encoding,User-Agent,Referer" - OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE: "Last-Modified,Content-Type" - OTEL_METRICS_EXPORTER: otlp #,console - OTEL_EXPORTER_OTLP_PROTOCOL: grpc + # OTEL_PYTHON_TRACER_PROVIDER: sdk_tracer_provider + # OTEL_SERVICE_NAME: guardrails-api + # OTEL_EXPORTER_OTLP_ENDPOINT: http://otel-collector:4317 + # OTEL_TRACES_EXPORTER: otlp #,console + # OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST: "Accept-Encoding,User-Agent,Referer" + # OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE: "Last-Modified,Content-Type" + # OTEL_METRICS_EXPORTER: otlp #,console + # OTEL_EXPORTER_OTLP_PROTOCOL: grpc # # Disable logging for now to reduce noise # OTEL_LOGS_EXPORTER: otlp,console # OTEL_PYTHON_LOG_CORRELATION: true @@ -68,9 +68,9 @@ services: # OTEL_EXPORTER_OTLP_METRICS_ENDPOINT: http://otel-collector:4317 # OTEL_EXPORTER_OTLP_LOGS_ENDPOINT: http://otel-collector:4317 # OTEL_PYTHON_LOG_FORMAT: "%(msg)s [span_id=%(span_id)s]" - depends_on: - - postgres - - otel-collector + # depends_on: + # - postgres + # - otel-collector opensearch-node1: profiles: ["all", "otel", "infra"] image: opensearchproject/opensearch:latest diff --git a/configs/otel-collector-config.yml b/configs/otel-collector-config.yml index a1378c2..b4e1138 100644 --- a/configs/otel-collector-config.yml +++ b/configs/otel-collector-config.yml @@ -2,7 +2,9 @@ receivers: otlp: protocols: grpc: - # http: + endpoint: 0.0.0.0:4317 + http: + endpoint: 0.0.0.0:4318 processors: batch: diff --git a/requirements-lock.txt b/requirements-lock.txt index c03e008..16b3f43 100644 --- a/requirements-lock.txt +++ b/requirements-lock.txt @@ -5,19 +5,18 @@ anyio==4.4.0 arrow==1.3.0 attrs==23.2.0 blinker==1.8.2 -boto3==1.34.132 -botocore==1.34.132 +boto3==1.34.149 +botocore==1.34.149 cachelib==0.9.0 certifi==2024.7.4 -cffi==1.16.0 charset-normalizer==3.3.2 click==8.1.7 colorama==0.4.6 coloredlogs==15.0.1 -cryptography==42.0.8 +coverage==7.6.0 Deprecated==1.2.14 distro==1.9.0 -Faker==25.9.1 +Faker==25.9.2 filelock==3.15.4 Flask==3.0.3 Flask-Caching==2.3.0 @@ -25,22 +24,21 @@ Flask-Cors==4.0.1 Flask-SQLAlchemy==3.1.1 fqdn==1.5.1 frozenlist==1.4.1 -fsspec==2024.6.0 +fsspec==2024.6.1 googleapis-common-protos==1.63.2 griffe==0.36.9 -grpcio==1.64.1 -guardrails-ai==0.5.0a2 -guardrails-api @ file:///Users/calebcourier/Projects/gr-mono/guardrails-cdk/guardrails-api -guardrails-api-client==0.3.8 +grpcio==1.65.1 +guardrails-ai==0.5.1 +guardrails-api-client==0.3.9 gunicorn==22.0.0 h11==0.14.0 httpcore==1.0.5 httpx==0.27.0 -huggingface-hub==0.23.4 +huggingface-hub==0.24.2 humanfriendly==10.0 idna==3.7 -ijson==3.3.0 -importlib_metadata==7.1.0 +importlib_metadata==8.0.0 +iniconfig==2.0.0 isoduration==20.11.0 itsdangerous==2.2.0 Jinja2==3.1.4 @@ -49,39 +47,41 @@ joblib==1.4.2 jsonpatch==1.33 jsonpointer==3.0.0 jsonref==1.1.0 -jsonschema==4.22.0 +jsonschema==4.23.0 jsonschema-specifications==2023.12.1 -jwt==1.3.1 -langchain-core==0.2.9 -langsmith==0.1.82 -litellm==1.40.25 +langchain-core==0.2.23 +langsmith==0.1.93 +litellm==1.42.3 lxml==4.9.4 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 multidict==6.0.5 nltk==3.8.1 -openai==1.35.3 -opentelemetry-api==1.25.0 -opentelemetry-exporter-otlp-proto-common==1.25.0 -opentelemetry-exporter-otlp-proto-grpc==1.25.0 -opentelemetry-exporter-otlp-proto-http==1.25.0 -opentelemetry-instrumentation==0.46b0 -opentelemetry-instrumentation-flask==0.46b0 -opentelemetry-instrumentation-wsgi==0.46b0 -opentelemetry-proto==1.25.0 -opentelemetry-sdk==1.25.0 -opentelemetry-semantic-conventions==0.46b0 -opentelemetry-util-http==0.46b0 -orjson==3.10.5 +openai==1.37.1 +opentelemetry-api==1.26.0 +opentelemetry-exporter-otlp-proto-common==1.26.0 +opentelemetry-exporter-otlp-proto-grpc==1.26.0 +opentelemetry-exporter-otlp-proto-http==1.26.0 +opentelemetry-instrumentation==0.47b0 +opentelemetry-instrumentation-flask==0.47b0 +opentelemetry-instrumentation-wsgi==0.47b0 +opentelemetry-proto==1.26.0 +opentelemetry-sdk==1.26.0 +opentelemetry-semantic-conventions==0.47b0 +opentelemetry-util-http==0.47b0 +orjson==3.10.6 packaging==24.1 -protobuf==4.25.3 +pluggy==1.5.0 +protobuf==4.25.4 psycopg2-binary==2.9.9 -pycparser==2.22 -pydantic==2.7.4 -pydantic_core==2.18.4 +pydantic==2.8.2 +pydantic_core==2.20.1 pydash==7.0.7 Pygments==2.18.0 +PyJWT==2.8.0 +pytest==8.3.2 +pytest-mock==3.14.0 python-dateutil==2.9.0.post0 python-dotenv==1.0.1 PyYAML==6.0.1 @@ -91,15 +91,16 @@ requests==2.32.3 rfc3339-validator==0.1.4 rfc3987==1.3.8 rich==13.7.1 -rpds-py==0.18.1 +rpds-py==0.19.1 rstr==3.2.2 +ruff==0.5.5 s3transfer==0.10.2 -setuptools==70.1.0 +setuptools==71.1.0 shellingham==1.5.4 six==1.16.0 sniffio==1.3.1 SQLAlchemy==2.0.31 -tenacity==8.4.2 +tenacity==8.5.0 tiktoken==0.7.0 tokenizers==0.19.1 tqdm==4.66.4