Skip to content

Commit 7e544e7

Browse files
committed
Merge branch 'beta_dev' of https://github.com/shekharP1536/ollama-web into beta_dev
2 parents 9d45ca9 + 62c80cd commit 7e544e7

4 files changed

Lines changed: 188 additions & 32 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
pre code.hljs {
2+
display: block;
3+
overflow-x: auto;
4+
padding: 1em
5+
}
6+
7+
code.hljs {
8+
padding: 3px 5px
9+
}
10+
.hljs {
11+
background: #000000;
12+
}
13+
14+
.hljs-comment,
15+
.hljs-quote {
16+
color: #b6b18b
17+
}
18+
19+
.hljs-deletion,
20+
.hljs-name,
21+
.hljs-regexp,
22+
.hljs-selector-class,
23+
.hljs-selector-id,
24+
.hljs-tag,
25+
.hljs-template-variable,
26+
.hljs-variable {
27+
color: #eb3c54
28+
}
29+
30+
.hljs-built_in,
31+
.hljs-link,
32+
.hljs-literal,
33+
.hljs-meta,
34+
.hljs-number,
35+
.hljs-params,
36+
.hljs-type {
37+
color: #e7ce56
38+
}
39+
40+
.hljs-attribute {
41+
color: #ee7c2b
42+
}
43+
44+
.hljs-addition,
45+
.hljs-bullet,
46+
.hljs-string,
47+
.hljs-symbol {
48+
color: #4fb4d7
49+
}
50+
51+
.hljs-section,
52+
.hljs-title {
53+
color: #78bb65
54+
}
55+
56+
.hljs-keyword,
57+
.hljs-selector-tag {
58+
color: #b45ea4
59+
}
60+
61+
.hljs-emphasis {
62+
font-style: italic
63+
}
64+
65+
.hljs-strong {
66+
font-weight: 700
67+
}

static/resource/markdown.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function convertMarkdownToHTML(md) {
1616
console.log(language);
1717

1818
result += `
19-
<div class="code_div"><span style="margin: 10px;">${ language || 'code'}</span><pre class="language-${language || 'text'}"><button class="copy-button" onclick="copyCode(this)">Copy</button><code>`;
19+
<div class="code_div"><span style="margin: 10px;">${language || 'code'}</span><pre class="language-${language || 'text'}"><button class="copy-button" onclick="copyCode(this)">Copy</button><code>`;
2020
} else {
2121
// End of a code block
2222
inCodeBlock = false;
@@ -81,6 +81,8 @@ function convertMarkdownToHTML(md) {
8181
}, 2000);
8282
}
8383
function highlightAll(text) {
84+
// console.log(text);
85+
8486
// Ensure the text is a valid string
8587
if (typeof text !== 'string') {
8688
console.error("Invalid argument: 'text' must be a string.");
@@ -91,9 +93,13 @@ function highlightAll(text) {
9193
const tempDiv = document.createElement('div');
9294
tempDiv.innerHTML = text; // Set the text as HTML content
9395

96+
console.log(tempDiv);
9497
// Get all the <code> elements inside the temporary element
95-
const codeElements = tempDiv.querySelectorAll('code');
9698

99+
const parser = new DOMParser();
100+
const decodedHTML = parser.parseFromString(text, 'text/html').body.innerHTML;
101+
tempDiv.innerHTML = decodedHTML;
102+
const codeElements = tempDiv.querySelectorAll('code');
97103
// If no <code> blocks are found, return the original text
98104
if (codeElements.length === 0) {
99105
console.log("No code blocks found.");

static/script.js

Lines changed: 87 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ function startMessage(speaker) {
9797
if (speaker === "bot" && loadingIndicator) {
9898
loadingIndicator.remove();
9999
console.log("loadingremoved");
100-
101100
}
102101
}
103102
// Function to add content to the current message
@@ -166,42 +165,107 @@ function set_model() {
166165
const modelSelected = document.getElementById("select_model_btn").value;
167166

168167
}
169-
// Function to handle user input and send it to the server
170-
function sendUserInput() {
171-
const inputField = document.getElementById("userInput");
172-
const userPrompt = inputField.value.trim();
173-
const modelSelected = localStorage.getItem("selectedModel");
174-
175-
if (!modelSelected) {
176-
alert("Please select a model");
177-
return;
168+
169+
function processQueue() {
170+
if (!isSpeaking && textQueue.length > 0) {
171+
const sentence = textQueue.shift(); // Get the next sentence from the queue
172+
cleanText(sentence); // Prepare the text and start TTS
173+
isSpeaking = true; // Set speaking status to true while TTS is active
174+
}
175+
}
176+
177+
// Function to end the current message and optionally show a loading indicator
178+
function endMessage() {
179+
highlightAll();
180+
cleanText(text);
181+
text = "";
182+
response_content = "";
183+
flow = false;
184+
if (currentSpeaker === "user") {
185+
console.log("user");
186+
showLoadingIndicator("Thinking...")
187+
}
188+
currentSpeaker = null;
178189
}
179190

180-
if (userPrompt) {
181-
fetch("/get_response", {
191+
// Function to show a loading indicator
192+
function showLoadingIndicator(text) {
193+
// Create the loading indicator element
194+
loadingIndicator = document.createElement("div");
195+
loadingIndicator.className = "loading";
196+
loadingIndicator.innerHTML = text;
197+
// Ensure messageContent is defined and append the loading indicator
198+
if (messageContent) {
199+
messageDiv.appendChild(loadingIndicator);
200+
console.log(messageDiv, loadingIndicator);
201+
202+
} else {
203+
console.error("messageContent is not defined");
204+
}
205+
}
206+
207+
208+
// Function to handle user input and send it to the server
209+
function sendUserInput() {
210+
const inputField = document.getElementById("userInput");
211+
const userPrompt = inputField.value.trim();
212+
const modelSelected = localStorage.getItem("selectedModel");
213+
if (!modelSelected) {
214+
alert("Please select a model");
215+
return;
216+
}
217+
218+
if (userPrompt) {
219+
fetch("/get_response", {
220+
method: "POST",
221+
headers: { "Content-Type": "application/json" },
222+
body: JSON.stringify({ prompt: userPrompt, model_need: modelSelected }),
223+
})
224+
.then((response) => response.json())
225+
.then((data) => {
226+
console.log("Response received:", data.response);
227+
})
228+
.catch((error) => console.error("Error:", error));
229+
230+
inputField.value = ""; // Clear input field
231+
}
232+
}
233+
234+
// Function to create options for the model selection dropdown
235+
function createModelOption(name) {
236+
const selectElement = document.getElementById("select_model_btn");
237+
const option = document.createElement("option");
238+
option.value = name;
239+
option.textContent = name;
240+
selectElement.appendChild(option);
241+
}
242+
243+
// Fetch the list of models from the server and populate the dropdown
244+
function get_list() {
245+
fetch("/list_request", {
182246
method: "POST",
183247
headers: { "Content-Type": "application/json" },
184248
body: JSON.stringify({ prompt: userPrompt, model_need: modelSelected, new_chat: new_chat }),
185249
})
186250
.then((response) => response.json())
187251
.then((data) => {
188-
console.log("Response received:", data.response);
252+
localStorage.setItem("list", JSON.stringify(data));
253+
data.list.models.forEach((model) => createModelOption(model.name));
254+
data.list.models.forEach((model) => createModalList(model.name));
255+
showNotification("List fetched successfully");
256+
save_log("List fetched successfully");
189257
})
190258
.catch((error) => console.error("Error:", error));
191259

192260
inputField.value = ""; // Clear input field
193261
new_chat = false;
194262
}
195-
}
196263

197-
// Function to create options for the model selection dropdown
198-
function createModelOption(name) {
199-
const selectElement = document.getElementById("select_model_btn");
200-
const option = document.createElement("option");
201-
option.value = name;
202-
option.textContent = name;
203-
selectElement.appendChild(option);
204-
}
264+
// Event listeners for submitting input
265+
document.getElementById("submitButton").onclick = sendUserInput;
266+
document.getElementById("userInput").addEventListener("keypress", (event) => {
267+
if (!flow && event.key === "Enter") sendUserInput();
268+
});
205269

206270
// Fetch the list of models from the server and populate the dropdown
207271
function get_list() {
@@ -309,8 +373,7 @@ eventSource.onmessage = function (event) {
309373
addContent(response);
310374
break;
311375
}
312-
};
313-
376+
}
314377
// Function to copy text to clipboard
315378
function copyToClipboard(text) {
316379
const textArea = document.createElement("textarea");
@@ -323,7 +386,3 @@ function copyToClipboard(text) {
323386
document.body.removeChild(textArea);
324387
// alert("Copied to clipboard!");
325388
}
326-
const lastMessage = messageDiv.lastElementChild;
327-
if (lastMessage) {
328-
lastMessage.scrollIntoView({ behavior: "smooth" });
329-
}

static/styles.css

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
margin: 0;
55
padding: 0;
66
}
7+
:root {
8+
--base_grey: #262626;
9+
--base_light_icon: rgb(206, 206, 206);
10+
--base_active_icon: #ffffff;
11+
--base_green: #44d7b6;
12+
--base_main:#1e1e2f;
13+
--base_input_active:#393a4f;
14+
--base_input:#393a4f79;
15+
--base_secondary:#663399;
16+
}
717

818
:root {
919
--base_grey: #262626;
@@ -81,7 +91,6 @@ body {
8191

8292
/* Section_a
8393
*/
84-
8594
.section_a {
8695
display: flex;
8796
width: 350px;
@@ -249,7 +258,22 @@ body {
249258
background-color: #2a243d;
250259
transition: 0.5s;
251260
}
252-
261+
/* Headingbar */
262+
.heading_bar{
263+
display: flex;
264+
padding: 4px;
265+
}
266+
.heading div{
267+
margin: 0px 20px;
268+
font-size: 25px;
269+
}
270+
.toogle_section{
271+
margin: 10px 10px;
272+
}
273+
.toogle_section :hover{
274+
background-color: #2a243d;
275+
transition: 0.5s;
276+
}
253277
/* Chat Area */
254278
#new_msg {
255279
overflow-y: auto;

0 commit comments

Comments
 (0)