Skip to content

Commit 63f27b8

Browse files
fix: comment, throw when no image tag
1 parent ad1e46a commit 63f27b8

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

packages/react-native-executorch/src/controllers/LLMController.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,17 @@ export class LLMController {
186186
this.isGeneratingCallback(false);
187187
}
188188

189+
private getImageToken(): string {
190+
const token = this.tokenizerConfig.image_token;
191+
if (!token) {
192+
throw new RnExecutorchError(
193+
RnExecutorchErrorCode.InvalidConfig,
194+
"Tokenizer config is missing 'image_token'. Vision models require tokenizerConfigSource with an 'image_token' field."
195+
);
196+
}
197+
return token;
198+
}
199+
189200
private filterSpecialTokens(text: string): string {
190201
let filtered = text;
191202
if (
@@ -240,7 +251,7 @@ export class LLMController {
240251
? await this.nativeModule.generateMultimodal(
241252
input,
242253
imagePaths,
243-
this.tokenizerConfig?.image_token ?? '<image>',
254+
this.getImageToken(),
244255
this.onToken
245256
)
246257
: await this.nativeModule.generate(input, this.onToken);

packages/react-native-executorch/src/types/llm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export interface LLMTypeMultimodal<
157157
}
158158

159159
/**
160-
* Return type for `useLLM` when `model.isMultimodal` is absent or `false`.
160+
* Return type for `useLLM` when `model.capabilities` is absent or does not include `'vision'`.
161161
* `sendMessage` accepts only text.
162162
*
163163
* @category Types

0 commit comments

Comments
 (0)