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