diff --git a/.gitignore b/.gitignore index 5dce46ee..95edaf04 100644 --- a/.gitignore +++ b/.gitignore @@ -13,8 +13,10 @@ miniconda3/* __pycache__ *.log cache/* -userscripts/*.* +userscripts/* +!userscripts/examples !userscripts/kaipreset_*.lua +!userscripts/Readme.* softprompts/* # Ignore PyCharm project files. diff --git a/userscripts/Readme.txt b/userscripts/Readme.txt new file mode 100644 index 00000000..db19f70c --- /dev/null +++ b/userscripts/Readme.txt @@ -0,0 +1,2 @@ +This folder contains userscripts for KoboldAI, any script that begins with kaipreset_ is treated as a official part of KoboldAI and can be overwritten by updates. +If you would like to make modifications to any of the lua scripts it is recommended you that you either rename the script, or create a new copy with a new name. \ No newline at end of file diff --git a/userscripts/examples/Readme.txt b/userscripts/examples/Readme.txt new file mode 100644 index 00000000..5386a28c --- /dev/null +++ b/userscripts/examples/Readme.txt @@ -0,0 +1,2 @@ +This folder contains example code for KoboldAI, to use these scripts move them to the userscripts folder. +Anything in this folder is considered official, make sure to copy it to the userscripts folder first if you do not want changes overwritten or commited as examples. \ No newline at end of file diff --git a/userscripts/kaipreset_haxe_transcend.min.lua b/userscripts/examples/haxe_transcend.min.lua similarity index 100% rename from userscripts/kaipreset_haxe_transcend.min.lua rename to userscripts/examples/haxe_transcend.min.lua diff --git a/userscripts/kaipreset_src/haxe_transcend/KoboldLib.hx b/userscripts/examples/haxe_transcend/KoboldLib.hx similarity index 100% rename from userscripts/kaipreset_src/haxe_transcend/KoboldLib.hx rename to userscripts/examples/haxe_transcend/KoboldLib.hx diff --git a/userscripts/kaipreset_src/haxe_transcend/Main.hx b/userscripts/examples/haxe_transcend/Main.hx similarity index 100% rename from userscripts/kaipreset_src/haxe_transcend/Main.hx rename to userscripts/examples/haxe_transcend/Main.hx diff --git a/userscripts/kaipreset_src/haxe_transcend/README.md b/userscripts/examples/haxe_transcend/README.md similarity index 100% rename from userscripts/kaipreset_src/haxe_transcend/README.md rename to userscripts/examples/haxe_transcend/README.md diff --git a/userscripts/kaipreset_src/haxe_transcend/build.bat b/userscripts/examples/haxe_transcend/build.bat similarity index 97% rename from userscripts/kaipreset_src/haxe_transcend/build.bat rename to userscripts/examples/haxe_transcend/build.bat index a83926a8..aebafcde 100644 --- a/userscripts/kaipreset_src/haxe_transcend/build.bat +++ b/userscripts/examples/haxe_transcend/build.bat @@ -1,16 +1,16 @@ -:: This file is part of KoboldAI. -:: -:: KoboldAI is free software: you can redistribute it and/or modify -:: it under the terms of the GNU Affero General Public License as published by -:: the Free Software Foundation, either version 3 of the License, or -:: (at your option) any later version. -:: -:: This program is distributed in the hope that it will be useful, -:: but WITHOUT ANY WARRANTY; without even the implied warranty of -:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -:: GNU Affero General Public License for more details. -:: -:: You should have received a copy of the GNU Affero General Public License -:: along with this program. If not, see . - -@powershell ./build.ps1 %1 +:: This file is part of KoboldAI. +:: +:: KoboldAI is free software: you can redistribute it and/or modify +:: it under the terms of the GNU Affero General Public License as published by +:: the Free Software Foundation, either version 3 of the License, or +:: (at your option) any later version. +:: +:: This program is distributed in the hope that it will be useful, +:: but WITHOUT ANY WARRANTY; without even the implied warranty of +:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +:: GNU Affero General Public License for more details. +:: +:: You should have received a copy of the GNU Affero General Public License +:: along with this program. If not, see . + +@powershell ./build.ps1 %1 diff --git a/userscripts/kaipreset_src/haxe_transcend/build.ps1 b/userscripts/examples/haxe_transcend/build.ps1 similarity index 99% rename from userscripts/kaipreset_src/haxe_transcend/build.ps1 rename to userscripts/examples/haxe_transcend/build.ps1 index 04eb96c6..0e6bea90 100644 --- a/userscripts/kaipreset_src/haxe_transcend/build.ps1 +++ b/userscripts/examples/haxe_transcend/build.ps1 @@ -1,21 +1,21 @@ -# This file is part of KoboldAI. -# -# KoboldAI is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -$path = "out.lua" -if ($args[0].length -gt 0) { - $path = $args[0] -} -haxe --lua $path -L littleBigInt --main Main -if (-not $?) { exit 1 } -(Get-Content $path).replace('_G.require("rex_pcre")', '({flags = function() return {CASELESS = 1, DOTALL = 1, MULTILINE = 1, UCP = 1, UTF8 = 1} end, gsub = function() return "" end, new = function() return {} end})').replace("return _hx_exports", "return _hx_exports.Main").replace(" _hx_bit_raw = _G.require('bit32')", " _hx_bit_raw = {arshift = function(x, n) local y = x >> n; if (x < 0) then y = y | ~(-1 >> n) end return y end, band = function(x, y) return x & y end, bor = function(x, y) return x | y end, bnot = function(x) return ~x end, bxor = function(x, y) return x ~ y end, lshift = function(x, n) return x << n end, rshift = function(x, n) return x >> n end}").replace('__lua_lib_luautf8_Utf8 = _G.require("lua-utf8")', "__lua_lib_luautf8_Utf8 = {byte = _G.string.byte, find = _G.string.find, gmatch = _G.string.gmatch, gsub = _G.string.gsub, lower = _G.string.lower, match = _G.string.match, reverse = _G.string.reverse, sub = _G.string.sub, upper = _G.string.upper}; for k, v in pairs(_G.utf8) do __lua_lib_luautf8_Utf8[k] = v end;").replace("_G.xpcall(Main.main, _hx_error)", 'local err; if not xpcall(Main.main, function(obj) err = ""; local _print = _G.print; _G.print = function(...) local args = table.pack(...) for i = 1, args.n do args[i] = tostring(args[i]) end err = err .. table.concat(args, "\t") .. "\n" end _hx_error(obj); _G.print = _print end) then _G.error(err) return end;') | Set-Content $path +# This file is part of KoboldAI. +# +# KoboldAI is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +$path = "out.lua" +if ($args[0].length -gt 0) { + $path = $args[0] +} +haxe --lua $path -L littleBigInt --main Main +if (-not $?) { exit 1 } +(Get-Content $path).replace('_G.require("rex_pcre")', '({flags = function() return {CASELESS = 1, DOTALL = 1, MULTILINE = 1, UCP = 1, UTF8 = 1} end, gsub = function() return "" end, new = function() return {} end})').replace("return _hx_exports", "return _hx_exports.Main").replace(" _hx_bit_raw = _G.require('bit32')", " _hx_bit_raw = {arshift = function(x, n) local y = x >> n; if (x < 0) then y = y | ~(-1 >> n) end return y end, band = function(x, y) return x & y end, bor = function(x, y) return x | y end, bnot = function(x) return ~x end, bxor = function(x, y) return x ~ y end, lshift = function(x, n) return x << n end, rshift = function(x, n) return x >> n end}").replace('__lua_lib_luautf8_Utf8 = _G.require("lua-utf8")', "__lua_lib_luautf8_Utf8 = {byte = _G.string.byte, find = _G.string.find, gmatch = _G.string.gmatch, gsub = _G.string.gsub, lower = _G.string.lower, match = _G.string.match, reverse = _G.string.reverse, sub = _G.string.sub, upper = _G.string.upper}; for k, v in pairs(_G.utf8) do __lua_lib_luautf8_Utf8[k] = v end;").replace("_G.xpcall(Main.main, _hx_error)", 'local err; if not xpcall(Main.main, function(obj) err = ""; local _print = _G.print; _G.print = function(...) local args = table.pack(...) for i = 1, args.n do args[i] = tostring(args[i]) end err = err .. table.concat(args, "\t") .. "\n" end _hx_error(obj); _G.print = _print end) then _G.error(err) return end;') | Set-Content $path diff --git a/userscripts/kaipreset_src/haxe_transcend/build.sh b/userscripts/examples/haxe_transcend/build.sh similarity index 100% rename from userscripts/kaipreset_src/haxe_transcend/build.sh rename to userscripts/examples/haxe_transcend/build.sh diff --git a/userscripts/kaipreset_src/haxe_transcend/min.js b/userscripts/examples/haxe_transcend/min.js similarity index 100% rename from userscripts/kaipreset_src/haxe_transcend/min.js rename to userscripts/examples/haxe_transcend/min.js diff --git a/userscripts/examples/various_examples.lua b/userscripts/examples/various_examples.lua new file mode 100644 index 00000000..1d45a81c --- /dev/null +++ b/userscripts/examples/various_examples.lua @@ -0,0 +1,76 @@ +-- Example script +-- Description goes on +--[[subsequent lines including +in multiline comments]] + +kobold = require("bridge")() -- This line is optional and is only for EmmyLua type annotations + +-- You can import libraries that are in extern/lualibs/ +local inspect = require("inspect") +local mt19937ar = require("mt19937ar") + + +---@class KoboldUserScript +local userscript = {} + + +local twister = mt19937ar.new() +local seed = math.random(0, 2147483647) + +local token_num = 0 +local lifetime_token_num = 0 + +-- This gets run when user submits a string to the AI (right after the input +-- formatting is applied but before the string is actually sent to the AI) +function userscript.inmod() + warn("\nINPUT MODIFIER") + token_num = 0 + twister:init_genrand(seed) + print("Submitted text: " .. kobold.submission) -- You can also write to kobold.submission to alter the user's input + print("top-p sampling value: " .. kobold.settings.settopp) +end + +-- This gets run every time the AI generates a token (before the token is +-- actually sampled, so this is where you can make certain tokens more likely +-- to appear than others) +function userscript.genmod() + warn("\nGENERATION MODIFIER") + + print("Tokens generated in the current generation: " .. token_num) + print("Tokens generated since this script started up: " .. lifetime_token_num) + + local r = twister:genrand_real3() + print("Setting top-p sampling value to " .. r) + kobold.settings.settopp = r + + local generated = {} + for sequence_number, tokens in ipairs(kobold.generated) do + generated[sequence_number] = kobold.decode(tokens) + end + print("Current generated strings: " .. inspect(generated)) + + if token_num == math.floor(kobold.settings.genamt/2) then + print("\n\n\n\n\n\nMaking all subsequent tokens more likely to be exclamation marks...") + end + if token_num >= math.floor(kobold.settings.genamt/2) then + for i = 1, kobold.settings.numseqs do + kobold.logits[i][1] = 13.37 + end + end + + token_num = token_num + 1 + lifetime_token_num = lifetime_token_num + 1 +end + +-- This gets run right before the output formatting is applied after generation +-- is finished +function userscript.outmod() + warn("\nOUTPUT MODIFIER") + for chunk in kobold.story:reverse_iter() do + print(chunk.num, chunk.content) + end + print("Wrapping first output in brackets") + kobold.outputs[1] = "[" .. kobold.outputs[1] .. "]" +end + +return userscript