Skip to content

Commit

Permalink
add model service check (#41)
Browse files Browse the repository at this point in the history
* add model service check

* add model service check to chatbot

* improve checking_model output UI
  • Loading branch information
MichaelClifford authored Feb 19, 2024
1 parent c12f497 commit b0b2eca
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
22 changes: 21 additions & 1 deletion chatbot-langchain/chatbot_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,32 @@
from langchain_community.callbacks import StreamlitCallbackHandler
from langchain_core.prompts import ChatPromptTemplate
import streamlit as st
import requests
import time
import os


model_service = os.getenv("MODEL_SERVICE_ENDPOINT",
"http://localhost:8001/v1")

@st.cache_resource(show_spinner=False)
def checking_model_service():
start = time.time()
print("Checking Model Service Availability...")
ready = False
while not ready:
try:
request = requests.get(f'{model_service}/models')
if request.status_code == 200:
ready = True
except:
pass
time.sleep(1)
print("Model Service Available")
print(f"{time.time()-start} seconds")

with st.spinner("Checking Model Service Availability..."):
checking_model_service()

st.title("💬 Chatbot")
if "messages" not in st.session_state:
st.session_state["messages"] = [{"role": "assistant",
Expand Down
16 changes: 16 additions & 0 deletions chatbot/ai_applications/chat_ui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import gradio as gr
from gradio_client import Client
import requests
import time
import os


Expand All @@ -17,8 +19,22 @@ def ask(self, prompt, history):
yield r
yield str(job.outputs()[-1])

def checking_model_service(model_service):
print("Waiting for Model Service Availability...")
ready = False
while not ready:
try:
request = requests.get(f'{model_service}')
if request.status_code == 200:
ready = True
except:
pass
time.sleep(1)
print("Model Service Available")

if __name__ == "__main__":
model_endpoint = os.getenv('MODEL_ENDPOINT', "http://0.0.0.0:7860")
checking_model_service(model_endpoint)
chat = Chat(model_endpoint)
demo = gr.ChatInterface(chat.ask)
demo.launch(server_name="0.0.0.0", server_port=8080)

0 comments on commit b0b2eca

Please sign in to comment.