Fix for hash collisions as long as the mapping file specifies a name in addition

This commit is contained in:
DominikDoom
2023-07-13 18:27:51 +02:00
parent 3496fa58d9
commit 88fa4398c8
2 changed files with 24 additions and 2 deletions

View File

@@ -17,8 +17,16 @@ async function load() {
const parts = line.split(",");
const hash = parts[0];
const keywords = parts[1].replaceAll("| ", ", ").replaceAll("|", ", ").trim();
const name = parts[2]?.trim() || "none"
modelKeywordDict.set(hash, keywords);
if (modelKeywordDict.has(hash) && name !== "none") {
// Add a new name key if the hash already exists
modelKeywordDict.get(hash).set(name, keywords);
} else {
// Create new hash entry
let map = new Map().set(name, keywords);
modelKeywordDict.set(hash, map);
}
});
} catch (e) {
console.error("Error loading model-keywords list: " + e);

View File

@@ -447,7 +447,21 @@ async function insertTextAtCursor(textArea, result, tagword, tabCompletedWithout
let keywordsLength = 0;
if (TAC_CFG.modelKeywordCompletion && modelKeywordPath.length > 0 && (tagType === ResultType.lora || tagType === ResultType.lyco)) {
if (result.hash && result.hash !== "NOFILE" && result.hash.length > 0) {
let keywords = modelKeywordDict.get(result.hash);
let keywords = null;
let nameDict = modelKeywordDict.get(result.hash);
let name = result.text + ".safetensors";
console.log(name, nameDict);
if (nameDict) {
if (nameDict.size > 1)
keywords = nameDict.get(name);
else
keywords = nameDict.get("none");
}
console.log(keywords);
if (keywords && keywords.length > 0) {
newPrompt = `${keywords}, ${newPrompt}`;
keywordsLength = keywords.length + 2; // +2 for the comma and space