You can not select more than 25 topics
Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- namespace LLama.Examples;
-
- internal static class UserSettings
- {
- private static readonly string SettingsFilePath = Path.Join(AppContext.BaseDirectory, "DefaultModel.env");
-
- private static string? ReadDefaultModelPath()
- {
- if (!File.Exists(SettingsFilePath))
- return null;
-
- string path = File.ReadAllText(SettingsFilePath).Trim();
- if (!File.Exists(path))
- return null;
-
- return path;
- }
-
- private static void WriteDefaultModelPath(string path)
- {
- File.WriteAllText(SettingsFilePath, path);
- }
-
- public static string GetModelPath(bool alwaysPrompt = false)
- {
- string? defaultPath = ReadDefaultModelPath();
- return defaultPath is null || alwaysPrompt
- ? PromptUserForPath()
- : PromptUserForPathWithDefault(defaultPath);
- }
-
- private static string PromptUserForPath()
- {
- while (true)
- {
- Console.ForegroundColor = ConsoleColor.White;
- Console.Write("Please input your model path: ");
- string? path = Console.ReadLine();
-
- if (File.Exists(path))
- {
- WriteDefaultModelPath(path);
- return path;
- }
-
- Console.WriteLine("ERROR: invalid model file path\n");
- }
- }
-
- private static string PromptUserForPathWithDefault(string defaultPath)
- {
- while (true)
- {
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine($"Default model: {defaultPath}");
- Console.Write($"Please input a model path (or ENTER for default): ");
- string? path = Console.ReadLine();
-
- if (string.IsNullOrWhiteSpace(path))
- {
- return defaultPath;
- }
-
- if (File.Exists(path))
- {
- WriteDefaultModelPath(path);
- return path;
- }
-
- Console.WriteLine("ERROR: invalid model file path\n");
- }
- }
- }
|