Skip to content

Commit 3b63839

Browse files
cmodi-metafacebook-github-bot
authored andcommitted
Fix duplicating latest prompt (#5546)
Summary: Pull Request resolved: #5546 The last prompt sent would be included in `getConversationHistory()` + adding it prior to sending it with the generate(). It looks like this got move during the rebasing. To fix this we now call `getConversationHistory()` prior to adding the rawPrompt to a Message. In regards to model response, I noticed that it did not really change the quality of the response. (tested with Llama 3.1) Reviewed By: Riandy Differential Revision: D62761977 fbshipit-source-id: 2f975983965fe837147f1ffb8b5dcfa8f2061895
1 parent b361f91 commit 3b63839

File tree

1 file changed

+8
-3
lines changed
  • examples/demo-apps/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo

1 file changed

+8
-3
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,14 @@ private void onModelRunStopped() {
661661
mSendButton.setOnClickListener(
662662
view -> {
663663
addSelectedImagesToChatThread(mSelectedImageUri);
664+
String finalPrompt;
664665
String rawPrompt = mEditTextMessage.getText().toString();
666+
if (ModelUtils.getModelCategory(mCurrentSettingsFields.getModelType())
667+
== ModelUtils.VISION_MODEL) {
668+
finalPrompt = mCurrentSettingsFields.getFormattedSystemAndUserPrompt(rawPrompt);
669+
} else {
670+
finalPrompt = getTotalFormattedPrompt(getConversationHistory(), rawPrompt);
671+
}
665672
// We store raw prompt into message adapter, because we don't want to show the extra
666673
// tokens from system prompt
667674
mMessageAdapter.add(new Message(rawPrompt, true, MessageType.TEXT, promptID));
@@ -692,14 +699,12 @@ public void run() {
692699
if (ModelUtils.getModelCategory(mCurrentSettingsFields.getModelType())
693700
== ModelUtils.VISION_MODEL) {
694701
mModule.generateFromPos(
695-
mCurrentSettingsFields.getFormattedSystemAndUserPrompt(rawPrompt),
702+
finalPrompt,
696703
ModelUtils.VISION_MODEL_SEQ_LEN,
697704
startPos,
698705
MainActivity.this,
699706
false);
700707
} else {
701-
String finalPrompt =
702-
getTotalFormattedPrompt(getConversationHistory(), rawPrompt);
703708
ETLogging.getInstance().log("Running inference.. prompt=" + finalPrompt);
704709
mModule.generate(
705710
finalPrompt,

0 commit comments

Comments
 (0)