You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

NativeApi.LLava.cs 2.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace LLama.Native;
  4. using clip_ctx = IntPtr;
  5. public static unsafe partial class NativeApi
  6. {
  7. /// <summary>
  8. /// Sanity check for clip &lt;-&gt; llava embed size match
  9. /// </summary>
  10. /// <returns></returns>
  11. [DllImport(llavaLibraryName, EntryPoint = "llava_validate_embed_size", CallingConvention = CallingConvention.Cdecl)]
  12. public static extern bool llava_validate_embed_size( SafeLLamaContextHandle ctxLlama, SafeLlavaModelHandle ctxClip);
  13. /// <summary>
  14. /// Build an image embed from image file bytes
  15. /// </summary>
  16. /// <param name="ctx_clip"></param>
  17. /// <param name="n_threads"></param>
  18. /// <param name="image_bytes"></param>
  19. /// <param name="image_bytes_length"></param>
  20. /// <returns></returns>
  21. [DllImport(llavaLibraryName, EntryPoint = "llava_image_embed_make_with_bytes",
  22. CallingConvention = CallingConvention.Cdecl)]
  23. public static extern
  24. SafeLlavaImageEmbedHandle llava_image_embed_make_with_bytes(SafeLlavaModelHandle ctx_clip, int n_threads,
  25. byte[] image_bytes, int image_bytes_length);
  26. /// <summary>
  27. /// Build an image embed from a path to an image filename
  28. /// </summary>
  29. /// <param name="ctx_clip"></param>
  30. /// <param name="n_threads"></param>
  31. /// <param name="image_path"></param>
  32. /// <returns></returns>
  33. [DllImport(llavaLibraryName, EntryPoint = "llava_image_embed_make_with_filename", CallingConvention = CallingConvention.Cdecl)]
  34. public static extern
  35. SafeLlavaImageEmbedHandle llava_image_embed_make_with_filename(SafeLlavaModelHandle ctx_clip, int n_threads,
  36. [MarshalAs(UnmanagedType.LPStr)] string image_path);
  37. /// <summary>
  38. /// Free an embedding made with llava_image_embed_make_*
  39. /// </summary>
  40. /// <param name="embed"></param>
  41. /// <returns></returns>
  42. [DllImport(llavaLibraryName, EntryPoint = "llava_image_embed_free", CallingConvention = CallingConvention.Cdecl)]
  43. public static extern SafeLlavaImageEmbedHandle llava_image_embed_free(IntPtr embed);
  44. /// <summary>
  45. /// Write the image represented by embed into the llama context with batch size n_batch, starting at context
  46. /// pos n_past. on completion, n_past points to the next position in the context after the image embed.
  47. /// </summary>
  48. /// <param name="embed">ctx_llama</param>
  49. /// <returns></returns>
  50. [DllImport(llavaLibraryName, EntryPoint = "llava_eval_image_embed", CallingConvention = CallingConvention.Cdecl)]
  51. public static extern bool llava_eval_image_embed(SafeLLamaContextHandle ctc_llama, SafeLlavaImageEmbedHandle embed,
  52. int n_batch, ref int n_past);
  53. }