mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-02-17 12:10:49 +01:00
Add more sample scripts
This commit is contained in:
parent
e71c2d72cd
commit
7cae07a53f
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
*.min.lua linguist-vendored
|
@ -1,7 +1,20 @@
|
|||||||
-- Basic phrase bias
|
-- Basic phrase bias
|
||||||
-- Makes certain sequences of tokens more or less likely to appear than normal.
|
-- Makes certain sequences of tokens more or less likely to appear than normal.
|
||||||
-- Run this script once, then see the .conf file in the same directory as this
|
|
||||||
-- script for more information.
|
-- 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
kobold = require("bridge")() -- This line is optional and is only for EmmyLua type annotations
|
kobold = require("bridge")() -- This line is optional and is only for EmmyLua type annotations
|
||||||
local userscript = {} ---@class KoboldUserScript
|
local userscript = {} ---@class KoboldUserScript
|
||||||
|
20
userscripts/kaipreset_haxe_transcend.min.lua
vendored
Normal file
20
userscripts/kaipreset_haxe_transcend.min.lua
vendored
Normal file
File diff suppressed because one or more lines are too long
25
userscripts/kaipreset_src/haxe_transcend/KoboldLib.hx
Normal file
25
userscripts/kaipreset_src/haxe_transcend/KoboldLib.hx
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* 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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import lua.Table;
|
||||||
|
|
||||||
|
extern class KoboldLib {
|
||||||
|
@:luaDotMethod public function get_config_file(?clear:Bool):lua.FileHandle;
|
||||||
|
@:luaDotMethod public function halt_generation():Void;
|
||||||
|
@:luaDotMethod public function restart_generation(?sequence:Int):Void;
|
||||||
|
public var outputs:Null<Table<Int, String>>;
|
||||||
|
}
|
91
userscripts/kaipreset_src/haxe_transcend/Main.hx
Normal file
91
userscripts/kaipreset_src/haxe_transcend/Main.hx
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* 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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import haxe.exceptions.PosException;
|
||||||
|
import lua.Lua;
|
||||||
|
|
||||||
|
@:expose class Main {
|
||||||
|
public static final kobold:KoboldLib = untyped __lua__("_G.kobold");
|
||||||
|
public static final exampleConfig = "return true";
|
||||||
|
|
||||||
|
public static var shouldRun:Bool;
|
||||||
|
|
||||||
|
public static var f:BigInt = -2;
|
||||||
|
public static var e:BigInt = 4;
|
||||||
|
public static var s:BigInt = 8;
|
||||||
|
public static var t:BigInt = 1;
|
||||||
|
public static var i:BigInt = 0;
|
||||||
|
public static var v:BigInt = 1;
|
||||||
|
public static var a:BigInt = 6;
|
||||||
|
public static var l:BigInt = 1;
|
||||||
|
|
||||||
|
public static function inmod() {
|
||||||
|
if (!shouldRun) return;
|
||||||
|
kobold.halt_generation();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function outmod() {
|
||||||
|
if (!shouldRun) return;
|
||||||
|
|
||||||
|
// Gibbons, Jeremy. (2004). Unbounded Spigot Algorithms for the Digits
|
||||||
|
// of Pi. American Mathematical Monthly. 113. 10.2307/27641917.
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
var x = i/v;
|
||||||
|
if (x == (i + t)/v) {
|
||||||
|
trace(x);
|
||||||
|
kobold.outputs[1] = Std.string(x);
|
||||||
|
t *= 10;
|
||||||
|
i -= x*v;
|
||||||
|
i *= 10;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
v *= s*a;
|
||||||
|
i *= s;
|
||||||
|
s += 8;
|
||||||
|
i += e * t;
|
||||||
|
e += 4;
|
||||||
|
i *= a;
|
||||||
|
a += 4;
|
||||||
|
t *= f*l;
|
||||||
|
l += 2;
|
||||||
|
f -= 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kobold.restart_generation(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function main() {
|
||||||
|
var f = kobold.get_config_file();
|
||||||
|
f.seek("set");
|
||||||
|
if (f.read(1) == null) f.write(exampleConfig);
|
||||||
|
f.seek("set");
|
||||||
|
|
||||||
|
var a = f.read("a");
|
||||||
|
f.close();
|
||||||
|
var result = Lua.load(a);
|
||||||
|
trace(result);
|
||||||
|
if (result.message != null) throw new PosException(result.message);
|
||||||
|
shouldRun = switch result.func() {
|
||||||
|
case false: false;
|
||||||
|
case null: false;
|
||||||
|
default: true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
24
userscripts/kaipreset_src/haxe_transcend/README.md
Normal file
24
userscripts/kaipreset_src/haxe_transcend/README.md
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Installing dependencies:
|
||||||
|
|
||||||
|
* Install [Haxe](https://haxe.org/) 4 and Haxelib. Add them to your PATH. The specific version of Haxe used for this compilation was 4.2.4.
|
||||||
|
|
||||||
|
* Install the Haxelib package [littleBigInt](https://github.com/maitag/littleBigInt), version 0.1.3:
|
||||||
|
```
|
||||||
|
haxelib install littleBigInt 0.1.3
|
||||||
|
```
|
||||||
|
|
||||||
|
* Install [Node.js](https://nodejs.org/).
|
||||||
|
|
||||||
|
* Install https://github.com/FATH-Mechatronics/luamin/tree/d7359250cf28ab617ba5e43d1fda6ec411b1f9f7 using npm:
|
||||||
|
```
|
||||||
|
npm install FATH-Mechatronics/luamin#d7359250cf28ab617ba5e43d1fda6ec411b1f9f7
|
||||||
|
```
|
||||||
|
|
||||||
|
# Compilation:
|
||||||
|
|
||||||
|
* Run build.sh if you're running Linux or build.bat if you're running Windows.
|
||||||
|
|
||||||
|
* Use Node.js to run min.js:
|
||||||
|
```
|
||||||
|
node min.js
|
||||||
|
```
|
16
userscripts/kaipreset_src/haxe_transcend/build.bat
Normal file
16
userscripts/kaipreset_src/haxe_transcend/build.bat
Normal file
@ -0,0 +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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
@powershell ./build.ps1 %1
|
21
userscripts/kaipreset_src/haxe_transcend/build.ps1
Normal file
21
userscripts/kaipreset_src/haxe_transcend/build.ps1
Normal file
@ -0,0 +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 <https://www.gnu.org/licenses/>.
|
||||||
|
$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
|
27
userscripts/kaipreset_src/haxe_transcend/build.sh
Normal file
27
userscripts/kaipreset_src/haxe_transcend/build.sh
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# 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 <https://www.gnu.org/licenses/>.
|
||||||
|
set -e
|
||||||
|
path=$1
|
||||||
|
if [ $# -eq 0 ]
|
||||||
|
then
|
||||||
|
path="out.lua"
|
||||||
|
fi
|
||||||
|
haxe --lua $path -L littleBigInt --main Main
|
||||||
|
perl -pe 's/\Q_G.require("rex_pcre")/\E({flags = function() return {CASELESS = 1, DOTALL = 1, MULTILINE = 1, UCP = 1, UTF8 = 1} end, gsub = function() return "" end, new = function() return {} end})/' -i $path
|
||||||
|
perl -pe 's/\Qreturn _hx_exports/\Ereturn _hx_exports.Main/' -i $path
|
||||||
|
perl -pe "s/\Q _hx_bit_raw = _G.require('bit32')/\E _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}/" -i $path
|
||||||
|
perl -pe 's/\Q__lua_lib_luautf8_Utf8 = _G.require("lua-utf8")/\E__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;/' -i $path
|
||||||
|
perl -pe 's/\Q_G.xpcall(Main.main, _hx_error)/\Elocal 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;/' -i $path
|
28
userscripts/kaipreset_src/haxe_transcend/min.js
Normal file
28
userscripts/kaipreset_src/haxe_transcend/min.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
const fs = require("fs");
|
||||||
|
const luamin = require("luamin");
|
||||||
|
|
||||||
|
const in_path = "out.lua";
|
||||||
|
const out_path = "out.min.lua";
|
||||||
|
|
||||||
|
var data = fs.readFileSync(in_path, "utf8");
|
||||||
|
data = luamin.minify(data);
|
||||||
|
data = "-- Haxe trancendental test\n\
|
||||||
|
-- This is a script written in Haxe that prints the natural logarithm of the\n\
|
||||||
|
-- golden ratio in base 10 to arbitrarily many digits.\n\
|
||||||
|
\n\
|
||||||
|
-- This file is part of KoboldAI.\n\
|
||||||
|
--\n\
|
||||||
|
-- KoboldAI is free software: you can redistribute it and/or modify\n\
|
||||||
|
-- it under the terms of the GNU Affero General Public License as published by\n\
|
||||||
|
-- the Free Software Foundation, either version 3 of the License, or\n\
|
||||||
|
-- (at your option) any later version.\n\
|
||||||
|
--\n\
|
||||||
|
-- This program is distributed in the hope that it will be useful,\n\
|
||||||
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
|
||||||
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
|
||||||
|
-- GNU Affero General Public License for more details.\n\
|
||||||
|
--\n\
|
||||||
|
-- You should have received a copy of the GNU Affero General Public License\n\
|
||||||
|
-- along with this program. If not, see <https://www.gnu.org/licenses/>.\n\
|
||||||
|
\n" + data + "\n";
|
||||||
|
fs.writeFileSync(out_path, data);
|
65
userscripts/kaipreset_substitution.lua
Normal file
65
userscripts/kaipreset_substitution.lua
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
-- Word substitution
|
||||||
|
-- Performs a search-and-replace on the AI's output.
|
||||||
|
|
||||||
|
-- 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
kobold = require("bridge")() -- This line is optional and is only for EmmyLua type annotations
|
||||||
|
local userscript = {} ---@class KoboldUserScript
|
||||||
|
|
||||||
|
|
||||||
|
local example_config = [[;-- Substitution
|
||||||
|
;--
|
||||||
|
;-- This example config causes all occurrences of "Hello," (without the double
|
||||||
|
;-- quotes) to be replaced with "Goodbye," (without the double quotes) and
|
||||||
|
;-- all occurrences of "test" to be replaced with "****".
|
||||||
|
;--
|
||||||
|
;-- The strings are parsed as Lua strings, so the standard escape sequences \",
|
||||||
|
;-- \n, \\, and so on apply here as well.
|
||||||
|
;--
|
||||||
|
return {
|
||||||
|
{"Hello,", "Goodbye,"},
|
||||||
|
{"test", "****"},
|
||||||
|
}
|
||||||
|
]]
|
||||||
|
|
||||||
|
-- If config file is empty, write example config
|
||||||
|
local f = kobold.get_config_file()
|
||||||
|
f:seek("set")
|
||||||
|
if f:read(1) == nil then
|
||||||
|
f:write(example_config)
|
||||||
|
end
|
||||||
|
f:seek("set")
|
||||||
|
example_config = nil
|
||||||
|
|
||||||
|
-- Read config
|
||||||
|
local cfg, err = load(f:read("a"))
|
||||||
|
f:close()
|
||||||
|
if err ~= nil then
|
||||||
|
error(err)
|
||||||
|
end
|
||||||
|
cfg = cfg()
|
||||||
|
|
||||||
|
|
||||||
|
function userscript.outmod()
|
||||||
|
for i, output in ipairs(kobold.outputs) do
|
||||||
|
for j, row in ipairs(cfg) do
|
||||||
|
output = output:gsub(row[1], row[2])
|
||||||
|
end
|
||||||
|
kobold.outputs[i] = output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return userscript
|
108
userscripts/kaipreset_you_bias.lua
Normal file
108
userscripts/kaipreset_you_bias.lua
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
-- You bias
|
||||||
|
-- Makes the word "You" more or less common, optionally only if not between
|
||||||
|
-- double quotes.
|
||||||
|
-- Only works with models with a tokenizer based on GPT-2, such as GPT-2,
|
||||||
|
-- GPT-Neo and GPT-J.
|
||||||
|
|
||||||
|
-- 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
kobold = require("bridge")() -- This line is optional and is only for EmmyLua type annotations
|
||||||
|
local userscript = {} ---@class KoboldUserScript
|
||||||
|
|
||||||
|
|
||||||
|
local example_config = [[;-- You bias
|
||||||
|
;--
|
||||||
|
return {
|
||||||
|
bias = -7.0, -- Negative numbers make it less likely, positive numbers more, and -math.huge impossible
|
||||||
|
only_if_outside_double_quotes = true,
|
||||||
|
}
|
||||||
|
]]
|
||||||
|
|
||||||
|
-- If config file is empty, write example config
|
||||||
|
local f = kobold.get_config_file()
|
||||||
|
f:seek("set")
|
||||||
|
if f:read(1) == nil then
|
||||||
|
f:write(example_config)
|
||||||
|
end
|
||||||
|
f:seek("set")
|
||||||
|
example_config = nil
|
||||||
|
|
||||||
|
-- Read config
|
||||||
|
local cfg, err = load(f:read("a"))
|
||||||
|
f:close()
|
||||||
|
if err ~= nil then
|
||||||
|
error(err)
|
||||||
|
end
|
||||||
|
cfg = cfg()
|
||||||
|
if type(cfg.bias) ~= "number" then
|
||||||
|
error("`bias` must be a number")
|
||||||
|
elseif cfg.bias ~= cfg.bias or cfg.bias == math.huge then
|
||||||
|
error("`bias` can't be `nan` or `math.huge`")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
---@type table<integer, integer>
|
||||||
|
local you_tokens <const> = {345, 921, 1639, 5832, 7013, 36981}
|
||||||
|
|
||||||
|
local genmod_run = false
|
||||||
|
|
||||||
|
function userscript.genmod()
|
||||||
|
genmod_run = true
|
||||||
|
local context
|
||||||
|
if cfg.only_if_outside_double_quotes then
|
||||||
|
context = " " .. kobold.worldinfo:compute_context(kobold.submission, {})
|
||||||
|
end
|
||||||
|
|
||||||
|
for i, generated_row in ipairs(kobold.generated) do
|
||||||
|
local should_bias = true
|
||||||
|
|
||||||
|
if cfg.only_if_outside_double_quotes then
|
||||||
|
local str = context .. kobold.decode(generated_row)
|
||||||
|
local last_open_quote = 0
|
||||||
|
local last_close_quote = 0
|
||||||
|
local i = 0
|
||||||
|
local j = 0
|
||||||
|
while true do
|
||||||
|
i, j = str:find('"', j+1)
|
||||||
|
if i == nil then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
if str:sub(i-1, i-1) == " " or str:sub(i-1, i-1) == "\n" then
|
||||||
|
last_open_quote = j
|
||||||
|
else
|
||||||
|
last_close_quote = j
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if last_open_quote > last_close_quote then
|
||||||
|
should_bias = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if should_bias then
|
||||||
|
for k, v in ipairs(you_tokens) do
|
||||||
|
kobold.logits[i][v+1] = kobold.logits[i][v+1] + cfg.bias
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function userscript.outmod()
|
||||||
|
if not genmod_run then
|
||||||
|
warn("WARNING: Generation modifier was not executed, so this script has had no effect")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return userscript
|
Loading…
x
Reference in New Issue
Block a user