Skip to content

Commit 8d444bd

Browse files
committed
prompt a bit cleaner, remove redundant function
1 parent 4ccb580 commit 8d444bd

3 files changed

Lines changed: 9 additions & 16 deletions

File tree

XUnity.AutoTranslator.LlmTranslators/Behavior/BaseEndpointBehavior.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static string GetRequestData(LlmConfig config, string raw)
1717
var messages = new JSONArray();
1818
var systemMessage = new JSONObject();
1919
systemMessage["role"] = "system";
20-
systemMessage["content"] = systemPrompt.ToString();
20+
systemMessage["content"] = Regex.Replace(systemPrompt.ToString().Replace("\r","\n"), @"\n+", "\n");
2121
messages.Add(systemMessage);
2222

2323
var userMessage = new JSONObject();

XUnity.AutoTranslator.LlmTranslators/Config/Configuration.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System.Text;
2-
using System.Text.RegularExpressions;
3-
using System.Net;
42
using YamlDotNet.Serialization;
53
using YamlDotNet.Serialization.NamingConventions;
64

@@ -29,26 +27,23 @@ public static LlmConfig GetConfiguration(string file)
2927

3028
foreach (var folder in foldersToCheck)
3129
{
32-
string filepath = Path.Combine(folder, file);
33-
if (!File.Exists(filepath)) continue;
30+
string path = Path.Combine(folder, file);
31+
if (!File.Exists(path)) continue;
3432
var yamlDeserializer = new DeserializerBuilder()
3533
.WithNamingConvention(CamelCaseNamingConvention.Instance)
3634
.Build();
3735

38-
var config = yamlDeserializer.Deserialize<LlmConfig>(File.ReadAllText(filepath, Encoding.UTF8));
36+
var config = yamlDeserializer.Deserialize<LlmConfig>(File.ReadAllText(path, Encoding.UTF8));
3937

4038
// Check endpoint url
4139
ConfigFunctions.FindCompatibleUrl(config);
4240

4341
// When model is not set (Usually for local)
4442
if (string.IsNullOrWhiteSpace(config.Model))
45-
ConfigFunctions.DetectModel(config);
43+
ConfigFunctions.DetectModel(config);
4644

47-
if (config.Url == null)
48-
throw new Exception("No URLs configured for the endpoint.");
49-
5045
return config;
51-
}
46+
}
5247
throw new FileNotFoundException($"Could not find '{file}' in AutoTranslator or BepInEx config folder.");
5348
}
5449
}

XUnity.AutoTranslator.LlmTranslators/Config/configFunctions.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ public static string RegexModel(string body)
1212
}
1313
public static void DetectModel(LlmConfig config)
1414
{
15-
if (!string.IsNullOrWhiteSpace(config.Model))
16-
return; // already set
17-
1815
var trimmedBase = BaseEndpointBehavior.GetDomain(config.Url);
1916
var Combine = new Func<string, string>(path => BaseEndpointBehavior.CombineUrl(trimmedBase, path));
2017

@@ -42,7 +39,8 @@ public static void DetectModel(LlmConfig config)
4239
}
4340
catch { }
4441
}
45-
throw new Exception("Could not auto-detect model name from the provided URL. Please set the model first");
42+
config.Model = "default";
43+
Console.WriteLine("Could not auto-detect model name from the provided URL. Ignore this if endpoint doesn't require it (ie: koboldcpp, textgenwebui)");
4644
}
4745
public static void FindCompatibleUrl(LlmConfig config)
4846
{
@@ -145,7 +143,7 @@ public static void FindCompatibleUrl(LlmConfig config)
145143
}
146144
if (!found)
147145
throw new InvalidOperationException(
148-
$"Failed to connect {baseUrl}. Endpoint may not exist, or require a valid API key."
146+
$"Failed to connect {baseUrl}. Endpoint may not exist, or require a Model to set, or valid API key."
149147
);
150148
}
151149
}

0 commit comments

Comments
 (0)