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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<title>J Search</title>
|
5 |
+
<link rel="icon" type="image/png" href="../static/Jio-Logo.png" />
|
6 |
+
<link rel="apple-touch-icon" type="image/png" href="../static/Jio-Logo.png" />
|
7 |
+
<style>
|
8 |
+
body {
|
9 |
+
background-color: #ECE5DD;
|
10 |
+
font-family: Arial, sans-serif;
|
11 |
+
font-size: 14px;
|
12 |
+
padding: 20px;
|
13 |
+
}
|
14 |
+
.container {
|
15 |
+
display: flex;
|
16 |
+
flex-direction: column;
|
17 |
+
height: 950px;
|
18 |
+
/* max-width: 700px;*/
|
19 |
+
margin: 0 auto;
|
20 |
+
background-color: #fff;
|
21 |
+
border-radius: 10px;
|
22 |
+
box-shadow: 0px 5px 10px rgba(0,0,0,0.1);
|
23 |
+
overflow: hidden;
|
24 |
+
}
|
25 |
+
.header {
|
26 |
+
display: flex;
|
27 |
+
align-items: center;
|
28 |
+
justify-content: center;
|
29 |
+
height: 60px;
|
30 |
+
background-color:#0f3cc9 ;
|
31 |
+
/* #075E54 */
|
32 |
+
color: #fff;
|
33 |
+
font-weight: bold;
|
34 |
+
font-size: 20px;
|
35 |
+
}
|
36 |
+
|
37 |
+
.flex-container {
|
38 |
+
display: flex;
|
39 |
+
align-items: stretch;
|
40 |
+
height:90%;
|
41 |
+
}
|
42 |
+
|
43 |
+
/*.chat-area {
|
44 |
+
flex-grow: 1;
|
45 |
+
padding: 20px;
|
46 |
+
overflow-y: auto;
|
47 |
+
}*/
|
48 |
+
|
49 |
+
.chat-area {
|
50 |
+
flex: 1.5;
|
51 |
+
padding: 20px;
|
52 |
+
border: 2px solid black;
|
53 |
+
|
54 |
+
}
|
55 |
+
|
56 |
+
.llm-area {
|
57 |
+
flex: 1;
|
58 |
+
padding: 20px;
|
59 |
+
border: 2px solid black;
|
60 |
+
}
|
61 |
+
|
62 |
+
|
63 |
+
|
64 |
+
|
65 |
+
.chat-area p {
|
66 |
+
margin: 5px 0;
|
67 |
+
}
|
68 |
+
|
69 |
+
.llm-area p {
|
70 |
+
margin: 5px 0;
|
71 |
+
}
|
72 |
+
.message-box {
|
73 |
+
display: flex;
|
74 |
+
align-items: center;
|
75 |
+
background-color: #F4F4F4;
|
76 |
+
padding: 10px;
|
77 |
+
border-top: 1px solid #ccc;
|
78 |
+
}
|
79 |
+
.message-box input {
|
80 |
+
flex-grow: 1;
|
81 |
+
border: none;
|
82 |
+
padding: 10px;
|
83 |
+
font-size: 14px;
|
84 |
+
border-radius: 5px;
|
85 |
+
background-color: #fff;
|
86 |
+
margin-right: 10px;
|
87 |
+
}
|
88 |
+
.message-box button {
|
89 |
+
background-color:#0f3cc9 ;
|
90 |
+
/* #075E54 */
|
91 |
+
color: #fff;
|
92 |
+
border: none;
|
93 |
+
padding: 10px;
|
94 |
+
font-size: 14px;
|
95 |
+
font-weight: bold;
|
96 |
+
border-radius: 5px;
|
97 |
+
cursor: pointer;
|
98 |
+
}
|
99 |
+
.user-message {
|
100 |
+
display: flex;
|
101 |
+
flex-direction: row-reverse;
|
102 |
+
align-items: center;
|
103 |
+
margin-bottom: 10px;
|
104 |
+
}
|
105 |
+
.bot-message {
|
106 |
+
display: flex;
|
107 |
+
align-items: center;
|
108 |
+
margin-bottom: 10px;
|
109 |
+
}
|
110 |
+
.user-message p, .bot-message p {
|
111 |
+
background-color:#ccd6f2;
|
112 |
+
/* #DCF8C6; */
|
113 |
+
color: #000;
|
114 |
+
padding: 10px;
|
115 |
+
border-radius: 10px;
|
116 |
+
max-width: 90%;
|
117 |
+
word-wrap: break-word;
|
118 |
+
}
|
119 |
+
.user-message p {
|
120 |
+
margin-right: 10px;
|
121 |
+
}
|
122 |
+
.bot-message p {
|
123 |
+
margin-left: 10px;
|
124 |
+
}
|
125 |
+
|
126 |
+
.logoClass
|
127 |
+
{
|
128 |
+
width: 50px;
|
129 |
+
height: 40px;
|
130 |
+
align-self: center;
|
131 |
+
margin-right: 10px;
|
132 |
+
gap: 20px 20px;
|
133 |
+
background-repeat: no-repeat;
|
134 |
+
background-size: cover;
|
135 |
+
/* background-image: url({{url_for('static',filename='Jio-Logo.png')}}); */
|
136 |
+
}
|
137 |
+
|
138 |
+
|
139 |
+
</style>
|
140 |
+
</head>
|
141 |
+
<body>
|
142 |
+
<div class="container">
|
143 |
+
<div class="header">
|
144 |
+
|
145 |
+
<div>Search Powered by J Embedding Engine</div>
|
146 |
+
</div>
|
147 |
+
<div class="message-box">
|
148 |
+
<label for="llmID"><b>Select LLM for Response Generation</b></label>
|
149 |
+
<select name="llmID" id="llmID">
|
150 |
+
<option value="0">Open AI</option>
|
151 |
+
<option value="1">LLAMA 2 - 13B</option>
|
152 |
+
<option value="2">LLAMA 2 - 70B</option>
|
153 |
+
<option value="3">LLAMA 2 - 7B</option>
|
154 |
+
<option value="4">Mistral AI</option>
|
155 |
+
</select>
|
156 |
+
</div>
|
157 |
+
<div class="message-box">
|
158 |
+
<input id="user-input" type="text" placeholder="Enter your Search Query..." onkeyup="return searchKeyPress(event)">
|
159 |
+
<button id="send-button" onclick="sendMessage()">Search</button>
|
160 |
+
</div>
|
161 |
+
<div class="flex-container">
|
162 |
+
<div class="chat-area">
|
163 |
+
<!-- <div class="bot-message">
|
164 |
+
<p>Hello! How can I assist you today?</p>
|
165 |
+
</div> -->
|
166 |
+
</div>
|
167 |
+
<div class="llm-area">
|
168 |
+
<!-- <div class="bot-message">
|
169 |
+
<p>Hello! How can I assist you today?</p>
|
170 |
+
</div> -->
|
171 |
+
</div>
|
172 |
+
</div>
|
173 |
+
|
174 |
+
</div>
|
175 |
+
|
176 |
+
<script>
|
177 |
+
|
178 |
+
function searchKeyPress(event) {
|
179 |
+
event.preventDefault();
|
180 |
+
if (event.keyCode === 13) {
|
181 |
+
document.getElementById("send-button").click();
|
182 |
+
}
|
183 |
+
};
|
184 |
+
|
185 |
+
async function sendMessage() {
|
186 |
+
var response="";
|
187 |
+
// Get the user input
|
188 |
+
document.querySelector(".chat-area").innerHTML = ""
|
189 |
+
document.querySelector(".llm-area").innerHTML = ""
|
190 |
+
var userInput = document.getElementById("user-input").value;
|
191 |
+
var selectedllmid = document.getElementById("llmID").value;
|
192 |
+
console.log("Selected LLM ID:::"+selectedllmid)
|
193 |
+
|
194 |
+
// Create a new user message and add it to the chat area
|
195 |
+
var userMessage = document.createElement("div");
|
196 |
+
userMessage.classList.add("bot-message");
|
197 |
+
userMessage.innerHTML = '<p> Your Search Results for <b> “' + userInput + '” </b></p>';
|
198 |
+
document.querySelector(".chat-area").appendChild(userMessage);
|
199 |
+
|
200 |
+
// Clear the input field
|
201 |
+
document.getElementById("user-input").value = "";
|
202 |
+
|
203 |
+
|
204 |
+
|
205 |
+
// Generate a bot response
|
206 |
+
var botResponse = await generateBotResponse(userInput,selectedllmid);
|
207 |
+
|
208 |
+
|
209 |
+
}
|
210 |
+
|
211 |
+
async function generateBotResponse(userInput,selectedllmid) {
|
212 |
+
// Make a POST request to the chatbot API endpoint
|
213 |
+
// response = await fetch('http://127.0.0.1:1111/post_json', {
|
214 |
+
// method: 'POST',
|
215 |
+
// headers: {
|
216 |
+
// 'Content-Type': 'application/json'
|
217 |
+
// },
|
218 |
+
// body: JSON.stringify({
|
219 |
+
// query: userInput
|
220 |
+
// })
|
221 |
+
// });
|
222 |
+
|
223 |
+
var xhr = new XMLHttpRequest();
|
224 |
+
//xhr.open("POST", 'http://127.0.0.1:1111/post_json', true);
|
225 |
+
xhr.open("POST", '/agent/chat/suggestion', true);
|
226 |
+
xhr.setRequestHeader('Content-Type', 'application/json');
|
227 |
+
xhr.send(JSON.stringify({
|
228 |
+
message: [userInput],
|
229 |
+
llmID:selectedllmid
|
230 |
+
}));
|
231 |
+
|
232 |
+
xhr.onload = function() {
|
233 |
+
|
234 |
+
console.log(this.responseText);
|
235 |
+
var searchResultArray = JSON.parse(this.responseText).searchResult;
|
236 |
+
var llmResponse = JSON.parse(this.responseText).suggestions[0]['message'];
|
237 |
+
console.log("Semantic Search Array::::"+searchResultArray);
|
238 |
+
console.log("LLM Response::::"+llmResponse);
|
239 |
+
|
240 |
+
var botMessage = document.createElement("div");
|
241 |
+
botMessage.classList.add("bot-message");
|
242 |
+
botMessage.innerHTML = '<p> <b> LLM Response::</b> '+llmResponse+'</p>';
|
243 |
+
document.querySelector(".llm-area").appendChild(botMessage);
|
244 |
+
|
245 |
+
// Create a new bot message and add it to the chat area
|
246 |
+
for(let i = 0; i < searchResultArray.length; i++)
|
247 |
+
{
|
248 |
+
response=searchResultArray[i]
|
249 |
+
var botMessage = document.createElement("div");
|
250 |
+
botMessage.classList.add("bot-message");
|
251 |
+
botMessage.innerHTML = '<p> <b> Source :: </b><a>' + response.documentSource + '</a> <br> <br> <b> Semantically Matching Content::</b> '+response.pageContent+'</p>';
|
252 |
+
document.querySelector(".chat-area").appendChild(botMessage);
|
253 |
+
|
254 |
+
// Scroll to the bottom of the chat area
|
255 |
+
document.querySelector('.chat-area').scrollTop = document.querySelector('.chat-area').scrollHeight;
|
256 |
+
}
|
257 |
+
|
258 |
+
return response.botMessage;
|
259 |
+
}
|
260 |
+
|
261 |
+
// Parse the response JSON and return the bot message
|
262 |
+
//console.log(data);
|
263 |
+
//var data = await response.json();
|
264 |
+
|
265 |
+
//return response.botMessage;
|
266 |
+
}
|
267 |
+
</script>
|
268 |
+
</body>
|
269 |
+
</html>
|