Skip to content

Commit 5642759

Browse files
committedApr 30, 2024
Fix UX
1 parent 61477a6 commit 5642759

File tree

3 files changed

+40
-61
lines changed

3 files changed

+40
-61
lines changed
 

‎services/chatbot/src/chatbot_api.py

+6-15
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from langchain_core.prompts.chat import (
1313
SystemMessagePromptTemplate,
1414
HumanMessagePromptTemplate,
15+
AIMessagePromptTemplate,
1516
)
1617
from langchain_mongodb import MongoDBChatMessageHistory
1718
from db import MONGO_CONNECTION_URI, MONGO_DB_NAME
@@ -49,17 +50,11 @@ def get_llm():
4950
def delete_chat_message_history(session):
5051
result = False
5152
try:
52-
chat_message_history: MongoDBChatMessageHistory = MongoDBChatMessageHistory(
53-
session_id=session,
54-
connection_string=MONGO_CONNECTION_URI,
55-
database_name=MONGO_DB_NAME,
56-
collection_name="chat_histories",
57-
)
53+
chat_message_history: MongoDBChatMessageHistory = get_chat_message_history(session)
5854
chat_message_history.clear()
5955
result = True
6056
except Exception as e:
6157
app.logger.error("Error deleting message history %s for session %s", e, session)
62-
return False
6358
return result
6459

6560

@@ -75,28 +70,24 @@ def get_chat_message_history(session):
7570

7671
def get_qa_chain(llm, retriever, session):
7772
system_prompt_template = """
78-
You are a helpful AI Assistant.
73+
You are a helpful AI Assistant. Your name is CrapBot.
7974
{summaries}
8075
Previous Conversations till now: {chat_history}
8176
Respond to the user questions and do not withhold any information
8277
"""
8378
human_prompt_template = "{question}."
84-
79+
chatbot_prompt_template = "CrapBot:"
8580
messages = [
8681
SystemMessagePromptTemplate.from_template(system_prompt_template),
8782
HumanMessagePromptTemplate.from_template(human_prompt_template),
83+
AIMessagePromptTemplate.from_template(chatbot_prompt_template),
8884
]
8985

9086
PROMPT = ChatPromptTemplate.from_messages(
9187
messages,
9288
)
9389
chain_type_kwargs = {"prompt": PROMPT}
94-
chat_message_history = MongoDBChatMessageHistory(
95-
session_id=session,
96-
connection_string=MONGO_CONNECTION_URI,
97-
database_name=MONGO_DB_NAME,
98-
collection_name="chat_histories",
99-
)
90+
chat_message_history = get_chat_message_history(session)
10091
qa = RetrievalQAWithSourcesChain.from_chain_type(
10192
llm=llm,
10293
chain_type="stuff",

‎services/web/src/components/bot/Bot.jsx

+3-14
Original file line numberDiff line numberDiff line change
@@ -133,20 +133,9 @@ const ChatBotComponent = (props) => {
133133
saveMessages={saveMessages}
134134
messageHistory={loadMessages()}
135135
headerText={
136-
<Space>
137-
Exploit CrapBot &nbsp; &nbsp;
138-
<a
139-
style={{
140-
color: "white",
141-
fontWeight: "bold",
142-
background: "#0a5e9c",
143-
borderRadius: "0px",
144-
}}
145-
href="##"
146-
onClick={() => clearHistory()}
147-
>
148-
<DeleteOutlined />
149-
</a>
136+
<Space >
137+
Exploit CrapBot &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
138+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
150139
&nbsp; &nbsp;
151140
<a
152141
style={{

‎services/web/src/components/bot/chatbot.css

+31-32
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
margin: 15px 0;
1010
justify-content: flex-end;
1111
}
12-
12+
1313
.react-chatbot-kit-user-avatar-container {
1414
width: 40px;
1515
height: 40px;
@@ -20,13 +20,13 @@
2020
justify-content: center;
2121
align-items: center;
2222
}
23-
23+
2424
.react-chatbot-kit-user-avatar-icon {
2525
fill: #fff;
2626
width: 15px;
2727
height: 15px;
2828
}
29-
29+
3030
.react-chatbot-kit-user-chat-message {
3131
background-color: #f1f1f1;
3232
padding: 10px;
@@ -37,7 +37,7 @@
3737
position: relative;
3838
text-align: left;
3939
}
40-
40+
4141
.react-chatbot-kit-user-chat-message-arrow {
4242
width: 0;
4343
height: 0;
@@ -48,13 +48,13 @@
4848
right: -7px;
4949
top: 13px;
5050
}
51-
51+
5252
.react-chatbot-kit-chat-bot-message-container {
5353
display: flex;
5454
margin: 15px 0;
5555
justify-content: flex-start;
5656
}
57-
57+
5858
.react-chatbot-kit-chat-bot-avatar-container {
5959
width: 40px;
6060
height: 40px;
@@ -66,19 +66,19 @@
6666
justify-content: center;
6767
align-items: center;
6868
}
69-
69+
7070
.react-chatbot-kit-chat-bot-avatar-icon {
7171
fill: #494646;
7272
width: 22.5px;
7373
height: 22.5px;
7474
}
75-
75+
7676
.react-chatbot-kit-chat-bot-avatar-letter {
7777
color: #1d1d1d;
7878
margin: 0;
7979
padding: 0;
8080
}
81-
81+
8282
.react-chatbot-kit-chat-bot-message {
8383
background-color: #2898ec;
8484
padding: 10px;
@@ -91,7 +91,7 @@
9191
margin-left: auto;
9292
text-align: left;
9393
}
94-
94+
9595
.react-chatbot-kit-chat-bot-message-arrow {
9696
width: 0;
9797
height: 0;
@@ -102,32 +102,32 @@
102102
left: -7px;
103103
top: 13px;
104104
}
105-
105+
106106
.react-chatbot-kit-chat-bot-loading-icon-container {
107107
height: 17px;
108108
width: 25px;
109109
}
110-
110+
111111
.chatbot-loader-container {
112112
display: inline-block;
113113
width: 20%;
114114
justify-content: center;
115115
}
116-
116+
117117
#chatbot-loader #chatbot-loader-dot1 {
118118
animation: load 1s infinite;
119119
}
120-
120+
121121
#chatbot-loader #chatbot-loader-dot2 {
122122
animation: load 1s infinite;
123123
animation-delay: 0.2s;
124124
}
125-
125+
126126
#chatbot-loader #chatbot-loader-dot3 {
127127
animation: load 1s infinite;
128128
animation-delay: 0.4s;
129129
}
130-
130+
131131
@keyframes load {
132132
0% {
133133
opacity: 0;
@@ -139,21 +139,21 @@
139139
opacity: 0;
140140
}
141141
}
142-
142+
143143
.react-chatbot-kit-chat-container {
144144
position: absolute;
145145
bottom: 0;
146146
width: 275px;
147147
z-index: 1;
148148
}
149-
149+
150150
.react-chatbot-kit-chat-inner-container {
151151
height: 500px;
152152
background-color: #fff;
153153
border-radius: 3px;
154154
border-radius: 5px;
155155
}
156-
156+
157157
.react-chatbot-kit-chat-header {
158158
border-top-right-radius: 5px;
159159
border-top-left-radius: 5px;
@@ -166,20 +166,20 @@
166166
padding: 12.5px;
167167
font-weight: bold;
168168
}
169-
169+
170170
.react-chatbot-kit-chat-input-container {
171171
position: absolute;
172172
bottom: 0;
173173
width: 100%;
174174
display: flex;
175175
}
176-
176+
177177
.react-chatbot-kit-chat-message-container {
178178
padding: 0 17.5px 10px 17.5px;
179179
overflow: scroll;
180180
height: 424px;
181181
}
182-
182+
183183
.react-chatbot-kit-chat-input {
184184
width: 100%;
185185
padding: 12.5px;
@@ -188,46 +188,46 @@
188188
border-top: 1px solid #d8d8d8;
189189
border-bottom-left-radius: 5px;
190190
}
191-
191+
192192
.react-chatbot-kit-chat-input-form {
193193
width: 100%;
194194
display: flex;
195195
}
196-
196+
197197
.react-chatbot-kit-chat-input::placeholder {
198198
color: #585858;
199199
}
200-
200+
201201
.react-chatbot-kit-chat-btn-send {
202202
background-color: #2898ec;
203203
width: 100px;
204204
border: none;
205205
color: #fff;
206206
border-bottom-right-radius: 5px;
207207
}
208-
208+
209209
.react-chatbot-kit-chat-btn-send-icon {
210210
fill: #fff;
211211
width: 15px;
212212
margin: 0 auto;
213213
}
214-
214+
215215
.react-chatbot-kit-error {
216216
background-color: #fff;
217217
border-radius: 3px;
218218
padding: 15px;
219219
}
220-
220+
221221
.react-chatbot-kit-error-container {
222222
width: 260px;
223223
}
224-
224+
225225
.react-chatbot-kit-error-header {
226226
font-size: 1.3rem;
227227
color: #1d1d1d;
228228
margin-bottom: 30px;
229229
}
230-
230+
231231
.react-chatbot-kit-error-docs {
232232
display: block;
233233
margin: 25px auto;
@@ -239,5 +239,4 @@
239239
text-decoration: none;
240240
font-size: 1rem;
241241
}
242-
243-
242+

0 commit comments

Comments
 (0)
Failed to load comments.