Skip to content

Commit

Permalink
resolve comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
AsakusaRinne committed Nov 28, 2023
1 parent b05c315 commit ffc347a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
2 changes: 1 addition & 1 deletion LLama/Native/NativeApi.Load.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ private static IntPtr TryLoadLibrary()

var libraryTryLoadOrder = GetLibraryTryOrder(configuration);

string[] preferredPaths = configuration.SearchDirectories.OrderByDescending(kv => kv.Value).Select(kv => kv.Key).ToArray();
string[] preferredPaths = configuration.SearchDirectories;
string[] possiblePathPrefix = new string[] {
System.AppDomain.CurrentDomain.BaseDirectory,
Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) ?? ""
Expand Down
33 changes: 9 additions & 24 deletions LLama/Native/NativeLibraryConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ public sealed class NativeLibraryConfig
/// <summary>
/// search directory -> priority level, 0 is the lowest.
/// </summary>
private Dictionary<string, int> _searchDirectories = new Dictionary<string, int>()
{
{ "./", 0 }
};
private List<string> _searchDirectories = new List<string>();

private static void ThrowIfLoaded()
{
Expand Down Expand Up @@ -134,20 +131,13 @@ public NativeLibraryConfig WithLogs(bool enable = true)
/// directories must be the same as the default directory. Besides, the directory
/// won't be used recursively.
/// </summary>
/// <param name="directoriesAndPriorities">The directories and corresponding priorities, in which 0 is the lowest. The default path has priority 0.</param>
/// <param name="directories"></param>
/// <returns></returns>
public NativeLibraryConfig WithSearchDirectories(IDictionary<string, int> directoriesAndPriorities)
public NativeLibraryConfig WithSearchDirectories(IEnumerable<string> directories)
{
ThrowIfLoaded();

foreach(var (directory, priority) in directoriesAndPriorities)
{
if(priority < 0)
{
throw new ArgumentException("Priority must be a positive number.");
}
_searchDirectories[directory] = priority;
}
_searchDirectories.AddRange(directories);
return this;
}

Expand All @@ -157,17 +147,12 @@ public NativeLibraryConfig WithSearchDirectories(IDictionary<string, int> direct
/// won't be used recursively.
/// </summary>
/// <param name="directory"></param>
/// <param name="priority">The priority of your added search path. 0 is the lowest. The default path has priority 0.</param>
/// <returns></returns>
public NativeLibraryConfig WithSearchDirectory(string directory, int priority)
public NativeLibraryConfig WithSearchDirectory(string directory)
{
ThrowIfLoaded();

if (priority < 0)
{
throw new ArgumentException("Priority must be a positive number.");
}
_searchDirectories[directory] = priority;
_searchDirectories.Add(directory);
return this;
}

Expand All @@ -184,7 +169,7 @@ internal static Description CheckAndGatherDescription()
Instance._allowFallback,
Instance._skipCheck,
Instance._logging,
Instance._searchDirectories);
Instance._searchDirectories.Concat(new string[] { "./" }).ToArray());
}

internal static string AvxLevelToString(AvxLevel level)
Expand Down Expand Up @@ -241,7 +226,7 @@ public enum AvxLevel
Avx512,
}

internal record Description(string Path, bool UseCuda, AvxLevel AvxLevel, bool AllowFallback, bool SkipCheck, bool Logging, Dictionary<string, int> SearchDirectories)
internal record Description(string Path, bool UseCuda, AvxLevel AvxLevel, bool AllowFallback, bool SkipCheck, bool Logging, string[] SearchDirectories)
{
public override string ToString()
{
Expand All @@ -254,7 +239,7 @@ public override string ToString()
_ => "Unknown"
};

string searchDirectoriesString = string.Join(", ", SearchDirectories.Select(kv => $"[{kv.Key}: {kv.Value}]"));
string searchDirectoriesString = "{ " + string.Join(", ", SearchDirectories) + " }";

return $"NativeLibraryConfig Description:\n" +
$"- Path: {Path}\n" +
Expand Down

0 comments on commit ffc347a

Please sign in to comment.