Skip to content

Commit ee7a5e8

Browse files
added the API
1 parent 4c54e2a commit ee7a5e8

File tree

4 files changed

+45
-16
lines changed

4 files changed

+45
-16
lines changed

frontend/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
"@emotion/styled": "^11.11.0",
1515
"@mui/material": "^5.15.10",
1616
"@mui/styled-engine": "^5.15.9",
17-
"@neo4j-ndl/base": "^2.3.0",
18-
"@neo4j-ndl/react": "^2.3.0",
1917
"@types/uuid": "^9.0.7",
18+
"@neo4j-ndl/base": "^2.6.0",
19+
"@neo4j-ndl/react": "^2.6.2",
2020
"axios": "^1.6.5",
2121
"eslint-plugin-react": "^7.33.2",
2222
"neo4j-driver": "^5.14.0",

frontend/src/components/Chatbot.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ import { Button, Widget, Typography, Avatar, TextInput } from '@neo4j-ndl/react'
44
import ChatBotUserAvatar from '../assets/images/chatbot-user.png'
55
import ChatBotAvatar from '../assets/images/chatbot-ai.png';
66
import { ChatbotProps } from '../types';
7+
import { useCredentials } from '../context/UserCredentials';
8+
import { useFileContext } from '../context/UsersFiles';
9+
import chatBotAPI from '../services/QnaAPI';
710

811

912

1013
export default function Chatbot(props: ChatbotProps) {
11-
const { messages:listMessages,setMessages:setListMessages } = props;
14+
const { messages: listMessages, setMessages: setListMessages } = props;
1215
const [inputMessage, setInputMessage] = useState('');
1316
const formattedTextStyle = { color: 'rgb(var(--theme-palette-discovery-bg-strong))' };
14-
17+
const { userCredentials } = useCredentials();
18+
const { model } = useFileContext()
1519
const messagesEndRef = useRef<HTMLDivElement>(null);
1620

1721
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
@@ -40,17 +44,18 @@ export default function Chatbot(props: ChatbotProps) {
4044
}
4145
};
4246

43-
const handleSubmit = (e: { preventDefault: () => void }) => {
47+
const handleSubmit = async (e: { preventDefault: () => void }) => {
4448
e.preventDefault();
4549
if (!inputMessage.trim()) {
4650
return;
4751
}
4852
const date = new Date();
4953
const datetime = `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`;
5054
const userMessage = { id: 999, user: 'user', message: inputMessage, datetime: datetime };
55+
const chatresponse = await chatBotAPI(userCredentials, model, inputMessage)
56+
console.log(chatresponse)
5157
setListMessages((listMessages) => [...listMessages, userMessage]);
5258
setInputMessage('');
53-
5459
const chatbotReply = 'Hello Sir, how can I help you today?'; // Replace with getting a response from your chatbot through your APIs
5560
simulateTypingEffect(chatbotReply);
5661
};
@@ -65,7 +70,7 @@ export default function Chatbot(props: ChatbotProps) {
6570

6671
return (
6772
<div className='n-bg-palette-neutral-bg-weak flex flex-col justify-between min-h-full max-h-full overflow-hidden w-[312px]'>
68-
<div className='flex overflow-y-auto pb-12 min-w-full' style={{scrollbarWidth:"thin",overflowX:"hidden"}}>
73+
<div className='flex overflow-y-auto pb-12 min-w-full' style={{ scrollbarWidth: "thin", overflowX: "hidden" }}>
6974
<Widget className='n-bg-palette-neutral-bg-weak' header='' isElevated={false}>
7075
<div className='flex flex-col gap-4 gap-y-4'>
7176
{listMessages.map((chat) => (

frontend/src/services/QnaAPI.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import axios from "axios";
2+
import { url } from "../utils/Utils";
3+
4+
const chatBotAPI = async (userCredentials: any, model: string, question: string) => {
5+
try {
6+
const formData = new FormData();
7+
formData.append('uri', userCredentials?.uri ?? '');
8+
formData.append('database', userCredentials?.database ?? '');
9+
formData.append('userName', userCredentials?.userName ?? '');
10+
formData.append('password', userCredentials?.password ?? '');
11+
formData.append('model', model)
12+
formData.append('question', question)
13+
const response: any = await axios.post(`${url()}/chat_bot`, formData, {
14+
headers: {
15+
'Content-Type': 'multipart/form-data',
16+
},
17+
});
18+
return response;
19+
} catch (error) {
20+
console.log('Error Posting the Question:', error);
21+
throw error;
22+
}
23+
};
24+
export default chatBotAPI;

frontend/yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -927,20 +927,20 @@
927927
"@babel/runtime" "^7.20.13"
928928
"@neo4j-cypher/codemirror" "1.0.2"
929929

930-
"@neo4j-ndl/base@^2.3.0", "@neo4j-ndl/base@^2.7.6":
931-
version "2.7.6"
932-
resolved "https://registry.yarnpkg.com/@neo4j-ndl/base/-/base-2.7.6.tgz#a950cd204e9719c02406bb0493973c0204e341ec"
933-
integrity sha512-fbKMS4ArYg8plru45IhDdAwIh9JJhp7qRxUYw7xku/X/Ind2+CQQgCnn2dubNvjWr4zYf/vpbb343FlFmWnd/g==
930+
"@neo4j-ndl/base@^2.6.0", "@neo4j-ndl/base@^2.7.7":
931+
version "2.7.7"
932+
resolved "https://registry.yarnpkg.com/@neo4j-ndl/base/-/base-2.7.7.tgz#7fdbb46cecb59873a032b1f06737b38dd8fc9794"
933+
integrity sha512-r8h08IEy5GzX1oWdgiUkmQr15Z+79Isg4TLHf3DzvBsMI4WubDyzSWUC4Tlj0r5nl6uybH9vr3Go519dUS7i6w==
934934

935-
"@neo4j-ndl/react@^2.3.0":
936-
version "2.8.9"
937-
resolved "https://registry.yarnpkg.com/@neo4j-ndl/react/-/react-2.8.9.tgz#4e9bdb88b9b31d4a6eadb0d666347b18f7da3ea1"
938-
integrity sha512-KDLbSvRoW0LQhMijkCRRsfGcUfT43gV1mWWKpfCyaksFgXo3AFMEkrJrDpjUdzIBSlOMfXw9FGf7oRCsWO9qmA==
935+
"@neo4j-ndl/react@^2.6.2":
936+
version "2.8.10"
937+
resolved "https://registry.yarnpkg.com/@neo4j-ndl/react/-/react-2.8.10.tgz#3441292fa7b392caf8b8bd3e9147e7211133ee71"
938+
integrity sha512-u51rWnPJnzYnL751mF8UI/VLqbHWjT0hQL47HSV2EOrxj2KiRkxn3UmKYiAhxN3iVRxpYYvSDjY8OIbAhxmCkQ==
939939
dependencies:
940940
"@floating-ui/react" "0.25.1"
941941
"@heroicons/react" "2.0.13"
942942
"@neo4j-cypher/react-codemirror" "^1.0.1"
943-
"@neo4j-ndl/base" "^2.7.6"
943+
"@neo4j-ndl/base" "^2.7.7"
944944
"@table-nav/core" "0.0.7"
945945
"@table-nav/react" "0.0.7"
946946
"@tanstack/react-table" "^8.9.3"

0 commit comments

Comments
 (0)