Skip to content

Commit 3112478

Browse files
committed
replace tokens
1 parent b1883a0 commit 3112478

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

examples/demo-apps/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/MainActivity.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ public void onResult(String result) {
9090
if (result.equals(PromptFormat.getStopToken(mCurrentSettingsFields.getModelType()))) {
9191
return;
9292
}
93-
if (PromptFormat.shouldSkipToken(mCurrentSettingsFields.getModelType(), result)) {
94-
return;
95-
}
93+
result = PromptFormat.replaceSpecialToken(mCurrentSettingsFields.getModelType(), result);
9694
if (result.equals("\n\n") || result.equals("\n")) {
9795
if (!mResultMessage.getText().isEmpty()) {
9896
mResultMessage.appendText(result);

examples/demo-apps/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/PromptFormat.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,19 @@ public static String getThinkingModeToken(ModelType modelType, boolean thinkingM
9999
}
100100
}
101101

102-
public static boolean shouldSkipToken(ModelType modelType, String token) {
102+
public static String replaceSpecialToken(ModelType modelType, String token) {
103103
switch (modelType) {
104104
case QWEN_3:
105-
return token.equals("<|im_end|>");
105+
switch (token) {
106+
case "<|im_end|>":
107+
return "";
108+
case "<think>":
109+
return "Thinking...\n";
110+
case "</think>":
111+
return "\nDone thinking";
112+
}
106113
default:
107-
return false;
114+
return token;
108115
}
109116
}
110117

0 commit comments

Comments
 (0)