Merge pull request #47 from ParisNeo/flask_sse

Fixed encodingissues
This commit is contained in:
Saifeddine ALOUI 2023-04-08 18:01:16 +02:00 committed by GitHub
commit b4301c7251
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 107 deletions

24
app.py
View File

@ -236,7 +236,7 @@ GPT4All:Welcome! I'm here to assist you with anything you need. What can I do fo
top_p=self.args.top_p,
repeat_penalty=self.args.repeat_penalty,
repeat_last_n = self.args.repeat_last_n,
#seed=self.args.seed,
seed=self.args.seed,
n_threads=8
)
print(f"Bot said:{self.bot_says}")
@ -267,7 +267,7 @@ GPT4All:Welcome! I'm here to assist you with anything you need. What can I do fo
self.bot_says += text
if self.current_message in self.full_text:
self.is_bot_text_started = True
yield text
yield text.encode('utf-8').decode('latin-1')
def add_endpoint(
self,
@ -339,7 +339,7 @@ GPT4All:Welcome! I'm here to assist you with anything you need. What can I do fo
)
self.current_discussion.update_message(response_id, self.bot_says)
yield self.bot_says
yield self.bot_says.encode('utf-8').decode('latin-1')
# TODO : change this to use the yield version in order to send text word by word
return "\n".join(bot_says)
@ -458,18 +458,24 @@ GPT4All:Welcome! I'm here to assist you with anything you need. What can I do fo
def update_model_params(self):
data = request.get_json()
self.args.model = str(data["model"])
self.args.n_predict = int(data["nPredict"])
self.args.seed = int(data["seed"])
self.args.temp = float(data["temp"])
self.args.top_k = float(data["top_k"])
self.args.top_p = float(data["top_p"])
self.args.repeat_penalty = float(data["repeat_penalty"])
self.args.repeat_last_n = float(data["repeat_last_n"])
self.args.top_k = int(data["topK"])
self.args.top_p = float(data["topP"])
self.args.repeat_penalty = int(data["repeatPenalty"])
self.args.repeat_last_n = int(data["repeatLastN"])
print("Parameters changed to:")
print(f"\tTemperature:{self.args.temp}")
print(f"\tNPredict:{self.args.n_predict}")
print(f"\tSeed:{self.args.seed}")
print(f"\top_k:{self.args.top_k}")
print(f"\top_p:{self.args.top_p}")
print(f"\repeat_penalty:{self.args.repeat_penalty}")
print(f"\repeat_last_n:{self.args.repeat_last_n}")
print(f"\trepeat_penalty:{self.args.repeat_penalty}")
print(f"\trepeat_last_n:{self.args.repeat_last_n}")
return jsonify({"status":"ok"})

View File

@ -160,103 +160,6 @@ function addMessage(sender, message, id, can_edit=false) {
return {'messageTextElement':messageTextElement, 'hiddenElement':hiddenElement}
}
function add_collapsible_div(discussion_title, text, id) {
// Create the outer box element
const box = document.createElement('div');
box.classList.add('bg-gray-100', 'rounded-lg', 'p-4');
// Create the title element
const title = document.createElement('h2');
title.classList.add('text-lg', 'font-medium');
title.textContent = discussion_title;
// Create the toggle button element
const toggleBtn = document.createElement('button');
toggleBtn.classList.add('focus:outline-none');
toggleBtn.id = `${id}-toggle-btn`;
// Create the expand icon element
const expandIcon = document.createElement('path');
expandIcon.id = `${id}-expand-icon`;
expandIcon.setAttribute('d', 'M5 5h10v10H5z');
// Create the collapse icon element
const collapseIcon = document.createElement('path');
collapseIcon.id = `${id}-collapse-icon`;
collapseIcon.setAttribute('d', 'M7 10h6');
// Add the icons to the toggle button element
toggleBtn.appendChild(expandIcon);
toggleBtn.appendChild(collapseIcon);
// Create the content element
const content = document.createElement('div');
content.id = `${id}-box-content`;
content.classList.add('mt-4');
content.textContent = text;
// Add the title, toggle button, and content to the box element
// Create the title and toggle button container element
const titleToggleContainer = document.createElement('div');
titleToggleContainer.classList.add('flex', 'justify-between', 'items-center');
// Add the title and toggle button to the container element
titleToggleContainer.appendChild(title);
titleToggleContainer.appendChild(toggleBtn);
// Add the container element to the box element
box.appendChild(titleToggleContainer);
box.appendChild(content);
// Add the box to the document
document.body.appendChild(box);
// Add the CSS styles to the head of the document
const css = `
#${id}-box-content {
max-height: 0;
overflow: hidden;
transition: max-height 0.2s ease-out;
}
#${id}-box-content.expanded {
max-height: 1000px;
transition: max-height 0.5s ease-in;
}
#${id}-toggle-btn:focus #${id}-collapse-icon {
display: block;
}
#${id}-toggle-btn:focus #${id}-expand-icon {
display: none;
}
#${id}-collapse-icon {
display: none;
}
`;
const head = document.head || document.getElementsByTagName('head')[0];
const style = document.createElement('style');
style.type = 'text/css';
style.appendChild(document.createTextNode(css));
head.appendChild(style);
// Add the JavaScript code to toggle the box
const toggleBtnEl = document.querySelector(`#${id}-toggle-btn`);
const boxContentEl = document.querySelector(`#${id}-box-content`);
toggleBtnEl.addEventListener('click', function() {
boxContentEl.classList.toggle('expanded');
});
return box
}
const welcome_message = `
<div>
<code>This is a very early testing Web UI of GPT4All chatbot.
@ -278,7 +181,6 @@ const welcome_message = `
</div>
<div>Welcome! I'm here to assist you with anything you need. What can I do for you today?</div>
`;
//welcome_message = add_collapsible_div("Note:", text, 'hints');
addMessage("GPT4ALL",welcome_message,0);

View File

@ -5,6 +5,7 @@ submitButton.addEventListener('click', (event) => {
event.preventDefault();
modelInput = document.getElementById('model');
seedInput = document.getElementById('seed');
tempInput = document.getElementById('temp');
nPredictInput = document.getElementById('n-predict');

View File

@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>GPT4All - WEBUI</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/chat.css') }}">
</head>