llava.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef LLAVA_H
  2. #define LLAVA_H
  3. #include "ggml.h"
  4. #ifdef LLAMA_SHARED
  5. # if defined(_WIN32) && !defined(__MINGW32__)
  6. # ifdef LLAMA_BUILD
  7. # define LLAVA_API __declspec(dllexport)
  8. # else
  9. # define LLAVA_API __declspec(dllimport)
  10. # endif
  11. # else
  12. # define LLAVA_API __attribute__ ((visibility ("default")))
  13. # endif
  14. #else
  15. # define LLAVA_API
  16. #endif
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. struct clip_ctx;
  21. struct llava_image_embed {
  22. float * embed;
  23. int n_image_pos;
  24. };
  25. /** sanity check for clip <-> llava embed size match */
  26. LLAVA_API bool llava_validate_embed_size(const struct llama_context * ctx_llama, const struct clip_ctx * ctx_clip);
  27. LLAVA_API bool llava_image_embed_make_with_clip_img(struct clip_ctx * ctx_clip, int n_threads, const struct clip_image_u8 * img, float ** image_embd_out, int * n_img_pos_out);
  28. /** build an image embed from image file bytes */
  29. LLAVA_API struct llava_image_embed * llava_image_embed_make_with_bytes(struct clip_ctx * ctx_clip, int n_threads, const unsigned char * image_bytes, int image_bytes_length);
  30. /** build an image embed from a path to an image filename */
  31. LLAVA_API struct llava_image_embed * llava_image_embed_make_with_filename(struct clip_ctx * ctx_clip, int n_threads, const char * image_path);
  32. /** free an embedding made with llava_image_embed_make_* */
  33. LLAVA_API void llava_image_embed_free(struct llava_image_embed * embed);
  34. /** write the image represented by embed into the llama context with batch size n_batch, starting at context pos n_past. on completion, n_past points to the next position in the context after the image embed. */
  35. LLAVA_API bool llava_eval_image_embed(struct llama_context * ctx_llama, const struct llava_image_embed * embed, int n_batch, int * n_past);
  36. #ifdef __cplusplus
  37. }
  38. #endif
  39. #endif