mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-04 13:07:21 +00:00
Fixed the tokenizer path in exported provider configurations (#1076)
This commit is contained in:
1 parent
22065783c2
commit
d333720f3f
12 files changed
+451
-23
No files matched your search
@@ -18,13 +18,22 @@ public static class LuaTools
|
||||
public static string ToLuaStringLiteral(string? value, bool forceLongString = false, int longStringLengthThreshold = 80)
|
||||
{
|
||||
value ??= string.Empty;
|
||||
if (!forceLongString &&
|
||||
value.Length <= longStringLengthThreshold &&
|
||||
!value.Contains('\n') &&
|
||||
!value.Contains('\r'))
|
||||
|
||||
//
|
||||
// Lua reads every kind of line break in a long string as \n. A carriage return therefore
|
||||
// survives only in a quoted string, where it is escaped, even when a long string was asked for:
|
||||
//
|
||||
if (value.Contains('\r') || (!forceLongString &&
|
||||
value.Length <= longStringLengthThreshold &&
|
||||
!value.Contains('\n')))
|
||||
return $"\"{EscapeLuaString(value)}\"";
|
||||
|
||||
return $"{CreateLongStringOpeningDelimiter(value)}{value}{CreateLongStringClosingDelimiter(value)}";
|
||||
//
|
||||
// Lua also drops a line break right after the opening bracket, so a text which starts with
|
||||
// one gets another one in front:
|
||||
//
|
||||
var skippedLineBreak = value.StartsWith('\n') ? "\n" : string.Empty;
|
||||
return $"{CreateLongStringOpeningDelimiter(value)}{skippedLineBreak}{value}{CreateLongStringClosingDelimiter(value)}";
|
||||
}
|
||||
|
||||
private static string CreateLongStringOpeningDelimiter(string value)
|
||||
@@ -41,8 +50,13 @@ public static class LuaTools
|
||||
|
||||
private static string CreateLongStringEquals(string value)
|
||||
{
|
||||
//
|
||||
// The closing bracket must neither occur in the text nor be completed by its end. A text
|
||||
// which ends with "]===" would otherwise form "]===]" with the first character of the
|
||||
// closing bracket, and Lua ends the string right there:
|
||||
//
|
||||
var equalsCount = 3;
|
||||
while (value.Contains($"]{new string('=', equalsCount)}]"))
|
||||
while (value.Contains($"]{new string('=', equalsCount)}]") || value.EndsWith($"]{new string('=', equalsCount)}", StringComparison.Ordinal))
|
||||
equalsCount++;
|
||||
|
||||
return new string('=', equalsCount);
|
||||
|
||||
Reference in new issue
Block a user