-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from SkywardAI/rag-implement
implement RAG features
- Loading branch information
Showing
18 changed files
with
605 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,74 @@ | ||
/** | ||
* create a normal setting section | ||
* @param { "text" | "select" } type What type this section should contains | ||
* @param { "text" | "select" | "button" } type What type this section should contains | ||
* @param {String} title Name of this secction, apperas on top | ||
* @param {Function} callback Callback function takes one parameter of updated value of this section | ||
* @returns { [HTMLElement, Function] } Returns an array where index 0 is the element of section and index 1 is the setter function | ||
* @returns { [HTMLElement, Function, Function] } | ||
* Returns an array containes necessary fields | ||
* **Index 0**: The HTMLElement | ||
* **Index 1**: The setter function to update value | ||
* **Index 2**: The setter function to update args | ||
*/ | ||
export default function normalSettigSection(type, title, callback, ...args) { | ||
export default function normalSettigSection(type, title, callback = null, ...args) { | ||
const section = document.createElement('div'); | ||
section.className = 'setting-section' | ||
section.innerHTML = `<div class='title'>${title}</div>`; | ||
|
||
let input_like; | ||
if(type === 'text') { | ||
input_like = document.createElement('input'); | ||
input_like.type = 'text'; | ||
} else if(type === 'select') { | ||
|
||
function setArgs(...new_args) { | ||
args = new_args; | ||
loadArgs(); | ||
} | ||
|
||
function loadArgs() { | ||
if(type === 'select') { | ||
input_like.innerHTML = ''; | ||
args[0].forEach(({value, title})=>{ | ||
const option = document.createElement('option'); | ||
option.value = value; | ||
option.textContent = title || value; | ||
input_like.appendChild(option); | ||
}) | ||
} else if(type === 'button') { | ||
input_like.value = args[0]; | ||
input_like.onclick = args[1]; | ||
input_like.classList.add('clickable') | ||
} | ||
} | ||
|
||
if(type === 'select') { | ||
input_like = document.createElement('select'); | ||
args[0].forEach(({value, title})=>{ | ||
const option = document.createElement('option'); | ||
option.textContent = title || value; | ||
input_like.appendChild(option); | ||
}) | ||
} else { | ||
input_like = document.createElement('input'); | ||
input_like.type = type; | ||
} | ||
|
||
function setter(value) { | ||
loadArgs(); | ||
|
||
function setValue(value) { | ||
input_like.value = value; | ||
} | ||
|
||
function toggleDisable(is_disabled) { | ||
switch(type) { | ||
case 'text': | ||
input_like.disable = is_disabled; | ||
break; | ||
case 'button': | ||
input_like.onclick = is_disabled ? null : args[1]; | ||
break; | ||
case 'select': | ||
input_like.classList.toggle('disabled', is_disabled); | ||
break; | ||
} | ||
} | ||
|
||
input_like.onchange = () => { | ||
callback(input_like.value); | ||
callback && callback(input_like.value); | ||
} | ||
|
||
section.appendChild(input_like) | ||
|
||
return [section, setter]; | ||
return [section, { setValue, setArgs, toggleDisable }]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.