using System;
using System.Threading;
using System.Threading.Tasks;
using LLama.Native;
namespace LLama;
///
/// A set of llava model weights (mmproj), loaded into memory.
///
public sealed class LLavaWeights : IDisposable
{
///
/// The native handle, which is used in the native APIs
///
/// Be careful how you use this!
public SafeLlavaModelHandle NativeHandle { get; }
private LLavaWeights(SafeLlavaModelHandle weights)
{
NativeHandle = weights;
}
///
/// Load weights into memory
///
/// path to the "mmproj" model file
///
public static LLavaWeights LoadFromFile(string mmProject)
{
var weights = SafeLlavaModelHandle.LoadFromFile(mmProject, 1);
return new LLavaWeights(weights);
}
///
/// Load weights into memory
///
/// path to the "mmproj" model file
///
///
public static Task LoadFromFileAsync(string mmProject, CancellationToken token = default)
{
return Task.Run(() => LoadFromFile(mmProject), token);
}
///
/// Create the Image Embeddings from the bytes of an image.
///
///
/// Image bytes. Supported formats:
///
/// - JPG
/// - PNG
/// - BMP
/// - TGA
///
///
///
public SafeLlavaImageEmbedHandle CreateImageEmbeddings(LLamaContext ctxLlama, byte[] image )
{
return NativeHandle.CreateImageEmbeddings(ctxLlama, image );
}
///
/// Create the Image Embeddings from the bytes of an image.
///
///
/// Path to the image file. Supported formats:
///
/// - JPG
/// - PNG
/// - BMP
/// - TGA
///
///
///
///
public SafeLlavaImageEmbedHandle CreateImageEmbeddings(LLamaContext ctxLlama, string image )
{
return NativeHandle.CreateImageEmbeddings(ctxLlama, image );
}
///
/// Eval the image embeddings
///
///
///
///
///
public bool EvalImageEmbed(LLamaContext ctxLlama, SafeLlavaImageEmbedHandle imageEmbed, ref int n_past)
{
return NativeHandle.EvalImageEmbed( ctxLlama, imageEmbed, ref n_past );
}
///
public void Dispose()
{
NativeHandle.Dispose();
}
}