mirror of
				https://github.com/KoboldAI/KoboldAI-Client.git
				synced 2025-06-05 21:59:24 +02:00 
			
		
		
		
	Added VE_FORBRYDERNE's Selective World Info
This update allows you to selectively choose when World Info is loaded for more control and RAM savings.
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -5,3 +5,4 @@ client.settings | |||||||
| stories/* | stories/* | ||||||
| !stories/sample_story.json | !stories/sample_story.json | ||||||
| /.project | /.project | ||||||
|  | *.bak | ||||||
							
								
								
									
										43
									
								
								aiserver.py
									
									
									
									
									
								
							
							
						
						
									
										43
									
								
								aiserver.py
									
									
									
									
									
								
							| @@ -506,6 +506,10 @@ def get_message(msg): | |||||||
|             addwiitem() |             addwiitem() | ||||||
|     elif(msg['cmd'] == 'widelete'): |     elif(msg['cmd'] == 'widelete'): | ||||||
|         deletewi(msg['data']) |         deletewi(msg['data']) | ||||||
|  |     elif(msg['cmd'] == 'wiselon'): | ||||||
|  |         vars.worldinfo[msg['data']]["selective"] = True | ||||||
|  |     elif(msg['cmd'] == 'wiseloff'): | ||||||
|  |         vars.worldinfo[msg['data']]["selective"] = False | ||||||
|     elif(msg['cmd'] == 'sendwilist'): |     elif(msg['cmd'] == 'sendwilist'): | ||||||
|         commitwi(msg['data']) |         commitwi(msg['data']) | ||||||
|     elif(msg['cmd'] == 'aidgimport'): |     elif(msg['cmd'] == 'aidgimport'): | ||||||
| @@ -1240,7 +1244,7 @@ def togglewimode(): | |||||||
| #    | #    | ||||||
| #==================================================================# | #==================================================================# | ||||||
| def addwiitem(): | def addwiitem(): | ||||||
|     ob = {"key": "", "content": "", "num": len(vars.worldinfo), "init": False} |     ob = {"key": "", "keysecondary": "", "content": "", "num": len(vars.worldinfo), "init": False, "selective": False} | ||||||
|     vars.worldinfo.append(ob); |     vars.worldinfo.append(ob); | ||||||
|     emit('from_server', {'cmd': 'addwiitem', 'data': ob}) |     emit('from_server', {'cmd': 'addwiitem', 'data': ob}) | ||||||
|  |  | ||||||
| @@ -1292,7 +1296,9 @@ def organizewi(): | |||||||
| def commitwi(ar): | def commitwi(ar): | ||||||
|     for ob in ar: |     for ob in ar: | ||||||
|         vars.worldinfo[ob["num"]]["key"]          = ob["key"] |         vars.worldinfo[ob["num"]]["key"]          = ob["key"] | ||||||
|  |         vars.worldinfo[ob["num"]]["keysecondary"] = ob["keysecondary"] | ||||||
|         vars.worldinfo[ob["num"]]["content"]      = ob["content"] |         vars.worldinfo[ob["num"]]["content"]      = ob["content"] | ||||||
|  |         vars.worldinfo[ob["num"]]["selective"]    = ob["selective"] | ||||||
|     # Was this a deletion request? If so, remove the requested index |     # Was this a deletion request? If so, remove the requested index | ||||||
|     if(vars.deletewi >= 0): |     if(vars.deletewi >= 0): | ||||||
|         del vars.worldinfo[vars.deletewi] |         del vars.worldinfo[vars.deletewi] | ||||||
| @@ -1345,12 +1351,27 @@ def checkworldinfo(txt): | |||||||
|         if(wi["key"] != ""): |         if(wi["key"] != ""): | ||||||
|             # Split comma-separated keys |             # Split comma-separated keys | ||||||
|             keys = wi["key"].split(",") |             keys = wi["key"].split(",") | ||||||
|  |             keys_secondary = wi.get("keysecondary", "").split(",") | ||||||
|  |  | ||||||
|             for k in keys: |             for k in keys: | ||||||
|                 ky = k |                 ky = k | ||||||
|                 # Remove leading/trailing spaces if the option is enabled |                 # Remove leading/trailing spaces if the option is enabled | ||||||
|                 if(vars.wirmvwhtsp): |                 if(vars.wirmvwhtsp): | ||||||
|                     ky = k.strip() |                     ky = k.strip() | ||||||
|                 if ky in txt: |                 if ky in txt: | ||||||
|  |                     if wi.get("selective", False) and len(keys_secondary): | ||||||
|  |                         found = False | ||||||
|  |                         for ks in keys_secondary: | ||||||
|  |                             ksy = ks | ||||||
|  |                             if(vars.wirmvwhtsp): | ||||||
|  |                                 ksy = ks.strip() | ||||||
|  |                             if ksy in txt: | ||||||
|  |                                 wimem = wimem + wi["content"] + "\n" | ||||||
|  |                                 found = True | ||||||
|  |                                 break | ||||||
|  |                         if found: | ||||||
|  |                             break | ||||||
|  |                     else: | ||||||
|                         wimem = wimem + wi["content"] + "\n" |                         wimem = wimem + wi["content"] + "\n" | ||||||
|                         break |                         break | ||||||
|      |      | ||||||
| @@ -1549,7 +1570,9 @@ def saveRequest(savpath): | |||||||
|             if(wi["key"] != ""): |             if(wi["key"] != ""): | ||||||
|                 js["worldinfo"].append({ |                 js["worldinfo"].append({ | ||||||
|                     "key": wi["key"], |                     "key": wi["key"], | ||||||
|                     "content": wi["content"] |                     "keysecondary": wi["keysecondary"], | ||||||
|  |                     "content": wi["content"], | ||||||
|  |                     "selective": wi["selective"] | ||||||
|                 }) |                 }) | ||||||
|          |          | ||||||
|         # Write it |         # Write it | ||||||
| @@ -1606,9 +1629,11 @@ def loadRequest(loadpath): | |||||||
|             for wi in js["worldinfo"]: |             for wi in js["worldinfo"]: | ||||||
|                 vars.worldinfo.append({ |                 vars.worldinfo.append({ | ||||||
|                     "key": wi["key"], |                     "key": wi["key"], | ||||||
|  |                     "keysecondary": wi.get("keysecondary", ""), | ||||||
|                     "content": wi["content"], |                     "content": wi["content"], | ||||||
|                     "num": num, |                     "num": num, | ||||||
|                     "init": True |                     "init": True, | ||||||
|  |                     "selective": wi.get("selective", False) | ||||||
|                 }) |                 }) | ||||||
|                 num += 1 |                 num += 1 | ||||||
|          |          | ||||||
| @@ -1722,9 +1747,11 @@ def importgame(): | |||||||
|                 for wi in ref["worldInfo"]: |                 for wi in ref["worldInfo"]: | ||||||
|                     vars.worldinfo.append({ |                     vars.worldinfo.append({ | ||||||
|                         "key": wi["keys"], |                         "key": wi["keys"], | ||||||
|  |                         "keysecondary": wi.get("keysecondary", ""), | ||||||
|                         "content": wi["entry"], |                         "content": wi["entry"], | ||||||
|                         "num": num, |                         "num": num, | ||||||
|                         "init": True |                         "init": True, | ||||||
|  |                         "selective": wi.get("selective", False) | ||||||
|                     }) |                     }) | ||||||
|                     num += 1 |                     num += 1 | ||||||
|          |          | ||||||
| @@ -1766,9 +1793,11 @@ def importAidgRequest(id): | |||||||
|         for wi in js["worldInfos"]: |         for wi in js["worldInfos"]: | ||||||
|             vars.worldinfo.append({ |             vars.worldinfo.append({ | ||||||
|                 "key": wi["keys"], |                 "key": wi["keys"], | ||||||
|  |                 "keysecondary": wi.get("keysecondary", ""), | ||||||
|                 "content": wi["entry"], |                 "content": wi["entry"], | ||||||
|                 "num": num, |                 "num": num, | ||||||
|                 "init": True |                 "init": True, | ||||||
|  |                 "selective": wi.get("selective", False) | ||||||
|             }) |             }) | ||||||
|             num += 1 |             num += 1 | ||||||
|          |          | ||||||
| @@ -1797,9 +1826,11 @@ def wiimportrequest(): | |||||||
|             for wi in js: |             for wi in js: | ||||||
|                 vars.worldinfo.append({ |                 vars.worldinfo.append({ | ||||||
|                     "key": wi["keys"], |                     "key": wi["keys"], | ||||||
|  |                     "keysecondary": wi.get("keysecondary", ""), | ||||||
|                     "content": wi["entry"], |                     "content": wi["entry"], | ||||||
|                     "num": num, |                     "num": num, | ||||||
|                     "init": True |                     "init": True, | ||||||
|  |                     "selective": wi.get("selective", False) | ||||||
|                 }) |                 }) | ||||||
|                 num += 1 |                 num += 1 | ||||||
|          |          | ||||||
|   | |||||||
| @@ -178,6 +178,7 @@ function addImportLine(ob) { | |||||||
|  |  | ||||||
| function addWiLine(ob) { | function addWiLine(ob) { | ||||||
| 	if(ob.init) { | 	if(ob.init) { | ||||||
|  | 		if(ob.selective){ | ||||||
| 			wi_menu.append("<div class=\"wilistitem\">\ | 			wi_menu.append("<div class=\"wilistitem\">\ | ||||||
| 				<div class=\"wiremove\">\ | 				<div class=\"wiremove\">\ | ||||||
| 					<button type=\"button\" class=\"btn btn-primary heightfull\" id=\"btn_wi"+ob.num+"\">X</button>\ | 					<button type=\"button\" class=\"btn btn-primary heightfull\" id=\"btn_wi"+ob.num+"\">X</button>\ | ||||||
| @@ -185,14 +186,43 @@ function addWiLine(ob) { | |||||||
| 					<button type=\"button\" class=\"btn btn-danger heighthalf hidden\" id=\"btn_wican"+ob.num+"\">⮌</button>\ | 					<button type=\"button\" class=\"btn btn-danger heighthalf hidden\" id=\"btn_wican"+ob.num+"\">⮌</button>\ | ||||||
| 				</div>\ | 				</div>\ | ||||||
| 				<div class=\"wikey\">\ | 				<div class=\"wikey\">\ | ||||||
| 				<input class=\"form-control\" type=\"text\" placeholder=\"Key(s)\" id=\"wikey"+ob.num+"\">\ | 					<input class=\"form-control heightfull hidden\" type=\"text\" placeholder=\"Key(s)\" id=\"wikey"+ob.num+"\">\ | ||||||
|  | 					<input class=\"form-control heighthalf\" type=\"text\" placeholder=\"Primary Key(s)\" id=\"wikeyprimary"+ob.num+"\">\ | ||||||
|  | 					<input class=\"form-control heighthalf\" type=\"text\" placeholder=\"Secondary Key(s)\" id=\"wikeysecondary"+ob.num+"\">\ | ||||||
| 				</div>\ | 				</div>\ | ||||||
| 				<div class=\"wientry\">\ | 				<div class=\"wientry\">\ | ||||||
| 					<textarea class=\"form-control\" id=\"wientry"+ob.num+"\" placeholder=\"What To Remember\">"+ob.content+"</textarea>\ | 					<textarea class=\"form-control\" id=\"wientry"+ob.num+"\" placeholder=\"What To Remember\">"+ob.content+"</textarea>\ | ||||||
| 				</div>\ | 				</div>\ | ||||||
|  | 				<div class=\"wiselective\">\ | ||||||
|  | 					<button type=\"button\" class=\"btn btn-success heightfull hidden\" id=\"btn_wiselon"+ob.num+"\">Enable Selective Mode</button>\ | ||||||
|  | 					<button type=\"button\" class=\"btn btn-danger heightfull\" id=\"btn_wiseloff"+ob.num+"\">Disable Selective Mode</button>\ | ||||||
|  | 				</div>\ | ||||||
| 			</div>"); | 			</div>"); | ||||||
|  | 		} else { | ||||||
|  | 			wi_menu.append("<div class=\"wilistitem\">\ | ||||||
|  | 				<div class=\"wiremove\">\ | ||||||
|  | 					<button type=\"button\" class=\"btn btn-primary heightfull\" id=\"btn_wi"+ob.num+"\">X</button>\ | ||||||
|  | 					<button type=\"button\" class=\"btn btn-success heighthalf hidden\" id=\"btn_widel"+ob.num+"\">✓</button>\ | ||||||
|  | 					<button type=\"button\" class=\"btn btn-danger heighthalf hidden\" id=\"btn_wican"+ob.num+"\">⮌</button>\ | ||||||
|  | 				</div>\ | ||||||
|  | 				<div class=\"wikey\">\ | ||||||
|  | 					<input class=\"form-control heightfull\" type=\"text\" placeholder=\"Key(s)\" id=\"wikey"+ob.num+"\">\ | ||||||
|  | 					<input class=\"form-control heighthalf hidden\" type=\"text\" placeholder=\"Primary Key(s)\" id=\"wikeyprimary"+ob.num+"\">\ | ||||||
|  | 					<input class=\"form-control heighthalf hidden\" type=\"text\" placeholder=\"Secondary Key(s)\" id=\"wikeysecondary"+ob.num+"\">\ | ||||||
|  | 				</div>\ | ||||||
|  | 				<div class=\"wientry\">\ | ||||||
|  | 					<textarea class=\"form-control\" id=\"wientry"+ob.num+"\" placeholder=\"What To Remember\">"+ob.content+"</textarea>\ | ||||||
|  | 				</div>\ | ||||||
|  | 				<div class=\"wiselective\">\ | ||||||
|  | 					<button type=\"button\" class=\"btn btn-success heightfull\" id=\"btn_wiselon"+ob.num+"\">Enable Selective Mode</button>\ | ||||||
|  | 					<button type=\"button\" class=\"btn btn-danger heightfull hidden\" id=\"btn_wiseloff"+ob.num+"\">Disable Selective Mode</button>\ | ||||||
|  | 				</div>\ | ||||||
|  | 			</div>"); | ||||||
|  | 		} | ||||||
| 		// Send key value to text input | 		// Send key value to text input | ||||||
| 		$("#wikey"+ob.num).val(ob.key); | 		$("#wikey"+ob.num).val(ob.key); | ||||||
|  | 		$("#wikeyprimary"+ob.num).val(ob.key); | ||||||
|  | 		$("#wikeysecondary"+ob.num).val(ob.keysecondary); | ||||||
| 		// Assign delete event to button | 		// Assign delete event to button | ||||||
| 		$("#btn_wi"+ob.num).on("click", function () { | 		$("#btn_wi"+ob.num).on("click", function () { | ||||||
| 			showWiDeleteConfirm(ob.num); | 			showWiDeleteConfirm(ob.num); | ||||||
| @@ -206,11 +236,17 @@ function addWiLine(ob) { | |||||||
| 				<button type=\"button\" class=\"btn btn-danger heighthalf hidden\" id=\"btn_wican"+ob.num+"\">X</button>\ | 				<button type=\"button\" class=\"btn btn-danger heighthalf hidden\" id=\"btn_wican"+ob.num+"\">X</button>\ | ||||||
| 			</div>\ | 			</div>\ | ||||||
| 			<div class=\"wikey\">\ | 			<div class=\"wikey\">\ | ||||||
| 				<input class=\"form-control hidden\" type=\"text\" placeholder=\"Key(s)\" id=\"wikey"+ob.num+"\">\ | 				<input class=\"form-control heightfull hidden\" type=\"text\" placeholder=\"Key(s)\" id=\"wikey"+ob.num+"\">\ | ||||||
|  | 				<input class=\"form-control heighthalf hidden\" type=\"text\" placeholder=\"Primary Key(s)\" id=\"wikeyprimary"+ob.num+"\">\ | ||||||
|  | 				<input class=\"form-control heighthalf hidden\" type=\"text\" placeholder=\"Secondary Key(s)\" id=\"wikeysecondary"+ob.num+"\">\ | ||||||
| 			</div>\ | 			</div>\ | ||||||
| 			<div class=\"wientry\">\ | 			<div class=\"wientry\">\ | ||||||
| 				<textarea class=\"form-control hidden\" id=\"wientry"+ob.num+"\" placeholder=\"What To Remember\"></textarea>\ | 				<textarea class=\"form-control hidden\" id=\"wientry"+ob.num+"\" placeholder=\"What To Remember\"></textarea>\ | ||||||
| 			</div>\ | 			</div>\ | ||||||
|  | 			<div class=\"wiselective\">\ | ||||||
|  | 				<button type=\"button\" class=\"btn btn-success heightfull hidden\" id=\"btn_wiselon"+ob.num+"\">Enable Selective Mode</button>\ | ||||||
|  | 				<button type=\"button\" class=\"btn btn-danger heightfull hidden\" id=\"btn_wiseloff"+ob.num+"\">Disable Selective Mode</button>\ | ||||||
|  | 			</div>\ | ||||||
| 		</div>"); | 		</div>"); | ||||||
| 		// Assign function to expand WI item to button | 		// Assign function to expand WI item to button | ||||||
| 		$("#btn_wi"+ob.num).on("click", function () { | 		$("#btn_wi"+ob.num).on("click", function () { | ||||||
| @@ -224,10 +260,16 @@ function addWiLine(ob) { | |||||||
| 	$("#btn_widel"+ob.num).on("click", function () { | 	$("#btn_widel"+ob.num).on("click", function () { | ||||||
| 		socket.send({'cmd': 'widelete', 'data': ob.num}); | 		socket.send({'cmd': 'widelete', 'data': ob.num}); | ||||||
| 	}); | 	}); | ||||||
|  | 	$("#btn_wiselon"+ob.num).on("click", function () { | ||||||
|  | 		enableWiSelective(ob.num); | ||||||
|  | 	}); | ||||||
|  | 	$("#btn_wiseloff"+ob.num).on("click", function () { | ||||||
|  | 		disableWiSelective(ob.num); | ||||||
|  | 	}); | ||||||
| } | } | ||||||
|  |  | ||||||
| function expandWiLine(num) { | function expandWiLine(num) { | ||||||
| 	show([$("#wikey"+num), $("#wientry"+num)]); | 	show([$("#wikey"+num), $("#wientry"+num), $("#btn_wiselon"+num)]); | ||||||
| 	$("#btn_wi"+num).html("X"); | 	$("#btn_wi"+num).html("X"); | ||||||
| 	$("#btn_wi"+num).off(); | 	$("#btn_wi"+num).off(); | ||||||
| 	// Tell server the WI entry was initialized | 	// Tell server the WI entry was initialized | ||||||
| @@ -247,6 +289,20 @@ function hideWiDeleteConfirm(num) { | |||||||
| 	hide([$("#btn_widel"+num), $("#btn_wican"+num)]); | 	hide([$("#btn_widel"+num), $("#btn_wican"+num)]); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | function enableWiSelective(num) { | ||||||
|  | 	hide([$("#btn_wiselon"+num), $("#wikey"+num)]); | ||||||
|  | 	// Tell server the WI entry is now selective | ||||||
|  | 	socket.send({'cmd': 'wiselon', 'data': num}); | ||||||
|  | 	show([$("#wikeyprimary"+num), $("#wikeysecondary"+num), $("#btn_wiseloff"+num)]); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function disableWiSelective(num) { | ||||||
|  | 	hide([$("#btn_wiseloff"+num), $("#wikeyprimary"+num), $("#wikeysecondary"+num)]); | ||||||
|  | 	// Tell server the WI entry is now non-selective | ||||||
|  | 	socket.send({'cmd': 'wiseloff', 'data': num}); | ||||||
|  | 	show([$("#btn_wiselon"+num), $("#wikey"+num)]); | ||||||
|  | } | ||||||
|  |  | ||||||
| function highlightImportLine(ref) { | function highlightImportLine(ref) { | ||||||
| 	$("#popupcontent > div").removeClass("popuplistselected"); | 	$("#popupcontent > div").removeClass("popuplistselected"); | ||||||
| 	ref.addClass("popuplistselected"); | 	ref.addClass("popuplistselected"); | ||||||
| @@ -397,8 +453,10 @@ function returnWiList(ar) { | |||||||
| 	var list = []; | 	var list = []; | ||||||
| 	var i; | 	var i; | ||||||
| 	for(i=0; i<ar.length; i++) { | 	for(i=0; i<ar.length; i++) { | ||||||
| 		var ob     = {"key": "", "content": "", "num": ar[i]}; | 		var ob          = {"key": "", "keysecondary": "", "content": "", "num": ar[i], "selective": false}; | ||||||
| 		ob.key     = $("#wikey"+ar[i]).val(); | 		ob.selective    = $("#wikeyprimary"+ar[i]).css("display") != "none" | ||||||
|  | 		ob.key          = ob.selective ? $("#wikeyprimary"+ar[i]).val() : $("#wikey"+ar[i]).val(); | ||||||
|  | 		ob.keysecondary = $("#wikeysecondary"+ar[i]).val() | ||||||
| 		ob.content      = $("#wientry"+ar[i]).val(); | 		ob.content      = $("#wientry"+ar[i]).val(); | ||||||
| 		list.push(ob); | 		list.push(ob); | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -655,12 +655,13 @@ action { | |||||||
| .wilistitem { | .wilistitem { | ||||||
| 	height: 80px; | 	height: 80px; | ||||||
| 	display: grid; | 	display: grid; | ||||||
| 	grid-template-columns: 4% 30% 66%; | 	grid-template-columns: 4% 30% 58% 8%; | ||||||
| 	margin-bottom: 10px; | 	margin-bottom: 10px; | ||||||
| } | } | ||||||
|  |  | ||||||
| .wientry { | .wientry { | ||||||
| 	padding-left: 10px; | 	padding-left: 10px; | ||||||
|  | 	padding-right: 10px; | ||||||
| 	background-color: #212122; | 	background-color: #212122; | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -677,7 +678,6 @@ action { | |||||||
| } | } | ||||||
|  |  | ||||||
| .wikey > input { | .wikey > input { | ||||||
| 	height: 100%; |  | ||||||
| 	background-color: #404040; | 	background-color: #404040; | ||||||
| 	color: #ffffff; | 	color: #ffffff; | ||||||
| } | } | ||||||
| @@ -687,3 +687,7 @@ action { | |||||||
| 	overflow: hidden; | 	overflow: hidden; | ||||||
| 	font-size: 12pt; | 	font-size: 12pt; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | .wiselective > button { | ||||||
|  | 	white-space: normal; | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user