Skip to content

Commit 939ca17

Browse files
committed
Update LLAVA_API code in llava_cpp.py
1 parent c5a8284 commit 939ca17

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

llama_cpp/llava_cpp.py

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
clip_ctx_p = NewType("clip_ctx_p", int)
5656
clip_ctx_p_ctypes = c_void_p
5757

58+
# struct clip_image_u8;
59+
clip_image_u8_p = NewType("clip_image_u8_p", int)
60+
clip_image_u8_p_ctypes = c_void_p
61+
5862

5963
# struct llava_image_embed {
6064
# float * embed;
@@ -79,19 +83,35 @@ def llava_validate_embed_size(
7983
) -> bool:
8084
...
8185

86+
# 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);
87+
@ctypes_function(
88+
"llava_image_embed_make_with_clip_img",
89+
[clip_ctx_p_ctypes, c_int, clip_image_u8_p_ctypes, POINTER(POINTER(c_float)), POINTER(c_int)],
90+
c_bool
91+
)
92+
def llava_image_embed_make_with_clip_img(
93+
ctx_clip: clip_ctx_p,
94+
n_threads: int,
95+
img: clip_image_u8_p,
96+
image_embd_out: _Pointer[_Pointer[c_float]],
97+
n_img_pos_out: _Pointer[c_int],
98+
/,
99+
) -> bool:
100+
...
101+
82102

83103
# /** build an image embed from image file bytes */
84104
# 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);
85105
@ctypes_function(
86106
"llava_image_embed_make_with_bytes",
87-
[clip_ctx_p_ctypes, c_int, POINTER(c_uint8), c_int],
107+
[clip_ctx_p_ctypes, c_int, c_char_p, c_int],
88108
POINTER(llava_image_embed),
89109
)
90110
def llava_image_embed_make_with_bytes(
91111
ctx_clip: clip_ctx_p,
92-
n_threads: Union[c_int, int],
93-
image_bytes: CtypesArray[c_uint8],
94-
image_bytes_length: Union[c_int, int],
112+
n_threads: c_int,
113+
image_bytes: c_char_p,
114+
image_bytes_length: c_int,
95115
/,
96116
) -> "_Pointer[llava_image_embed]":
97117
...
@@ -105,7 +125,7 @@ def llava_image_embed_make_with_bytes(
105125
POINTER(llava_image_embed),
106126
)
107127
def llava_image_embed_make_with_filename(
108-
ctx_clip: clip_ctx_p, n_threads: Union[c_int, int], image_path: bytes, /
128+
ctx_clip: clip_ctx_p, n_threads: c_int, image_path: c_char_p, /
109129
) -> "_Pointer[llava_image_embed]":
110130
...
111131

@@ -143,18 +163,14 @@ def llava_eval_image_embed(
143163
# clip.h
144164
################################################
145165

146-
# struct clip_image_f32;
147-
clip_image_f32_p = NewType("clip_image_f32_p", int)
148-
clip_image_f32_p_ctypes = c_void_p
149-
150-
# struct clip_image_u8;
151-
clip_image_u8_p = NewType("clip_image_u8_p", int)
152-
clip_image_u8_p_ctypes = c_void_p
153-
154166
# struct clip_image_u8_batch;
155167
clip_image_u8_batch_p = NewType("clip_image_u8_batch_p", int)
156168
clip_image_u8_batch_p_ctypes = c_void_p
157169

170+
# struct clip_image_f32;
171+
clip_image_f32_p = NewType("clip_image_f32_p", int)
172+
clip_image_f32_p_ctypes = c_void_p
173+
158174
# struct clip_image_f32_batch;
159175
clip_image_f32_batch_p = NewType("clip_image_f32_batch_p", int)
160176
clip_image_f32_batch_p_ctypes = c_void_p
@@ -449,7 +465,7 @@ def clip_image_encode(
449465
ctx: clip_ctx_p,
450466
n_threads: int,
451467
img: clip_image_f32_p,
452-
vec: POINTER(c_float), /
468+
vec: _Pointer[c_float], /
453469
) -> bool:
454470
...
455471

@@ -459,7 +475,7 @@ def clip_image_batch_encode(
459475
ctx: clip_ctx_p,
460476
n_threads: int,
461477
imgs: clip_image_f32_batch_p,
462-
vec: POINTER(c_float), /
478+
vec: _Pointer[c_float], /
463479
) -> bool:
464480
...
465481

@@ -502,9 +518,9 @@ def clip_is_gemma3(ctx: clip_ctx_p) -> bool:
502518
def clip_n_output_tokens(
503519
ctx: clip_ctx_p,
504520
n_threads: int,
505-
img: POINTER(float),
521+
img: _Pointer[float],
506522
h: int,
507523
w: int,
508-
vec: POINTER(float),/
524+
vec: _Pointer[float],/
509525
) -> bool:
510526
...

0 commit comments

Comments
 (0)