Skip to content

Commit 9a48eb6

Browse files
Merge branch 'DEV' into wikipedia-as-new-source-type-frontend
2 parents 4da9846 + 9c6ce38 commit 9a48eb6

File tree

6 files changed

+100
-20
lines changed

6 files changed

+100
-20
lines changed

backend/score.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@ async def chat_bot(uri=Form(None),
177177
result = await asyncio.to_thread(QA_RAG,uri=uri,userName=userName,password=password,model_version=model,question=question)
178178
return result
179179

180+
@app.post("/connect")
181+
async def connect(uri=Form(None),
182+
userName=Form(None),
183+
password=Form(None),
184+
database=Form(None)):
185+
result = await asyncio.to_thread(connection_check,uri,userName,password,database)
186+
return result
187+
180188
def decode_password(pwd):
181189
sample_string_bytes = base64.b64decode(pwd)
182190
decoded_password = sample_string_bytes.decode("utf-8")

backend/src/main.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,27 @@ def update_graph(uri,userName,password,db_name):
552552
error_message = str(e)
553553
logging.exception(f'Exception in update KNN graph:{error_message}')
554554
raise Exception(error_message)
555+
556+
def connection_check(uri,userName,password,db_name):
557+
"""
558+
Args:
559+
uri: URI of the graph to extract
560+
userName: Username to use for graph creation ( if None will use username from config file )
561+
password: Password to use for graph creation ( if None will use password from config file )
562+
db_name: db_name is database name to connect to graph db
563+
Returns:
564+
Returns a status of connection from NEO4j is success or failure
565+
"""
566+
try:
567+
graph = Neo4jGraph(url=uri, database=db_name, username=userName, password=password)
568+
if graph:
569+
return create_api_response("Success",message="Connection Successful")
570+
except Exception as e:
571+
job_status = "Failed"
572+
message="Connection Failed"
573+
error_message = str(e)
574+
logging.exception(f'Exception:{error_message}')
575+
return create_api_response(job_status,message=message,error=error_message)
555576

556577
def create_api_response(status,success_count=None,Failed_count=None, data=None, error=None,message=None,file_source=None,file_name=None):
557578
"""

frontend/src/App.css

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,34 @@
121121
overflow: hidden;
122122
text-overflow: ellipsis;
123123
white-space: nowrap;
124+
}
125+
126+
.loader {
127+
width: 8px;
128+
height: 8px;
129+
border-radius: 50%;
130+
display: block;
131+
margin: 7px auto;
132+
position: relative;
133+
background: #FFF;
134+
box-shadow: -12px 0 #FFF, 12px 0 #FFF;
135+
box-sizing: border-box;
136+
animation: shadowPulse 2s linear infinite;
137+
}
138+
139+
@keyframes shadowPulse {
140+
33% {
141+
background: #FFF;
142+
box-shadow: -12px 0 rgb(var(--theme-palette-primary-bg-strong)), 12px 0 #FFF;
143+
}
144+
145+
66% {
146+
background: rgb(var(--theme-palette-primary-bg-strong));
147+
box-shadow: -12px 0 #FFF, 12px 0 #FFF;
148+
}
149+
150+
100% {
151+
background: #FFF;
152+
box-shadow: -12px 0 #FFF, 12px 0 rgb(var(--theme-palette-primary-bg-strong));
153+
}
124154
}
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
{
2-
"listMessages": [
1+
{
2+
"listMessages": [
33
{
44
"id": 1,
55
"message": "Hi, I need help with creating a Cypher query for Neo4j.",
@@ -8,7 +8,7 @@
88
},
99
{
1010
"id": 2,
11-
"message": "Hi there! Welcome to Neo4j Chat! Your insights are just a click away from completed files",
11+
"message": " Welcome to the Neo4j Knowledge Graph Chat. You can ask questions related to documents which have been completely processed.",
1212
"user": "chatbot",
1313
"datetime": "01/01/2024 00:00:00"
1414
},
@@ -20,8 +20,7 @@
2020
},
2121
{
2222
"id": 4,
23-
"message":
24-
"Alright, you can use the following query: `MATCH (e:Employee)-[:WORKS_IN]->(d:Department {name: 'IT'}) RETURN e.name`. This query matches nodes labeled 'Employee' related to the 'IT' department and returns their names.",
23+
"message": "Alright, you can use the following query: `MATCH (e:Employee)-[:WORKS_IN]->(d:Department {name: 'IT'}) RETURN e.name`. This query matches nodes labeled 'Employee' related to the 'IT' department and returns their names.",
2524
"user": "chatbot",
2625
"datetime": "01/01/2024 00:00:00"
2726
},
@@ -33,10 +32,9 @@
3332
},
3433
{
3534
"id": 6,
36-
"message":
37-
"To get the count, use: `MATCH (e:Employee)-[:WORKS_IN]->(d:Department {name: 'IT'}) RETURN count(e)`. This counts all the distinct 'Employee' nodes related to the 'IT' department.",
35+
"message": "To get the count, use: `MATCH (e:Employee)-[:WORKS_IN]->(d:Department {name: 'IT'}) RETURN count(e)`. This counts all the distinct 'Employee' nodes related to the 'IT' department.",
3836
"user": "chatbot",
3937
"datetime": "01/01/2024 00:00:00"
4038
}
41-
]
42-
}
39+
]
40+
}

frontend/src/components/Chatbot.tsx

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,33 @@ export default function Chatbot(props: ChatbotProps) {
2525
if (index < responseText.length) {
2626
const nextIndex = index + 1;
2727
const currentTypedText = responseText.substring(0, nextIndex);
28-
2928
if (index === 0) {
3029
const date = new Date();
3130
const datetime = `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`;
32-
setListMessages((msgs) => [
33-
...msgs,
34-
{ id: Date.now(), user: 'chatbot', message: currentTypedText, datetime: datetime, isTyping: true },
35-
]);
31+
if (responseText.length <= 1) {
32+
setListMessages((msgs) => [
33+
...msgs,
34+
{ id: Date.now(), user: 'chatbot', message: currentTypedText, datetime: datetime, isTyping: true },
35+
]);
36+
} else {
37+
setListMessages((msgs) => {
38+
const lastmsg = { ...msgs[msgs.length - 1] };
39+
lastmsg.id = Date.now();
40+
lastmsg.user = 'chatbot';
41+
lastmsg.message = currentTypedText;
42+
lastmsg.datetime = datetime;
43+
lastmsg.isTyping = true;
44+
return msgs.map((msg, index) => {
45+
if (index === msgs.length - 1) {
46+
return lastmsg;
47+
}
48+
return msg;
49+
});
50+
});
51+
}
3652
} else {
3753
setListMessages((msgs) => msgs.map((msg) => (msg.isTyping ? { ...msg, message: currentTypedText } : msg)));
3854
}
39-
4055
setTimeout(() => simulateTypingEffect(responseText, nextIndex), 20);
4156
} else {
4257
setListMessages((msgs) => msgs.map((msg) => (msg.isTyping ? { ...msg, isTyping: false } : msg)));
@@ -55,9 +70,10 @@ export default function Chatbot(props: ChatbotProps) {
5570
setListMessages((listMessages) => [...listMessages, userMessage]);
5671
try {
5772
setLoading(true);
73+
setInputMessage('');
74+
simulateTypingEffect(' ');
5875
const chatresponse = await chatBotAPI(userCredentials, model, inputMessage);
5976
chatbotReply = chatresponse?.data?.message;
60-
setInputMessage('');
6177
simulateTypingEffect(chatbotReply);
6278
setLoading(false);
6379
} catch (error) {
@@ -81,7 +97,7 @@ export default function Chatbot(props: ChatbotProps) {
8197
<div className='flex overflow-y-auto pb-12 min-w-full' style={{ scrollbarWidth: 'thin', overflowX: 'hidden' }}>
8298
<Widget className='n-bg-palette-neutral-bg-weak' header='' isElevated={false}>
8399
<div className='flex flex-col gap-4 gap-y-4'>
84-
{listMessages.map((chat) => (
100+
{listMessages.map((chat, index) => (
85101
<div
86102
ref={messagesEndRef}
87103
key={chat.id}
@@ -119,7 +135,11 @@ export default function Chatbot(props: ChatbotProps) {
119135
chat.user === 'chatbot' ? 'n-bg-palette-neutral-bg-strong' : 'n-bg-palette-primary-bg-weak'
120136
}`}
121137
>
122-
<div>
138+
<div
139+
className={`${
140+
loading && index === listMessages.length - 1 && chat.user == 'chatbot' ? 'loader' : ''
141+
}`}
142+
>
123143
{chat.message.split(/`(.+?)`/).map((part, index) =>
124144
index % 2 === 1 ? (
125145
<span key={index} style={formattedTextStyle}>
@@ -148,7 +168,7 @@ export default function Chatbot(props: ChatbotProps) {
148168
fluid
149169
onChange={handleInputChange}
150170
/>
151-
<Button type='submit' disabled={loading}>
171+
<Button type='submit' loading={loading}>
152172
Submit
153173
</Button>
154174
</form>

frontend/src/components/RightSideBar.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ interface RightSideBarProps {
99
}
1010

1111
const RightSideBar: React.FC<RightSideBarProps> = ({ showChatBot, closeChatBot }) => {
12-
const [messages, setMessages] = useState<messages[]>([chatbotmessages.listMessages[1]]);
12+
const date = new Date();
13+
const [messages, setMessages] = useState<messages[]>([
14+
{ ...chatbotmessages.listMessages[1], datetime: `${date.toLocaleDateString()} ${date.toLocaleTimeString()}` },
15+
]);
1316
return (
1417
<Drawer
1518
expanded={showChatBot}

0 commit comments

Comments
 (0)