Merge branch 'main' into dev

This commit is contained in:
AndzejsP 2023-06-24 14:10:18 +03:00
commit 9f891f6b33
11 changed files with 265 additions and 186 deletions

10
app.py
View File

@ -484,7 +484,7 @@ class LoLLMsWebUI(LoLLMsAPPI):
elif setting_name== "model_name": elif setting_name== "model_name":
self.config["model_name"]=data['setting_value'] self.config["model_name"]=data['setting_value']
try: try:
self.binding.build_model() self.model = self.binding.build_model()
except Exception as ex: except Exception as ex:
print(f"Couldn't load model: [{ex}]") print(f"Couldn't load model: [{ex}]")
return jsonify({ "status":False, 'error':str(ex)}) return jsonify({ "status":False, 'error':str(ex)})
@ -497,16 +497,10 @@ class LoLLMsWebUI(LoLLMsAPPI):
self.config["binding_name"]=data['setting_value'] self.config["binding_name"]=data['setting_value']
try: try:
self.binding = BindingBuilder().build_binding(self.config, self.lollms_paths) self.binding = BindingBuilder().build_binding(self.config, self.lollms_paths)
try: self.model = None
self.binding.build_model()
except Exception as ex:
print(f"Couldn't load model: [{ex}]")
return jsonify({ "status":False, 'error':str(ex)})
except Exception as ex: except Exception as ex:
print(f"Couldn't build binding: [{ex}]") print(f"Couldn't build binding: [{ex}]")
return jsonify({"status":False, 'error':str(ex)}) return jsonify({"status":False, 'error':str(ex)})
else: else:
if self.config["debug"]: if self.config["debug"]:
print(f"Configuration {data['setting_name']} set to {data['setting_value']}") print(f"Configuration {data['setting_name']} set to {data['setting_value']}")

BIN
images/default_model.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

125
web/dist/assets/index-d3ac3109.js vendored Normal file

File diff suppressed because one or more lines are too long

8
web/dist/assets/index-f4372a0b.css vendored Normal file

File diff suppressed because one or more lines are too long

4
web/dist/index.html vendored
View File

@ -6,8 +6,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LoLLMS WebUI - Welcome</title> <title>LoLLMS WebUI - Welcome</title>
<script type="module" crossorigin src="/assets/index-39127af6.js"></script> <script type="module" crossorigin src="/assets/index-d3ac3109.js"></script>
<link rel="stylesheet" href="/assets/index-952f715f.css"> <link rel="stylesheet" href="/assets/index-f4372a0b.css">
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>

21
web/package-lock.json generated
View File

@ -14,8 +14,10 @@
"flowbite-vue": "^0.0.10", "flowbite-vue": "^0.0.10",
"highlight.js": "^11.8.0", "highlight.js": "^11.8.0",
"markdown-it": "^13.0.1", "markdown-it": "^13.0.1",
"markdown-it-attrs": "^4.1.6",
"markdown-it-emoji": "^2.0.2", "markdown-it-emoji": "^2.0.2",
"papaparse": "^5.4.1", "papaparse": "^5.4.1",
"prismjs": "^1.29.0",
"socket.io-client": "^4.6.1", "socket.io-client": "^4.6.1",
"vue": "^3.2.47", "vue": "^3.2.47",
"vue-router": "^4.1.6", "vue-router": "^4.1.6",
@ -2142,6 +2144,17 @@
"markdown-it": "bin/markdown-it.js" "markdown-it": "bin/markdown-it.js"
} }
}, },
"node_modules/markdown-it-attrs": {
"version": "4.1.6",
"resolved": "https://registry.npmjs.org/markdown-it-attrs/-/markdown-it-attrs-4.1.6.tgz",
"integrity": "sha512-O7PDKZlN8RFMyDX13JnctQompwrrILuz2y43pW2GagcwpIIElkAdfeek+erHfxUOlXWPsjFeWmZ8ch1xtRLWpA==",
"engines": {
"node": ">=6"
},
"peerDependencies": {
"markdown-it": ">= 9.0.0"
}
},
"node_modules/markdown-it-emoji": { "node_modules/markdown-it-emoji": {
"version": "2.0.2", "version": "2.0.2",
"resolved": "https://registry.npmjs.org/markdown-it-emoji/-/markdown-it-emoji-2.0.2.tgz", "resolved": "https://registry.npmjs.org/markdown-it-emoji/-/markdown-it-emoji-2.0.2.tgz",
@ -2594,6 +2607,14 @@
"node": ">=6.0.0" "node": ">=6.0.0"
} }
}, },
"node_modules/prismjs": {
"version": "1.29.0",
"resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.29.0.tgz",
"integrity": "sha512-Kx/1w86q/epKcmte75LNrEoT+lX8pBpavuAbvJWRXar7Hz8jrtF+e3vY751p0R8H9HdArwaCTNDDzHg/ScJK1Q==",
"engines": {
"node": ">=6"
}
},
"node_modules/proxy-from-env": { "node_modules/proxy-from-env": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",

View File

@ -16,8 +16,10 @@
"flowbite-vue": "^0.0.10", "flowbite-vue": "^0.0.10",
"highlight.js": "^11.8.0", "highlight.js": "^11.8.0",
"markdown-it": "^13.0.1", "markdown-it": "^13.0.1",
"markdown-it-attrs": "^4.1.6",
"markdown-it-emoji": "^2.0.2", "markdown-it-emoji": "^2.0.2",
"papaparse": "^5.4.1", "papaparse": "^5.4.1",
"prismjs": "^1.29.0",
"socket.io-client": "^4.6.1", "socket.io-client": "^4.6.1",
"vue": "^3.2.47", "vue": "^3.2.47",
"vue-router": "^4.1.6", "vue-router": "^4.1.6",

View File

@ -1,19 +1,24 @@
<template> <template>
<div class=" break-all "> <div class="break-all">
<div v-html="renderedMarkdown" class=""></div> <div v-html="renderedMarkdown" class=""></div>
</div> </div>
</template> </template>
<script> <script>
import { nextTick } from 'vue' import { nextTick } from 'vue';
import feather from 'feather-icons' import feather from 'feather-icons';
import MarkdownIt from 'markdown-it'; import MarkdownIt from 'markdown-it';
import emoji from 'markdown-it-emoji'; import emoji from 'markdown-it-emoji';
//import 'highlight.js/styles/tomorrow-night-blue.css' import hljs from 'highlight.js/lib/core';
//import 'highlight.js/styles/tokyo-night-dark.css' import 'highlight.js/styles/tomorrow-night-blue.css';
import hljs from 'highlight.js'; import 'highlight.js/styles/tokyo-night-dark.css';
import attrs from 'markdown-it-attrs';
function generateUniqueId() {
const timestamp = Date.now().toString();
const randomSuffix = Math.floor(Math.random() * 1000).toString();
return timestamp + randomSuffix;
}
const markdownIt = new MarkdownIt('commonmark', { const markdownIt = new MarkdownIt('commonmark', {
html: false, html: false,
@ -22,92 +27,124 @@ const markdownIt = new MarkdownIt('commonmark', {
linkify: true, linkify: true,
typographer: true, typographer: true,
highlight: (str, lang) => { highlight: (str, lang) => {
const language = hljs.highlight(str, { language: lang }).language
const languageCapital = language.charAt(0).toUpperCase() + language.slice(1);
if (lang && hljs.getLanguage(lang)) { if (lang && hljs.getLanguage(lang)) {
try { try {
const highlightedCode = hljs.highlight(lang, str).value;
return ( return (
'<div class="bg-bg-light-tone-panel dark:bg-bg-dark-tone-panel p-2 rounded-lg shadow-sm ">' + '<div class="bg-bg-light-tone-panel dark:bg-bg-dark-tone-panel p-2 rounded-lg shadow-sm">' +
languageCapital + lang +
'<button class="px-2 py-1 ml-10 mb-2 text-left p-2 text-sm font-medium bg-bg-dark-tone-panel dark:bg-bg-dark-tone rounded-lg hover:bg-primary dark:hover:bg-primary text-white text-xs transition-colors duration-200">' +
'<pre class=" hljs p-1 rounded-md break-all grid grid-cols-1 ">' + '<span class="mr-1" id="copy-btn" onclick="copyContentToClipboard(' +
id +
'<code class="overflow-x-auto break-all scrollbar-thin scrollbar-track-bg-light-tone scrollbar-thumb-bg-light-tone-panel hover:scrollbar-thumb-primary dark:scrollbar-track-bg-dark-tone dark:scrollbar-thumb-bg-dark-tone-panel dark:hover:scrollbar-thumb-primary active:scrollbar-thumb-secondary ">' + ')">Copy</span>' +
hljs.highlightAuto(str).value + '<span class="hidden text-xs text-green-500" id="copyed-btn_' +
'</code></pre>' + '</div>' id +
'" onclick="copyContentToClipboard(' +
id +
')">Copied!</span>' +
'</button>' +
'<pre class="hljs p-1 rounded-md break-all grid grid-cols-1">' +
'<code id="code_' +
id +
'" class="overflow-x-auto break-all scrollbar-thin scrollbar-track-bg-light-tone scrollbar-thumb-bg-light-tone-panel hover:scrollbar-thumb-primary dark:scrollbar-track-bg-dark-tone dark:scrollbar-thumb-bg-dark-tone-panel dark:hover:scrollbar-thumb-primary active:scrollbar-thumb-secondary">' +
highlightedCode +
'</code>' +
'</pre>' +
'</div>'
); );
} catch (error) {
} catch (__) { } console.error(`Syntax highlighting failed for language '${lang}':`, error);
}
} }
let id = generateUniqueId();
return ( let codeString =
'<div class="bg-bg-light-tone-panel dark:bg-bg-dark-tone-panel p-2 rounded-lg shadow-sm ">' + '<div class="bg-bg-light-tone-panel dark:bg-bg-dark-tone-panel p-2 rounded-lg shadow-sm">' +
languageCapital + lang +
'<button class="px-2 py-1 ml-10 mb-2 text-left p-2 text-sm font-medium bg-bg-dark-tone-panel dark:bg-bg-dark-tone rounded-lg hover:bg-primary dark:hover:bg-primary text-white text-xs transition-colors duration-200">' +
'<pre class=" hljs p-1 rounded-md break-all grid grid-cols-1 ">' + '<span class="mr-1" id="copy-btn_' +
id +
'<code class="overflow-x-auto break-all scrollbar-thin scrollbar-track-bg-light-tone scrollbar-thumb-bg-light-tone-panel hover:scrollbar-thumb-primary dark:scrollbar-track-bg-dark-tone dark:scrollbar-thumb-bg-dark-tone-panel dark:hover:scrollbar-thumb-primary active:scrollbar-thumb-secondary ">' + '" onclick="copyContentToClipboard(' +
id +
')">Copy</span>' +
'<span class="hidden text-xs text-green-500" id="copyed-btn_' +
id +
'" onclick="copyContentToClipboard(' +
id +
')">Copied!</span>' +
'</button>' +
'<pre class="hljs p-1 rounded-md break-all grid grid-cols-1">' +
'<code id="code_' +
id +
'" class="overflow-x-auto break-all scrollbar-thin scrollbar-track-bg-light-tone scrollbar-thumb-bg-light-tone-panel hover:scrollbar-thumb-primary dark:scrollbar-track-bg-dark-tone dark:scrollbar-thumb-bg-dark-tone-panel dark:hover:scrollbar-thumb-primary active:scrollbar-thumb-secondary">' +
markdownIt.utils.escapeHtml(str) + markdownIt.utils.escapeHtml(str) +
'</code></pre>' + '</div>' '</code>' +
); '</pre>' +
'</div>';
} return codeString;
}).use(emoji); },
}).use(emoji).use(attrs); // Add attrs plugin for adding attributes to elements
export default { export default {
name: 'MarkdownRenderer', name: 'MarkdownRenderer',
props: { props: {
markdownText: { markdownText: {
type: String, type: String,
required: true required: true,
} },
}, },
data() { data() {
return { return {
renderedMarkdown: '', renderedMarkdown: '',
isCopied: false,
}; };
}, },
mounted() {
mounted() {
const script = document.createElement('script');
script.textContent = `
// Your inline script code here
console.log('Inline script executed!');
function copyContentToClipboard(id) {
console.log("copied");
const codeElement = document.getElementById('code_' + id);
const copybtnElement = document.getElementById('copy-btn_' + id);
const copyedbtnElement = document.getElementById('copyed-btn_' + id);
copybtnElement.classList.add('hidden');
copyedbtnElement.classList.remove('hidden');
const range = document.createRange();
range.selectNode(codeElement);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand('copy');
window.getSelection().removeAllRanges();
this.isCopied = true;
setTimeout(() => {
this.isCopied = false;
}, 1500);
}
`;
script.async = true; // Set to true if the script should be loaded asynchronously
document.body.appendChild(script);
this.renderedMarkdown = markdownIt.render(this.markdownText); this.renderedMarkdown = markdownIt.render(this.markdownText);
nextTick(() => { nextTick(() => {
feather.replace() feather.replace();
});
})
},
created() {
},
methods: {
copyContentToClipboard() {
navigator.clipboard.writeText(theCode);
},
}, },
methods: {},
watch: { watch: {
markdownText(newText) { markdownText(newText) {
this.renderedMarkdown = markdownIt.render(newText); this.renderedMarkdown = markdownIt.render(newText);
nextTick(() => { nextTick(() => {
feather.replace() feather.replace();
});
})
}, },
}, },
computed: {
}
}; };
</script> </script>
<style type='text/css'></style> <style>
/* Include any additional styles you need */
</style>

View File

@ -377,8 +377,8 @@ export default {
async stop_gen() { async stop_gen() {
try { try {
socket.emit('cancel_generation', {}); socket.emit('cancel_generation');
const res = await axios.get('/stop_gen') //const res = await axios.get('/stop_gen')
if (res) { if (res) {
return res.data return res.data