Skip to content

Commit edc9b6d

Browse files
committed
feat: added VERBOSE environment variable to enable/disable verbose logging, disabled by default.
1 parent 721b9e9 commit edc9b6d

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

.github/workflows/dev.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ on:
1010
description: Memory size of the lambda function
1111
normalize_embeddings:
1212
description: Enabled by default. You can disable it by specify "0" or "False"
13+
verbose:
14+
description: Enabled verbose logging in the console by specify any value, otherwise leave it blank
1315

1416
jobs:
1517
deploy-dev:
@@ -18,6 +20,7 @@ jobs:
1820
MODEL: ${{ github.event.inputs.model_name }}
1921
MEMORY_SIZE: ${{ github.event.inputs.memory_size }}
2022
NORMALIZE_EMBEDDINGS: ${{ github.event.inputs.normalize_embeddings }}
23+
VERBOSE: ${{ github.event.inputs.verbose }}
2124

2225
steps:
2326
- name: Checkout repo

.github/workflows/rm-dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ jobs:
2525
MODEL=${{ github.event.inputs.model_name }}
2626
MEMORY_SIZE=128
2727
NORMALIZE_EMBEDDINGS=
28+
VERBOSE=
2829
sls remove

open/text/embeddings/server/gzip.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
# Created with the help of the ChatGPT (GPT-3.5)
22
# REF: https://chat.openai.com/share/4ab741e7-8059-4be1-b3da-46b8e78d98cc
33
# REF: https://gealber.com/gzip-middleware-fastapi
4+
import os
45
import gzip
56
from starlette.types import Message
67
from starlette.requests import Request
78
from starlette.responses import JSONResponse
89
from starlette.middleware.base import BaseHTTPMiddleware
910

11+
verbose = bool(os.environ.get('VERBOSE', ''))
12+
1013

1114
class GZipRequestMiddleware(BaseHTTPMiddleware):
1215
async def set_body(self, request: Request):
1316
receive_ = await request._receive()
1417
content_encoding = request.headers.get('Content-Encoding', '').lower()
15-
print("content_encoding", content_encoding)
18+
if (verbose):
19+
print("content_encoding", content_encoding)
1620
if 'gzip' in content_encoding:
17-
# print("receive_", receive_)
18-
1921
try:
2022
content_length = int(
2123
request.headers.get('Content-Length', '0'))
@@ -27,9 +29,9 @@ async def set_body(self, request: Request):
2729
)
2830
json_byte_string = gzip.decompress(body)
2931
receive_['body'] = json_byte_string
30-
print("content_length", content_length)
31-
# print("body", body)
32-
print("gzip decompressed body:", receive_['body'])
32+
if (verbose):
33+
print("content_length", content_length)
34+
print("gzip decompressed body:", receive_['body'])
3335
except ValueError:
3436
return JSONResponse(
3537
content={"error": "Invalid Content-Length header"},

serverless.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ functions:
3232
environment:
3333
MODEL: ${env:MODEL}
3434
NORMALIZE_EMBEDDINGS: ${env:NORMALIZE_EMBEDDINGS}
35+
VERBOSE: ${env:VERBOSE}
3536
TRANSFORMERS_CACHE: /tmp/transformer_cache
3637
timeout:
3738
900

0 commit comments

Comments
 (0)