|
|
|
@@ -3,10 +3,13 @@ using LLama.Exceptions; |
|
|
|
|
|
|
|
namespace LLama.Native |
|
|
|
{ |
|
|
|
/// <summary> |
|
|
|
/// A reference to a set of llama model weights |
|
|
|
/// </summary> |
|
|
|
public class SafeLlamaModelHandle |
|
|
|
: SafeLLamaHandleBase |
|
|
|
{ |
|
|
|
public SafeLlamaModelHandle(IntPtr handle) |
|
|
|
internal SafeLlamaModelHandle(IntPtr handle) |
|
|
|
: base(handle) |
|
|
|
{ |
|
|
|
} |
|
|
|
@@ -19,10 +22,17 @@ namespace LLama.Native |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// Load a model from the given file path into memory |
|
|
|
/// </summary> |
|
|
|
/// <param name="modelPath"></param> |
|
|
|
/// <param name="lparams"></param> |
|
|
|
/// <returns></returns> |
|
|
|
/// <exception cref="RuntimeError"></exception> |
|
|
|
public static SafeLlamaModelHandle LoadFromFile(string modelPath, LLamaContextParams lparams) |
|
|
|
{ |
|
|
|
var model_ptr = NativeApi.llama_load_model_from_file(modelPath, lparams); |
|
|
|
if (model_ptr == null) |
|
|
|
if (model_ptr == IntPtr.Zero) |
|
|
|
throw new RuntimeError($"Failed to load model {modelPath}."); |
|
|
|
|
|
|
|
return new SafeLlamaModelHandle(model_ptr); |
|
|
|
|