Skip to content

Commit ffc347a

Browse files
committed
resolve comments.
1 parent b05c315 commit ffc347a

File tree

2 files changed

+10
-25
lines changed

2 files changed

+10
-25
lines changed

LLama/Native/NativeApi.Load.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ private static IntPtr TryLoadLibrary()
275275

276276
var libraryTryLoadOrder = GetLibraryTryOrder(configuration);
277277

278-
string[] preferredPaths = configuration.SearchDirectories.OrderByDescending(kv => kv.Value).Select(kv => kv.Key).ToArray();
278+
string[] preferredPaths = configuration.SearchDirectories;
279279
string[] possiblePathPrefix = new string[] {
280280
System.AppDomain.CurrentDomain.BaseDirectory,
281281
Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) ?? ""

LLama/Native/NativeLibraryConfig.cs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ public sealed class NativeLibraryConfig
3232
/// <summary>
3333
/// search directory -> priority level, 0 is the lowest.
3434
/// </summary>
35-
private Dictionary<string, int> _searchDirectories = new Dictionary<string, int>()
36-
{
37-
{ "./", 0 }
38-
};
35+
private List<string> _searchDirectories = new List<string>();
3936

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

143-
foreach(var (directory, priority) in directoriesAndPriorities)
144-
{
145-
if(priority < 0)
146-
{
147-
throw new ArgumentException("Priority must be a positive number.");
148-
}
149-
_searchDirectories[directory] = priority;
150-
}
140+
_searchDirectories.AddRange(directories);
151141
return this;
152142
}
153143

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

166-
if (priority < 0)
167-
{
168-
throw new ArgumentException("Priority must be a positive number.");
169-
}
170-
_searchDirectories[directory] = priority;
155+
_searchDirectories.Add(directory);
171156
return this;
172157
}
173158

@@ -184,7 +169,7 @@ internal static Description CheckAndGatherDescription()
184169
Instance._allowFallback,
185170
Instance._skipCheck,
186171
Instance._logging,
187-
Instance._searchDirectories);
172+
Instance._searchDirectories.Concat(new string[] { "./" }).ToArray());
188173
}
189174

190175
internal static string AvxLevelToString(AvxLevel level)
@@ -241,7 +226,7 @@ public enum AvxLevel
241226
Avx512,
242227
}
243228

244-
internal record Description(string Path, bool UseCuda, AvxLevel AvxLevel, bool AllowFallback, bool SkipCheck, bool Logging, Dictionary<string, int> SearchDirectories)
229+
internal record Description(string Path, bool UseCuda, AvxLevel AvxLevel, bool AllowFallback, bool SkipCheck, bool Logging, string[] SearchDirectories)
245230
{
246231
public override string ToString()
247232
{
@@ -254,7 +239,7 @@ public override string ToString()
254239
_ => "Unknown"
255240
};
256241

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

259244
return $"NativeLibraryConfig Description:\n" +
260245
$"- Path: {Path}\n" +

0 commit comments

Comments
 (0)