Add dedicated information panel to the UI (#137)
* Allow streaming to the chatbot and the information panel without threading * Highlight evidence in a simple manner
This commit is contained in:
committed by
GitHub
parent
ebc61400d8
commit
513e86f490
@@ -23,6 +23,9 @@ class ChatPage(BasePage):
|
||||
self.report_issue = ReportIssue(self._app)
|
||||
with gr.Column(scale=6):
|
||||
self.chat_panel = ChatPanel(self._app)
|
||||
with gr.Column(scale=3):
|
||||
with gr.Accordion(label="Information panel", open=True):
|
||||
self.info_panel = gr.Markdown(elem_id="chat-info-panel")
|
||||
|
||||
def on_register_events(self):
|
||||
self.chat_panel.submit_btn.click(
|
||||
@@ -33,7 +36,11 @@ class ChatPage(BasePage):
|
||||
self.data_source.files,
|
||||
self._app.settings_state,
|
||||
],
|
||||
outputs=[self.chat_panel.text_input, self.chat_panel.chatbot],
|
||||
outputs=[
|
||||
self.chat_panel.text_input,
|
||||
self.chat_panel.chatbot,
|
||||
self.info_panel,
|
||||
],
|
||||
).then(
|
||||
fn=update_data_source,
|
||||
inputs=[
|
||||
@@ -52,7 +59,11 @@ class ChatPage(BasePage):
|
||||
self.data_source.files,
|
||||
self._app.settings_state,
|
||||
],
|
||||
outputs=[self.chat_panel.text_input, self.chat_panel.chatbot],
|
||||
outputs=[
|
||||
self.chat_panel.text_input,
|
||||
self.chat_panel.chatbot,
|
||||
self.info_panel,
|
||||
],
|
||||
).then(
|
||||
fn=update_data_source,
|
||||
inputs=[
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import asyncio
|
||||
import os
|
||||
import tempfile
|
||||
from copy import deepcopy
|
||||
@@ -116,24 +117,33 @@ def create_pipeline(settings: dict, files: Optional[list] = None):
|
||||
return pipeline
|
||||
|
||||
|
||||
def chat_fn(chat_input, chat_history, files, settings):
|
||||
async def chat_fn(chat_input, chat_history, files, settings):
|
||||
"""Chat function"""
|
||||
queue: asyncio.Queue[Optional[dict]] = asyncio.Queue()
|
||||
|
||||
# construct the pipeline
|
||||
pipeline = create_pipeline(settings, files)
|
||||
pipeline.set_output_queue(queue)
|
||||
|
||||
text = ""
|
||||
refs = []
|
||||
for response in pipeline(chat_input):
|
||||
if response.metadata.get("citation", None):
|
||||
citation = response.metadata["citation"]
|
||||
for idx, fact_with_evidence in enumerate(citation.answer):
|
||||
quotes = fact_with_evidence.substring_quote
|
||||
if quotes:
|
||||
refs.append(
|
||||
(None, f"***Reference {idx+1}***: {' ... '.join(quotes)}")
|
||||
)
|
||||
else:
|
||||
text += response.text
|
||||
asyncio.create_task(pipeline(chat_input))
|
||||
text, refs = "", ""
|
||||
|
||||
yield "", chat_history + [(chat_input, text)] + refs
|
||||
while True:
|
||||
try:
|
||||
response = queue.get_nowait()
|
||||
except Exception:
|
||||
await asyncio.sleep(0)
|
||||
continue
|
||||
|
||||
if response is None:
|
||||
break
|
||||
|
||||
if "output" in response:
|
||||
text += response["output"]
|
||||
if "evidence" in response:
|
||||
refs += response["evidence"]
|
||||
|
||||
yield "", chat_history + [(chat_input, text)], refs
|
||||
|
||||
|
||||
def is_liked(convo_id, liked: gr.LikeData):
|
||||
|
Reference in New Issue
Block a user