Skip to content

Commit ed80e3b

Browse files
authored
[LlamaDemo] Replace some tokens
Differential Revision: D74687286 Pull Request resolved: #10863
1 parent 62cf849 commit ed80e3b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public void onResult(String result) {
9090
if (result.equals(PromptFormat.getStopToken(mCurrentSettingsFields.getModelType()))) {
9191
return;
9292
}
93+
result = PromptFormat.replaceSpecialToken(mCurrentSettingsFields.getModelType(), result);
9394
if (result.equals("\n\n") || result.equals("\n")) {
9495
if (!mResultMessage.getText().isEmpty()) {
9596
mResultMessage.appendText(result);

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,22 @@ public static String getThinkingModeToken(ModelType modelType, boolean thinkingM
9999
}
100100
}
101101

102+
public static String replaceSpecialToken(ModelType modelType, String token) {
103+
switch (modelType) {
104+
case QWEN_3:
105+
switch (token) {
106+
case "<|im_end|>":
107+
return "";
108+
case "<think>":
109+
return "Thinking...\n";
110+
case "</think>":
111+
return "\nDone thinking";
112+
}
113+
default:
114+
return token;
115+
}
116+
}
117+
102118
public static String getLlavaPresetPrompt() {
103119
return "A chat between a curious human and an artificial intelligence assistant. The assistant"
104120
+ " gives helpful, detailed, and polite answers to the human's questions. USER: ";

0 commit comments

Comments
 (0)