Added preset information

This commit is contained in:
Saifeddine ALOUI 2023-08-23 01:35:22 +02:00
parent eccc164006
commit 6e284ed346
9 changed files with 251 additions and 121 deletions

60
app.py
View File

@ -45,6 +45,8 @@ def run_update_script(args=None):
os.system(f"python {update_script}")
sys.exit(0)
from lollms.helpers import ASCIIColors, get_trace_exception, trace_exception
try:
import git
@ -58,7 +60,6 @@ try:
from lollms.binding import LOLLMSConfig, BindingBuilder
from lollms.personality import AIPersonality
from lollms.config import BaseConfig
from lollms.helpers import ASCIIColors, get_trace_exception, trace_exception
from lollms.paths import LollmsPaths
from api.db import Discussion
@ -87,8 +88,7 @@ try:
import socket
except Exception as ex:
print(ex)
print("Error importing some libraries. Updating lollms...")
trace_exception(ex)
run_update_script()
@ -333,14 +333,6 @@ class LoLLMsWebUI(LoLLMsAPPI):
"/delete_message", "delete_message", self.delete_message, methods=["GET"]
)
self.add_endpoint(
"/set_binding", "set_binding", self.set_binding, methods=["POST"]
)
self.add_endpoint(
"/set_model", "set_model", self.set_model, methods=["POST"]
)
self.add_endpoint(
"/get_config", "get_config", self.get_config, methods=["GET"]
@ -704,6 +696,15 @@ class LoLLMsWebUI(LoLLMsAPPI):
self.config["model_name"]=data['setting_value']
if self.config["model_name"] is not None:
try:
if self.binding:
self.binding.destroy_model()
self.binding = None
self.model = None
for per in self.mounted_personalities:
per.model = None
gc.collect()
self.binding = BindingBuilder().build_binding(self.config, self.lollms_paths)
self.model = self.binding.build_model()
self.rebuild_personalities(reload_all=True)
except Exception as ex:
@ -1615,42 +1616,7 @@ class LoLLMsWebUI(LoLLMsAPPI):
ASCIIColors.yellow("Message deleted")
return jsonify({"status":True,"new_rank": new_rank})
def set_binding(self):
data = request.get_json()
binding = str(data["binding"])
if self.config['binding_name']!= binding:
print("New binding selected")
self.config['binding_name'] = binding
try:
binding_ =self.process.load_binding(config["binding_name"],True)
models = binding_.list_models(self.config)
if len(models)>0:
self.binding = binding_
self.config['model_name'] = models[0]
# Build chatbot
return jsonify(self.process.set_config(self.config))
else:
return jsonify({"status": "no_models_found"})
except :
return jsonify({"status": "failed"})
return jsonify({"status": "error"})
def set_model(self):
data = request.get_json()
model = str(data["model_name"])
if self.config['model_name']!= model:
print("set_model: New model selected")
self.config['model_name'] = model
# Build chatbot
return jsonify(self.process.set_config(self.config))
return jsonify({"status": "succeeded"})
def get_available_models(self):
"""Get the available models

View File

@ -1,20 +1,14 @@
{
"Build a Latex Book": "@<Add some context information to give the AI some context about the book or leave blank if you have no specific idea>@\n```latex\n\\documentclass[12pt]{book}\n\\usepackage{url}\n\\begin{document}\n\\title{@<Put the title of the book here>@}\n\\author{@<Put the author name here>@} % Author\n\\date{\\today} % Date\n\\maketitle\n\\tableofcontents\n\\chapter{Introduction}\n@<Add any required text then press generate to push the AI to build your book>@\n\\end{document}\n```", "Simple Book writing":"Once apon a time",
"Simple Question Answer":"User:@<Put your question here>@\nAssistant:",
"Question Answer with conditionning":"Assistant is a highly developed AI capable of answering any question about any subject.\nUser:@<Put your question here>\nAssistant:",
"Instruct mode": "Instructions:\n@<Put your instructions here>@\nAnswer:",
"Make full python code": "```python\n# project: @<project name>@ \n# author: @<author of the project>@\n# description: @<The description of the code>@\n\n@<Place holder for text generation>@\n```\n---------\nExtra information:\nLicence: apache 2.0\nProgram type: Stand alone.\nDocumentation:\nMake README.md with the following table of contents:\n## Description\n## Installation\n## Usage\n## Licence\n## Contribute\n## Ethical guidelines\nInstructions:\nWrite a user side README.md\nStick to the provided code content and do not invent extra information.\nMake sure all sections of the table of contents are present in the file.\n----\nREADME.md:\n```markdown\n@<Place holder for text generation>@\n```",
"Make a python function": "Here is a python function that @<describe the function you want lollms to build>@:\n```python\ndef",
"Make a c++ function": "Here is a c++ function that @<describe the function you want lollms to build>@:\n```c++\n/*",
"Make a c# function": "Here is a c# function that @<describe the function you want lollms to build>@:\n```c#\n/*",
"Make a objective-c function": "Here is a objective-c function that @<describe the function you want lollms to build>@:\n```objective-c\n/*",
"Make a java function": "Here is a java function that @<describe the function you want lollms to build>@:\n```java\n/*",
"Make a visual basic.net function": "Here is a visual basic function that <describe the function you want lollms to build>@:\n```vb.net\n/*",
"Make a vue.js ui": "Here is a vue.js template that @<describe the user interface you want to make with this>@:\n```vue.js\n<template>",
"Make a HTML5 ui": "Here is a HTML5 ui that @<describe the user interface you want to make with this>@:\n```html",
"Explain code": "```@<the name of the programming language>\n@<put your code here>@\n```\nHere is an explanation of the previous method:",
"Translate yaml file": "Instruction: Translate the comments and values of the yaml file from english to French.\nSession 1:\n```yaml language=english\n# This is a comment\nparameter_1: this is parameter 1\nparameter_2: this is parameter 2\nparameter_3: 25\nparameter_4: |\n This is a multi\n line parameter\n```\n```yaml language=french\n# Ceci est un commentaire\nparameter_1: ceci est le param\u00e8tre 1\nparameter_2: ceci est le param\u00e8tre 2\nparameter_3: 25\nparameter_4: |\n Ceci est une multiligne\n ligne de param\u00e8tre\n```\nSession 2:\n```yaml language=english\n@<Put your yaml data here>@\n```\n```yaml language=french",
"Translate json file": "Instruction: Translate the values of the json file from english to French.\nSession 1:\n```json language=english\n{\n\"parameter_1\": \"this is parameter 1\",\n\"parameter_2\": \"this is parameter 2\",\n\"parameter_3\": 25,\n\"parameter_4\": \"This is a multi\\nline string\",\n}\n```\nAfter translation, we get:\n```json language=french\n{\n\"parameter_1\": \"ceci est le param\u00e8tre 1\",\n\"parameter_2\": \"ceci est le param\u00e8tre 2\",\n\"parameter_3\": 25,\n\"parameter_4\": \"Ceci est une cha\u00eene de caract\u00e8res multiligne\\n\",\n}\n```\nSession 2:\n```json language=english\n@<Put your json data here>@\n```\n```json language=french\n",
"Translate python strings": "Instruction: Translate the strings inside this python code.\nSession 1:\n```python language=english\na = input(\"a:\")\nprint(f\"you have input the value {a}\")\n```\nAfter translation, we get:\n```python language=fr\na = input(\"a:\")\nprint(f\"vous avez entr\u00e9 la valeur {a}\")\n```\nSession 2:\n```python language=@<source language example: english>@\n@<Put your python code here>@\n```\n```python language=@<source language example: french>@\n@<Remove this placeholder and place the cursor in here then press Generate Text>@\n```\n",
"Generic translator": "```@<put your source language name here. example english>@\n@<Put your english text here>@\n```\n```@<put your destination language name here. example french>@\n@<Remove this block and place the cursor here to make the AI generate the translation>@\n```\n"
"Build a Latex Book": "@<Add some context information to give the AI some context about the book or leave blank if you have no specific idea>@\n```latex\n\\documentclass[12pt]{book}\n\\usepackage{url}\n\\begin{document}\n\\title{@<Title of the book>@}\n\\author{@<Author name>@} % Author\n\\date{\\today} % Date\n\\maketitle\n\\tableofcontents\n\\chapter{Introduction}\n@<generation_placeholder>@\n\\end{document}\n```",
"Simple Book writing":"Once apon a time",
"Simple Question Answer":"User:@<What is your question>@\nAssistant:@<generation_placeholder>@",
"Question Answer with conditionning":"Assistant is a highly developed AI capable of answering any question about any subject.\nUser:@<What's your question?>\nAssistant:@<generation_placeholder>@",
"Instruct mode": "Instructions:\n@<Give instructions to the AI>@\nAnswer:@<generation_placeholder>@",
"Code explainer": "# Code\n```@<Programming language:python>@\n@<Code to document>@\n```\n# Documantation\n```markdown\n@<generation_placeholder>@\n```\n",
"Make a function": "Here is a @<Language:python:c:c++:java:javascript:php:ruby:go:swift:kotlin:rust:haskell:erlang:lisp:scheme:prolog:cobol:fortran:pascal:delphi:d:eiffel:h:basic:visual_basic:smalltalk:objective-c:html5:node.js:vue.js:svelte:react:angular:ember:clipper:stex:arduino:brainfuck:r:assembly:mason:lepton:seacat:bbc_microbit:raspberry_pi_gpio:raspberry_pi_spi:raspberry_pi_i2c:raspberry_pi_uart:raspberry_pi_adc:raspberry_pi_ddio@ function that @<describe the function you want lollms to build>@:\n```@<Language:python:c:c++:java:javascript:php:ruby:go:swift:kotlin:rust:haskell:erlang:lisp:scheme:prolog:cobol:fortran:pascal:delphi:d:eiffel:h:basic:visual_basic:smalltalk:objective-c:html5:node.js:vue.js:svelte:react:angular:ember:clipper:stex:arduino:brainfuck:r:assembly:mason:lepton:seacat:bbc_microbit:raspberry_pi_gpio:raspberry_pi_spi:raspberry_pi_i2c:raspberry_pi_uart:raspberry_pi_adc:raspberry_pi_ddio>@\n@<generation_placeholder>@",
"Fix a code": "Here is a @<Language:python:c:c++:java:javascript:php:ruby:go:swift:kotlin:rust:haskell:erlang:lisp:scheme:prolog:cobol:fortran:pascal:delphi:d:eiffel:h:basic:visual_basic:smalltalk:objective-c:html5:node.js:vue.js:svelte:react:angular:ember:clipper:stex:arduino:brainfuck:r:assembly:mason:lepton:seacat:bbc_microbit:raspberry_pi_gpio:raspberry_pi_spi:raspberry_pi_i2c:raspberry_pi_uart:raspberry_pi_adc:raspberry_pi_ddio>@ code:\n```@<Language:python:c:c++:java:javascript:php:ruby:go:swift:kotlin:rust:haskell:erlang:lisp:scheme:prolog:cobol:fortran:pascal:delphi:d:eiffel:h:basic:visual_basic:smalltalk:objective-c:html5:node.js:vue.js:svelte:react:angular:ember:clipper:stex:arduino:brainfuck:r:assembly:mason:lepton:seacat:bbc_microbit:raspberry_pi_gpio:raspberry_pi_spi:raspberry_pi_i2c:raspberry_pi_uart:raspberry_pi_adc:raspberry_pi_ddio>@\n@<Input your code>@\n```\nInstruction:Check this code and fix any errors if there are any.\nAI:@<generation_placeholder>@",
"Make programming project": "```@<Language:python:c:c++:java:javascript:php:ruby:go:swift:kotlin:rust:haskell:erlang:lisp:scheme:prolog:cobol:fortran:pascal:delphi:d:eiffel:h:basic:visual_basic:smalltalk:objective-c:html5:node.js:vue.js:svelte:react:angular:ember:clipper:stex:arduino:brainfuck:r:assembly:mason:lepton:seacat:bbc_microbit:raspberry_pi_gpio:raspberry_pi_spi:raspberry_pi_i2c:raspberry_pi_uart:raspberry_pi_adc:raspberry_pi_ddio>@\n# project: @<Project name>@ \n# author: @<Author name>@\n# description: @<The description of the code>@\n\n@<generation_placeholder>@\n```\n---------\nExtra information:\nLicence: apache 2.0\nProgram type: Stand alone.\nDocumentation:\nMake README.md with the following table of contents:\n## Description\n## Installation\n## Usage\n## Licence\n## Contribute\n## Ethical guidelines\nInstructions:\nWrite a user side README.md\nStick to the provided code content and do not invent extra information.\nMake sure all sections of the table of contents are present in the file.\n----\nREADME.md:\n```markdown\n@<generation_placeholder>@\n```",
"Explain code": "```@<Language:python:c:c++:java:javascript:php:ruby:go:swift:kotlin:rust:haskell:erlang:lisp:scheme:prolog:cobol:fortran:pascal:delphi:d:eiffel:h:basic:visual_basic:smalltalk:objective-c:html5:node.js:vue.js:svelte:react:angular:ember:clipper:stex:arduino:brainfuck:r:assembly:mason:lepton:seacat:bbc_microbit:raspberry_pi_gpio:raspberry_pi_spi:raspberry_pi_i2c:raspberry_pi_uart:raspberry_pi_adc:raspberry_pi_ddio>@\n@<put your code here>@\n```\nHere is an explanation of the previous method:",
"Translate code file": "Instruction: Translate the comments and values of the @<File type:yaml:json:python:c:c++:java:javascript:php:ruby:go:swift:kotlin:rust:haskell:erlang:lisp:scheme:prolog:cobol:fortran:pascal:delphi:d:eiffel:h:basic:visual_basic:smalltalk:objective-c:html5:node.js:vue.js:svelte:react:angular:ember:clipper:stex:arduino:brainfuck:r:assembly:mason:lepton:seacat:bbc_microbit:raspberry_pi_gpio:raspberry_pi_spi:raspberry_pi_i2c:raspberry_pi_uart:raspberry_pi_adc:raspberry_pi_ddio>@ file from @<Source language:english:french:german:chinese:japanese:spanish:italian:russian:portuguese:swedish:danish:dutch:norwegian:slovak:czech:hungarian:polish:ukrainian:bulgarian:latvian:lithuanian:estonian:maltese:irish:galician:basque:welsh:breton:georgian:turkmen:kazakh:uzbek:tajik:afghan:sri-lankan:filipino:vietnamese:lao:cambodian:thai:burmese:kenyan:botswanan:zimbabwean:malawian:mozambican:angolan:namibian:south-african:madagascan:seychellois:mauritian:haitian:peruvian:ecuadorian:bolivian:paraguayan:chilean:argentinean:uruguayan:brazilian:colombian:venezuelan:puerto-rican:cuban:dominican:honduran:nicaraguan:salvadorean:guatemalan:el-salvadoran:belizean:panamanian:costa-rican:antiguan:barbudan:dominica's:grenada's:st-lucia's:st-vincent's:gibraltarian:faroe-islander:greenlandic:icelandic:jamaican:trinidadian:tobagonian:barbadian:anguillan:british-virgin-islander:us-virgin-islander:turkish:israeli:palestinian:lebanese:egyptian:libyan:tunisian:algerian:moroccan:bahraini:kuwaiti:saudi-arabian:yemeni:omani:irani:iraqi:afghanistan's:pakistani:indian:nepalese:sri-lankan:maldivan:burmese:thai:lao:vietnamese:kampuchean:malaysian:bruneian:indonesian:australian:new-zealanders:fijians:tongans:samoans:vanuatuans:wallisians:kiribatians:tuvaluans:solomon-islanders:marshallese:micronesians:hawaiians> to @<Destination language:english:french:german:chinese:japanese:spanish:italian:russian:portuguese:swedish:danish:dutch:norwegian:slovak:czech:hungarian:polish:ukrainian:bulgarian:latvian:lithuanian:estonian:maltese:irish:galician:basque:welsh:breton:georgian:turkmen:kazakh:uzbek:tajik:afghan:sri-lankan:filipino:vietnamese:lao:cambodian:thai:burmese:kenyan:botswanan:zimbabwean:malawian:mozambican:angolan:namibian:south-african:madagascan:seychellois:mauritian:haitian:peruvian:ecuadorian:bolivian:paraguayan:chilean:argentinean:uruguayan:brazilian:colombian:venezuelan:puerto-rican:cuban:dominican:honduran:nicaraguan:salvadorean:guatemalan:el-salvadoran:belizean:panamanian:costa-rican:antiguan:barbudan:dominica's:grenada's:st-lucia's:st-vincent's:gibraltarian:faroe-islander:greenlandic:icelandic:jamaican:trinidadian:tobagonian:barbadian:anguillan:british-virgin-islander:us-virgin-islander:turkish:israeli:palestinian:lebanese:egyptian:libyan:tunisian:algerian:moroccan:bahraini:kuwaiti:saudi-arabian:yemeni:omani:irani:iraqi:afghanistan's:pakistani:indian:nepalese:sri-lankan:maldivan:burmese:thai:lao:vietnamese:kampuchean:malaysian:bruneian:indonesian:australian:new-zealanders:fijians:tongans:samoans:vanuatuans:wallisians:kiribatians:tuvaluans:solomon-islanders:marshallese:micronesians:hawaiians>.\nSession 1:\n```yaml language=english\n# This is a comment\nparameter_1: this is parameter 1\nparameter_2: this is parameter 2\nparameter_3: 25\nparameter_4: |\n This is a multi\n line parameter\n```\n```yaml language=french\n# Ceci est un commentaire\nparameter_1: ceci est le param\u00e8tre 1\nparameter_2: ceci est le param\u00e8tre 2\nparameter_3: 25\nparameter_4: |\n Ceci est une multiligne\n ligne de param\u00e8tre\n```\nSession 2:\n```yaml language=english\n@<Put your yaml data here>@\n```\n```yaml language=french",
"Translate text": "```@<Source language:english:french:german:chinese:japanese:spanish:italian:russian:portuguese:swedish:danish:dutch:norwegian:slovak:czech:hungarian:polish:ukrainian:bulgarian:latvian:lithuanian:estonian:maltese:irish:galician:basque:welsh:breton:georgian:turkmen:kazakh:uzbek:tajik:afghan:sri-lankan:filipino:vietnamese:lao:cambodian:thai:burmese:kenyan:botswanan:zimbabwean:malawian:mozambican:angolan:namibian:south-african:madagascan:seychellois:mauritian:haitian:peruvian:ecuadorian:bolivian:paraguayan:chilean:argentinean:uruguayan:brazilian:colombian:venezuelan:puerto-rican:cuban:dominican:honduran:nicaraguan:salvadorean:guatemalan:el-salvadoran:belizean:panamanian:costa-rican:antiguan:barbudan:dominica's:grenada's:st-lucia's:st-vincent's:gibraltarian:faroe-islander:greenlandic:icelandic:jamaican:trinidadian:tobagonian:barbadian:anguillan:british-virgin-islander:us-virgin-islander:turkish:israeli:palestinian:lebanese:egyptian:libyan:tunisian:algerian:moroccan:bahraini:kuwaiti:saudi-arabian:yemeni:omani:irani:iraqi:afghanistan's:pakistani:indian:nepalese:sri-lankan:maldivan:burmese:thai:lao:vietnamese:kampuchean:malaysian:bruneian:indonesian:australian:new-zealanders:fijians:tongans:samoans:vanuatuans:wallisians:kiribatians:tuvaluans:solomon-islanders:marshallese:micronesians:hawaiians>@\n@<Text to translate>@\n```\n```@<Destination language:english:french:german:chinese:japanese:spanish:italian:russian:portuguese:swedish:danish:dutch:norwegian:slovak:czech:hungarian:polish:ukrainian:bulgarian:latvian:lithuanian:estonian:maltese:irish:galician:basque:welsh:breton:georgian:turkmen:kazakh:uzbek:tajik:afghan:sri-lankan:filipino:vietnamese:lao:cambodian:thai:burmese:kenyan:botswanan:zimbabwean:malawian:mozambican:angolan:namibian:south-african:madagascan:seychellois:mauritian:haitian:peruvian:ecuadorian:bolivian:paraguayan:chilean:argentinean:uruguayan:brazilian:colombian:venezuelan:puerto-rican:cuban:dominican:honduran:nicaraguan:salvadorean:guatemalan:el-salvadoran:belizean:panamanian:costa-rican:antiguan:barbudan:dominica's:grenada's:st-lucia's:st-vincent's:gibraltarian:faroe-islander:greenlandic:icelandic:jamaican:trinidadian:tobagonian:barbadian:anguillan:british-virgin-islander:us-virgin-islander:turkish:israeli:palestinian:lebanese:egyptian:libyan:tunisian:algerian:moroccan:bahraini:kuwaiti:saudi-arabian:yemeni:omani:irani:iraqi:afghanistan's:pakistani:indian:nepalese:sri-lankan:maldivan:burmese:thai:lao:vietnamese:kampuchean:malaysian:bruneian:indonesian:australian:new-zealanders:fijians:tongans:samoans:vanuatuans:wallisians:kiribatians:tuvaluans:solomon-islanders:marshallese:micronesians:hawaiians>@\n@<Remove this block and place the cursor here to make the AI generate the translation>@\n```\n"
}

File diff suppressed because one or more lines are too long

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

File diff suppressed because one or more lines are too long

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">
<title>LoLLMS WebUI - Welcome</title>
<script type="module" crossorigin src="/assets/index-ba01d903.js"></script>
<link rel="stylesheet" href="/assets/index-004a018d.css">
<script type="module" crossorigin src="/assets/index-c2c8591c.js"></script>
<link rel="stylesheet" href="/assets/index-39c6717e.css">
</head>
<body>
<div id="app"></div>

View File

@ -283,7 +283,7 @@ export default {
const findLastSentenceIndex = (startIndex) => {
let txt = this.message.content.substring(startIndex, startIndex+chunkSize)
// Define an array of characters that represent end of sentence markers.
const endOfSentenceMarkers = ['.', '!', '?'];
const endOfSentenceMarkers = ['.', '!', '?', '\n'];
// Initialize a variable to store the index of the last end of sentence marker.
let lastIndex = -1;

View File

@ -100,12 +100,145 @@
</template>
<script>
import feather from 'feather-icons'
import axios from "axios";
import socket from '@/services/websocket.js'
import Toast from '../components/Toast.vue'
import MarkdownRenderer from '../components/MarkdownRenderer.vue';
async function showInputPanel(name, default_value="", options=[]) {
return new Promise((resolve, reject) => {
const panel = document.createElement("div");
panel.className = "fixed inset-0 flex items-center justify-center bg-black bg-opacity-50 z-50";
if(options.length===0){
panel.innerHTML = `
<div class="bg-white p-6 rounded-md shadow-md w-80">
<h2 class="text-lg font-semibold mb-3">"${name}"</h2>
<textarea id="replacementInput" class="w-full h-32 border rounded p-2 mb-3">${default_value}</textarea>
<div class="flex justify-end">
<button id="cancelButton" class="mr-2 px-4 py-2 border rounded">Cancel</button>
<button id="okButton" class="px-4 py-2 bg-blue-500 text-white rounded">OK</button>
</div>
</div>
`;
}
else{
panel.innerHTML = `
<div class="bg-white p-6 rounded-md shadow-md w-80">
<h2 class="text-lg font-semibold mb-3">"${name}"</h2>
<select id="options_selector" class="form-control w-full h-25 border rounded p-2 mb-3">
${options.map(option => `<option value="${option}">${option}</option>`)}
</select>
<div class="flex justify-end">
<button id="cancelButton" class="mr-2 px-4 py-2 border rounded">Cancel</button>
<button id="okButton" class="px-4 py-2 bg-blue-500 text-white rounded">OK</button>
</div>
</div>
`;
}
document.body.appendChild(panel);
const cancelButton = panel.querySelector("#cancelButton");
const okButton = panel.querySelector("#okButton");
cancelButton.addEventListener("click", () => {
document.body.removeChild(panel);
resolve(null);
});
okButton.addEventListener("click", () => {
if(options.length===0){
const input = panel.querySelector("#replacementInput");
const value = input.value.trim();
document.body.removeChild(panel);
resolve(value);
}
else{
const input = panel.querySelector("#options_selector");
const value = input.value.trim();
document.body.removeChild(panel);
resolve(value);
}
});
});
}
function replaceInText(text, callback) {
console.log(text)
let replacementDict = {};
let delimiterRegex = /@<([^>]+)>@/g;
let matches = [];
let match;
while ((match = delimiterRegex.exec(text)) !== null) {
matches.push("@<"+match[1]+">@"); // The captured group is at index 1
}
console.log("matches")
console.log(matches)
matches = [...new Set(matches)]
async function handleReplacement(match) {
console.log(match)
let placeholder = match.toLowerCase().substring(2,match.length-2);
if (placeholder !== "generation_placeholder") {
if (placeholder.includes(":")) {
let splitResult = placeholder.split(":");
let name = splitResult[0];
let defaultValue = splitResult[1] || "";
let options = [];
if (splitResult.length>2) {
options = splitResult.slice(1);
}
let replacement = await showInputPanel(name, defaultValue, options);
if (replacement !== null) {
replacementDict[match] = replacement;
}
}
else{
let replacement = await showInputPanel(placeholder);
if (replacement !== null) {
replacementDict[match] = replacement;
}
}
}else{
//var result = confirm("generation placeholder found. Do you want to generate?\nIf you skip generation, you still can generate manually after wards");
}
}
let promiseChain = Promise.resolve();
matches.forEach(match => {
promiseChain = promiseChain.then(() => {
return handleReplacement(match);
}).then(result => {
console.log(result);
});
});
promiseChain.then(() => {
Object.entries(replacementDict).forEach(([key, value]) => {
console.log(`Key: ${key}, Value: ${value}`);
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // Escape special characters
}
const escapedKey = escapeRegExp(key);
const regex = new RegExp(escapedKey, 'g');
text = text.replace(regex, value);
//text = text.replace(new RegExp(key, 'g'), value);
});
callback(text); // Call the callback after all matches are processed
});
}
// Get input value function
function getInputValue() {
const inputField = document.getElementById('input-field');
return inputField ? inputField.value : '';
}
export default {
name: 'PlayGroundView',
data() {
@ -137,10 +270,20 @@ export default {
mounted() {
const text_element = document.getElementById('text_element');
text_element.addEventListener('input', () => {
this.cursorPosition = text_element.selectionStart;
try{
this.cursorPosition = text_element.selectionStart;
}
catch{
}
});
text_element.addEventListener('click', () => {
this.cursorPosition = text_element.selectionStart;
try{
this.cursorPosition = text_element.selectionStart;
}
catch{
}
});
axios.get('./presets.json').then(response => {
console.log(response.data)
@ -260,7 +403,7 @@ export default {
const findLastSentenceIndex = (startIndex) => {
let txt = this.text.substring(startIndex, startIndex+chunkSize)
// Define an array of characters that represent end of sentence markers.
const endOfSentenceMarkers = ['.', '!', '?'];
const endOfSentenceMarkers = ['.', '!', '?', '\n'];
// Initialize a variable to store the index of the last end of sentence marker.
let lastIndex = -1;
@ -358,8 +501,13 @@ export default {
inputFile.click();
},
setPreset() {
this.text = this.presets[this.selectedPreset];
this.text = replaceInText(this.presets[this.selectedPreset], (text)=>{
console.log("Done")
console.log(text);
this.text= text
});
},
addPreset() {
let title = prompt('Enter the title of the preset:');
this.presets[title] = this.text

View File

@ -3438,7 +3438,7 @@ export default {
// console.log('did settings?',this.settingsChanged)
await this.$router.isReady()
if (this.settingsChanged) {
const res = await this.$refs.yesNoDialog.askQuestion("Did You forgot to apply changes?\nYou need to apply changes before you leave, or else.", 'Apply configuration', 'Cancel')
const res = await this.$refs.yesNoDialog.askQuestion("Did You forget to apply changes?\nYou need to apply changes before you leave, or else.", 'Apply configuration', 'Cancel')
if (res) {
this.applyConfiguration()