Skip to content

Commit

Permalink
Add bearer auth support to chatbot
Browse files Browse the repository at this point in the history
Signed-off-by: thepetk <[email protected]>
  • Loading branch information
thepetk committed Sep 23, 2024
1 parent 192b5d6 commit c7524b8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions recipes/natural_language_processing/chatbot/app/chatbot_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
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}"}}
import pdb;pdb.set_trace()

@st.cache_resource(show_spinner=False)
def checking_model_service():
Expand All @@ -20,8 +25,8 @@ def checking_model_service():
ready = False
while not ready:
try:
request_cpp = requests.get(f'{model_service}/models')
request_ollama = requests.get(f'{model_service[:-2]}api/tags')
request_cpp = requests.get(f'{model_service}/models', **request_kwargs)
request_ollama = requests.get(f'{model_service[:-2]}api/tags', **request_kwargs)
if request_cpp.status_code == 200:
server = "Llamacpp_Python"
ready = True
Expand All @@ -37,7 +42,7 @@ def checking_model_service():

def get_models():
try:
response = requests.get(f"{model_service[:-2]}api/tags")
response = requests.get(f"{model_service[:-2]}api/tags", **request_kwargs)
return [i["name"].split(":")[0] for i in
json.loads(response.content)["models"]]
except:
Expand Down

0 comments on commit c7524b8

Please sign in to comment.