Skip to content

Commit 8ee4487

Browse files
authored
[LlamaDemo] Add a button to toggle thinking mode (#10667)
1 parent 3997ae9 commit 8ee4487

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import androidx.constraintlayout.widget.ConstraintLayout;
4343
import androidx.core.app.ActivityCompat;
4444
import androidx.core.content.ContextCompat;
45+
import androidx.core.content.res.ResourcesCompat;
4546
import com.google.gson.Gson;
4647
import com.google.gson.reflect.TypeToken;
4748
import java.lang.reflect.Type;
@@ -56,6 +57,7 @@
5657

5758
public class MainActivity extends AppCompatActivity implements Runnable, LlmCallback {
5859
private EditText mEditTextMessage;
60+
private ImageButton mThinkModeButton;
5961
private ImageButton mSendButton;
6062
private ImageButton mGalleryButton;
6163
private ImageButton mCameraButton;
@@ -77,6 +79,7 @@ public class MainActivity extends AppCompatActivity implements Runnable, LlmCall
7779
private SettingsFields mCurrentSettingsFields;
7880
private Handler mMemoryUpdateHandler;
7981
private Runnable memoryUpdater;
82+
private boolean mThinkMode = false;
8083
private int promptID = 0;
8184
private long startPos = 0;
8285
private static final int CONVERSATION_HISTORY_MESSAGE_LOOKBACK = 2;
@@ -252,6 +255,7 @@ protected void onCreate(Bundle savedInstanceState) {
252255
finish();
253256
}
254257

258+
mThinkModeButton = requireViewById(R.id.thinkModeButton);
255259
mEditTextMessage = requireViewById(R.id.editTextMessage);
256260
mSendButton = requireViewById(R.id.sendButton);
257261
mSendButton.setEnabled(false);
@@ -271,6 +275,28 @@ protected void onCreate(Bundle savedInstanceState) {
271275
MainActivity.this.startActivity(myIntent);
272276
});
273277

278+
mThinkModeButton.setOnClickListener(
279+
view -> {
280+
if (mThinkMode) {
281+
mThinkMode = false;
282+
mThinkModeButton.setImageDrawable(
283+
ResourcesCompat.getDrawable(
284+
getResources(), R.drawable.baseline_lightbulb_24, null));
285+
} else {
286+
mThinkMode = true;
287+
mThinkModeButton.setImageDrawable(
288+
ResourcesCompat.getDrawable(getResources(), R.drawable.blue_lightbulb_24, null));
289+
}
290+
runOnUiThread(
291+
() -> {
292+
String thinkingModeText = mThinkMode ? "on" : "off";
293+
mMessageAdapter.add(
294+
new Message(
295+
"Thinking mode is " + thinkingModeText, false, MessageType.SYSTEM, 0));
296+
mMessageAdapter.notifyDataSetChanged();
297+
});
298+
});
299+
274300
mCurrentSettingsFields = new SettingsFields();
275301
mMemoryUpdateHandler = new Handler(Looper.getMainLooper());
276302
onModelRunStopped();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
2+
3+
<path android:fillColor="@android:color/white" android:pathData="M9,21c0,0.5 0.4,1 1,1h4c0.6,0 1,-0.5 1,-1v-1L9,20v1zM12,2C8.1,2 5,5.1 5,9c0,2.4 1.2,4.5 3,5.7L8,17c0,0.5 0.4,1 1,1h6c0.6,0 1,-0.5 1,-1v-2.3c1.8,-1.3 3,-3.4 3,-5.7 0,-3.9 -3.1,-7 -7,-7z"/>
4+
5+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#6684EC" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
2+
3+
<path android:fillColor="@android:color/white" android:pathData="M9,21c0,0.5 0.4,1 1,1h4c0.6,0 1,-0.5 1,-1v-1L9,20v1zM12,2C8.1,2 5,5.1 5,9c0,2.4 1.2,4.5 3,5.7L8,17c0,0.5 0.4,1 1,1h6c0.6,0 1,-0.5 1,-1v-2.3c1.8,-1.3 3,-3.4 3,-5.7 0,-3.9 -3.1,-7 -7,-7z"/>
4+
5+
</vector>

examples/demo-apps/android/LlamaDemo/app/src/main/res/layout/activity_main.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@
174174
android:padding="10dp"
175175
android:src="@drawable/baseline_add_24" />
176176

177+
<ImageButton
178+
android:id="@+id/thinkModeButton"
179+
android:layout_width="wrap_content"
180+
android:layout_height="wrap_content"
181+
android:background="@android:color/transparent"
182+
android:padding="10dp"
183+
android:src="@drawable/baseline_lightbulb_24" />
184+
177185
<EditText
178186
android:id="@+id/editTextMessage"
179187
android:layout_width="match_parent"

0 commit comments

Comments
 (0)