Skip to content

Commit

Permalink
Add summarizer bearer auth support
Browse files Browse the repository at this point in the history
Signed-off-by: thepetk <thepetk@gmail.com>
  • Loading branch information
thepetk committed Sep 23, 2024
1 parent 9a4a08e commit 9bd66e0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions recipes/natural_language_processing/summarizer/app/summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
model_service = os.getenv("MODEL_ENDPOINT",
"http://localhost:8001")
model_service = f"{model_service}/v1"
model_service_bearer = os.getenv("MODEL_ENDPOINT_BEARER")
request_kwargs = {}
if model_service_bearer is not None:
request_kwargs["headers"] = {"Authorization": f"Bearer {model_service_bearer}"}

@st.cache_resource(show_spinner=False)
def checking_model_service():
Expand All @@ -23,7 +27,7 @@ def checking_model_service():
ready = False
while not ready:
try:
request = requests.get(f'{model_service}/models')
request = requests.get(f'{model_service}/models', **request_kwargs)
if request.status_code == 200:
ready = True
except:
Expand Down Expand Up @@ -53,8 +57,8 @@ def chunk_text(text):
text_chunks = text_splitter.create_documents([text])
for chunk in text_chunks:
chunk = chunk.page_content
count = requests.post(f"{model_service[:-2]}extras/tokenize/count",
json={"input":chunk}).content
chunk_kwargs = request_kwargs | {"json": {"input": chunk}}
count = requests.post(f"{model_service[:-2]}/v1/extras/tokenize/count", **chunk_kwargs).content
count = json.loads(count)["count"]
if count >= 2048:
split_append_chunk(chunk, chunks)
Expand Down

0 comments on commit 9bd66e0

Please sign in to comment.