Update app.py
Browse files
app.py
CHANGED
@@ -51,28 +51,28 @@ with demo:
|
|
51 |
#chat_model_selection = chat_model_dropdown.value
|
52 |
chat_model_selection = 'Intel/neural-chat-7b-v1-1'
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
#
|
77 |
#with gr.Blocks() as chat_interface:
|
78 |
# chatbot = gr.Chatbot()
|
|
|
51 |
#chat_model_selection = chat_model_dropdown.value
|
52 |
chat_model_selection = 'Intel/neural-chat-7b-v1-1'
|
53 |
|
54 |
+
def call_api_and_stream_response(query, chat_model):
|
55 |
+
"""
|
56 |
+
Call the API endpoint and yield characters as they are received.
|
57 |
+
This function simulates streaming by yielding characters one by one.
|
58 |
+
"""
|
59 |
+
url = inference_endpoint_url
|
60 |
+
params = {"query": query, "selected_model": chat_model}
|
61 |
+
with requests.get(url, json=params, stream=True) as r: # Use params for query parameters
|
62 |
+
for chunk in r.iter_content(chunk_size=1):
|
63 |
+
if chunk:
|
64 |
+
yield chunk.decode()
|
65 |
+
|
66 |
+
def get_response(query, history):
|
67 |
+
"""
|
68 |
+
Wrapper function to call the streaming API and compile the response.
|
69 |
+
"""
|
70 |
+
response = ''
|
71 |
+
for char in call_api_and_stream_response(query, chat_model=chat_model_selection):
|
72 |
+
if char == '<': # This seems to be your stopping condition; adjust as needed.
|
73 |
+
break
|
74 |
+
response += char
|
75 |
+
yield [(f"🤖 Response from LLM: {chat_model_selection}", response)] # Correct format for Gradio Chatbot
|
76 |
#
|
77 |
#with gr.Blocks() as chat_interface:
|
78 |
# chatbot = gr.Chatbot()
|