Skip to content

Commit

Permalink
perf: exclude system message
Browse files Browse the repository at this point in the history
  • Loading branch information
datvodinh committed May 12, 2024
1 parent 62ec01e commit f08b195
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 3 additions & 2 deletions rag_chatbot/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ def set_engine(self):
def get_history(self, chatbot: list[list[str]]):
history = []
for chat in chatbot:
history.append(ChatMessage(role=MessageRole.USER, content=chat[0]))
history.append(ChatMessage(role=MessageRole.ASSISTANT, content=chat[1]))
if chat[0]:
history.append(ChatMessage(role=MessageRole.USER, content=chat[0]))
history.append(ChatMessage(role=MessageRole.ASSISTANT, content=chat[1]))
return history

def query(
Expand Down
12 changes: 10 additions & 2 deletions rag_chatbot/ui/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DefaultElement:
DEFAULT_HISTORY: ClassVar[list] = []
DEFAULT_DOCUMENT: ClassVar[list] = []

HELLO_MESSAGE: str = "Hello ✋, How can I help you today?"
HELLO_MESSAGE: str = "Hi 👋, how can I help you today?"
SET_MODEL_MESSAGE: str = "You need to choose LLM model 🤖 first!"
EMPTY_MESSAGE: str = "You need to enter your message!"
DEFAULT_STATUS: str = "Ready!"
Expand All @@ -42,7 +42,7 @@ def _yield_string(self, message: str):
time.sleep(0.01)
yield (
DefaultElement.DEFAULT_MESSAGE,
[["", message[:i+1]]],
[[None, message[:i+1]]],
DefaultElement.DEFAULT_STATUS
)

Expand Down Expand Up @@ -267,6 +267,10 @@ def _show_hide_setting(self, state):
state
)

def _welcome(self):
for m in self._llm_response.welcome():
yield m

def build(self):
with gr.Blocks(
theme=gr.themes.Soft(primary_hue="slate"),
Expand Down Expand Up @@ -491,5 +495,9 @@ def build(self):
self._reset_document,
outputs=[documents, upload_doc_btn, reset_doc_btn]
)
demo.load(
self._welcome,
outputs=[message, chatbot, status]
)

return demo

0 comments on commit f08b195

Please sign in to comment.