@@ -104,9 +104,12 @@ public native int generate(
104
104
* @param startPos The starting position in KV cache of the input in the LLM.
105
105
* @return The updated starting position in KV cache of the input in the LLM.
106
106
*/
107
- public long prefillImages (
108
- int [] image , int width , int height , int channels , long startPos ) {
109
- return prefillImagesNative (image , width , height , channels , startPos )[1 ];
107
+ public long prefillImages (int [] image , int width , int height , int channels , long startPos ) {
108
+ long [] nativeResult = prefillImagesNative (image , width , height , channels , startPos );
109
+ if (nativeResult [0 ] != 0 ) {
110
+ throw new RuntimeException ("Prefill failed with error code: " + nativeResult [0 ]);
111
+ }
112
+ return nativeResult [1 ];
110
113
}
111
114
112
115
// returns a tuple of (error code, updated startPos)
@@ -124,13 +127,15 @@ private native long[] prefillImagesNative(
124
127
* @return The updated starting position in KV cache of the input in the LLM.
125
128
*/
126
129
public long prefillPrompt (String prompt , long startPos , int bos , int eos ) {
127
- return prefillPromptNative (prompt , startPos , bos , eos )[2 ];
130
+ long [] nativeResult = prefillPromptNative (prompt , startPos , bos , eos );
131
+ if (nativeResult [0 ] != 0 ) {
132
+ throw new RuntimeException ("Prefill failed with error code: " + nativeResult [0 ]);
133
+ }
134
+ return nativeResult [2 ];
128
135
}
129
136
130
-
131
137
// returns a tuple of (error, token, updated startPos)
132
- private native long [] prefillPromptNative (
133
- String prompt , long startPos , int bos , int eos );
138
+ private native long [] prefillPromptNative (String prompt , long startPos , int bos , int eos );
134
139
135
140
/**
136
141
* Generate tokens from the given prompt, starting from the given position.
0 commit comments