diff --git a/LLama/Native/NativeApi.cs b/LLama/Native/NativeApi.cs
index a0782b39..e9666ea8 100644
--- a/LLama/Native/NativeApi.cs
+++ b/LLama/Native/NativeApi.cs
@@ -11,8 +11,16 @@ namespace LLama.Native
{
using llama_token = Int32;
+ ///
+ /// Callback from llama.cpp with log messages
+ ///
+ ///
+ ///
public delegate void LLamaLogCallback(ILLamaLogger.LogLevel level, string message);
+ ///
+ /// Direct translation of the llama.cpp API
+ ///
public unsafe partial class NativeApi
{
static NativeApi()
@@ -41,18 +49,43 @@ namespace LLama.Native
[DllImport(libraryName, EntryPoint = "llama_mmap_supported", CallingConvention = CallingConvention.Cdecl)]
public static extern bool llama_empty_call();
+ ///
+ /// Create a LLamaContextParams with default values
+ ///
+ ///
[DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern LLamaContextParams llama_context_default_params();
+ ///
+ /// Create a LLamaModelQuantizeParams with default values
+ ///
+ ///
[DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern LLamaModelQuantizeParams llama_model_quantize_default_params();
+ ///
+ /// Check if memory mapping is supported
+ ///
+ ///
[DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern bool llama_mmap_supported();
+ ///
+ /// Check if memory lockingis supported
+ ///
+ ///
[DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern bool llama_mlock_supported();
+ ///
+ /// Export a static computation graph for context of 511 and batch size of 1
+ /// NOTE: since this functionality is mostly for debugging and demonstration purposes, we hardcode these
+ /// parameters here to keep things simple
+ /// IMPORTANT: do not use for anything else other than debugging and testing!
+ ///
+ ///
+ ///
+ ///
[DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern int llama_eval_export(SafeLLamaContextHandle ctx, string fname);
@@ -67,6 +100,13 @@ namespace LLama.Native
[DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr llama_load_model_from_file(string path_model, LLamaContextParams @params);
+ ///
+ /// Create a new llama_context with the given model.
+ /// Return value should always be wrapped in SafeLLamaContextHandle!
+ ///
+ ///
+ ///
+ ///
[DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr llama_new_context_with_model(SafeLlamaModelHandle model, LLamaContextParams @params);
@@ -79,7 +119,7 @@ namespace LLama.Native
public static extern void llama_backend_init(bool numa);
///
- /// Frees all allocated memory
+ /// Frees all allocated memory in the given llama_context
///
///
[DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)]
diff --git a/LLama/Native/SamplingApi.cs b/LLama/Native/SamplingApi.cs
index 56771579..e26bf971 100644
--- a/LLama/Native/SamplingApi.cs
+++ b/LLama/Native/SamplingApi.cs
@@ -1,8 +1,14 @@
using System;
+#pragma warning disable IDE1006 // Naming Styles
+
namespace LLama.Native
{
using llama_token = Int32;
+
+ ///
+ /// Direct translation of the llama.cpp sampling API
+ ///
public unsafe class SamplingApi
{
///
@@ -140,6 +146,13 @@ namespace LLama.Native
NativeApi.llama_sample_typical(ctx, ref st, p, min_keep);
}
+ ///
+ /// Sample with temperature.
+ /// As temperature increases, the prediction becomes diverse but also vulnerable to hallucinations -- generating tokens that are sensible but not factual
+ ///
+ ///
+ ///
+ ///
public static void llama_sample_temperature(SafeLLamaContextHandle ctx, LLamaTokenDataArray candidates, float temp)
{
using var handle = LLamaTokenDataArrayNative.Create(candidates, out var st);