mirror of https://github.com/M66B/FairEmail.git
Added option to configure answer prompt
This commit is contained in:
parent
ef425fd0b1
commit
74a93a1f73
|
@ -53,16 +53,17 @@ public class AI {
|
|||
HtmlHelper.removeSignatures(d);
|
||||
HtmlHelper.truncate(d, MAX_SUMMARIZE_TEXT_SIZE);
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
|
||||
if (body == null || TextUtils.isEmpty(body.toString().trim()))
|
||||
if (OpenAI.isAvailable(context))
|
||||
body = OpenAI.DEFAULT_ANSWER_PROMPT;
|
||||
body = prefs.getString("openai_answer", OpenAI.DEFAULT_ANSWER_PROMPT);
|
||||
else if (Gemini.isAvailable(context))
|
||||
body = Gemini.DEFAULT_ANSWER_PROMPT;
|
||||
body = prefs.getString("gemini_answer", Gemini.DEFAULT_ANSWER_PROMPT);
|
||||
else
|
||||
body = "?";
|
||||
|
||||
if (OpenAI.isAvailable(context)) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String model = prefs.getString("openai_model", OpenAI.DEFAULT_MODEL);
|
||||
float temperature = prefs.getFloat("openai_temperature", OpenAI.DEFAULT_TEMPERATURE);
|
||||
boolean multimodal = prefs.getBoolean("openai_multimodal", false);
|
||||
|
@ -95,7 +96,6 @@ public class AI {
|
|||
}
|
||||
return sb.toString();
|
||||
} else if (Gemini.isAvailable(context)) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String model = prefs.getString("gemini_model", Gemini.DEFAULT_MODEL);
|
||||
float temperature = prefs.getFloat("gemini_temperature", Gemini.DEFAULT_TEMPERATURE);
|
||||
|
||||
|
|
|
@ -84,6 +84,7 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
|
|||
private TextView tvOpenAiTemperature;
|
||||
private SeekBar sbOpenAiTemperature;
|
||||
private EditText etOpenAiSummarize;
|
||||
private EditText etOpenAiAnswer;
|
||||
private ImageButton ibOpenAi;
|
||||
private SwitchCompat swGemini;
|
||||
private TextView tvGeminiPrivacy;
|
||||
|
@ -93,6 +94,7 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
|
|||
private TextView tvGeminiTemperature;
|
||||
private SeekBar sbGeminiTemperature;
|
||||
private EditText etGeminiSummarize;
|
||||
private EditText etGeminiAnswer;
|
||||
private ImageButton ibGemini;
|
||||
|
||||
private CardView cardVirusTotal;
|
||||
|
@ -107,8 +109,8 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
|
|||
"deepl_enabled",
|
||||
"vt_enabled",
|
||||
"send_enabled", "send_host", "send_dlimit", "send_tlimit",
|
||||
"openai_enabled", "openai_uri", "openai_model", "openai_multimodal", "openai_temperature", "openai_summarize",
|
||||
"gemini_enabled", "gemini_uri", "gemini_model", "gemini_temperature", "gemini_summarize"
|
||||
"openai_enabled", "openai_uri", "openai_model", "openai_multimodal", "openai_temperature", "openai_summarize", "openai_answer",
|
||||
"gemini_enabled", "gemini_uri", "gemini_model", "gemini_temperature", "gemini_summarize", "gemini_answer"
|
||||
));
|
||||
|
||||
@Override
|
||||
|
@ -157,6 +159,7 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
|
|||
tvOpenAiTemperature = view.findViewById(R.id.tvOpenAiTemperature);
|
||||
sbOpenAiTemperature = view.findViewById(R.id.sbOpenAiTemperature);
|
||||
etOpenAiSummarize = view.findViewById(R.id.etOpenAiSummarize);
|
||||
etOpenAiAnswer = view.findViewById(R.id.etOpenAiAnswer);
|
||||
ibOpenAi = view.findViewById(R.id.ibOpenAi);
|
||||
|
||||
swGemini = view.findViewById(R.id.swGemini);
|
||||
|
@ -167,6 +170,7 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
|
|||
tvGeminiTemperature = view.findViewById(R.id.tvGeminiTemperature);
|
||||
sbGeminiTemperature = view.findViewById(R.id.sbGeminiTemperature);
|
||||
etGeminiSummarize = view.findViewById(R.id.etGeminiSummarize);
|
||||
etGeminiAnswer = view.findViewById(R.id.etGeminiAnswer);
|
||||
ibGemini = view.findViewById(R.id.ibGemini);
|
||||
|
||||
cardVirusTotal = view.findViewById(R.id.cardVirusTotal);
|
||||
|
@ -424,6 +428,7 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
|
|||
swOpenMultiModal.setEnabled(checked);
|
||||
sbOpenAiTemperature.setEnabled(checked);
|
||||
etOpenAiSummarize.setEnabled(checked);
|
||||
etOpenAiAnswer.setEnabled(checked);
|
||||
if (checked)
|
||||
swGemini.setChecked(false);
|
||||
}
|
||||
|
@ -549,6 +554,28 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
|
|||
}
|
||||
});
|
||||
|
||||
etOpenAiAnswer.setHint(OpenAI.DEFAULT_ANSWER_PROMPT);
|
||||
etOpenAiAnswer.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
String prompt = s.toString().trim();
|
||||
if (TextUtils.isEmpty(prompt))
|
||||
prefs.edit().remove("openai_answer").apply();
|
||||
else
|
||||
prefs.edit().putString("openai_answer", prompt).apply();
|
||||
}
|
||||
});
|
||||
|
||||
ibOpenAi.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -563,6 +590,7 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
|
|||
etGeminiModel.setEnabled(checked);
|
||||
sbGeminiTemperature.setEnabled(checked);
|
||||
etGeminiSummarize.setEnabled(checked);
|
||||
etGeminiAnswer.setEnabled(checked);
|
||||
if (checked)
|
||||
swOpenAi.setChecked(false);
|
||||
}
|
||||
|
@ -681,6 +709,28 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
|
|||
}
|
||||
});
|
||||
|
||||
etGeminiAnswer.setHint(Gemini.DEFAULT_ANSWER_PROMPT);
|
||||
etGeminiAnswer.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
String prompt = s.toString().trim();
|
||||
if (TextUtils.isEmpty(prompt))
|
||||
prefs.edit().remove("gemini_answer").apply();
|
||||
else
|
||||
prefs.edit().putString("gemini_answer", prompt).apply();
|
||||
}
|
||||
});
|
||||
|
||||
ibGemini.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -719,10 +769,12 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
|
|||
"openai_apikey".equals(key) ||
|
||||
"openai_model".equals(key) ||
|
||||
"openai_summarize".equals(key) ||
|
||||
"openai_answer".equals(key) ||
|
||||
"gemini_uri".equals(key) ||
|
||||
"gemini_apikey".equals(key) ||
|
||||
"gemini_model".equals(key) ||
|
||||
"gemini_summarize".equals(key))
|
||||
"gemini_summarize".equals(key) ||
|
||||
"gemini_answer".equals(key))
|
||||
return;
|
||||
|
||||
getMainHandler().removeCallbacks(update);
|
||||
|
@ -796,6 +848,8 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
|
|||
sbOpenAiTemperature.setEnabled(swOpenAi.isChecked());
|
||||
etOpenAiSummarize.setText(prefs.getString("openai_summarize", null));
|
||||
etOpenAiSummarize.setEnabled(swOpenAi.isChecked());
|
||||
etOpenAiAnswer.setText(prefs.getString("openai_answer", null));
|
||||
etOpenAiAnswer.setEnabled(swOpenAi.isChecked());
|
||||
|
||||
swGemini.setChecked(prefs.getBoolean("gemini_enabled", false));
|
||||
etGemini.setText(prefs.getString("gemini_uri", null));
|
||||
|
@ -810,6 +864,8 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
|
|||
|
||||
etGeminiSummarize.setText(prefs.getString("gemini_summarize", null));
|
||||
etGeminiSummarize.setEnabled(swGemini.isChecked());
|
||||
etGeminiAnswer.setText(prefs.getString("gemini_answer", null));
|
||||
etGeminiAnswer.setEnabled(swGemini.isChecked());
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
|
|
|
@ -715,6 +715,28 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvOpenAiSummarize" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvOpenAiAnswer"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_advanced_answer_prompt"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/etOpenAiSummarize" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etOpenAiAnswer"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:inputType="textCapSentences"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvOpenAiAnswer" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/ibOpenAi"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -724,7 +746,7 @@
|
|||
android:contentDescription="@string/title_info"
|
||||
android:tooltipText="@string/title_info"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/etOpenAiSummarize"
|
||||
app:layout_constraintTop_toBottomOf="@id/etOpenAiAnswer"
|
||||
app:srcCompat="@drawable/twotone_info_24" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
@ -899,6 +921,28 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvGeminiSummarize" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvGeminiAnswer"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_advanced_answer_prompt"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/etGeminiSummarize" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etGeminiAnswer"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:inputType="textCapSentences"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvGeminiAnswer" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/ibGemini"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -908,7 +952,7 @@
|
|||
android:contentDescription="@string/title_info"
|
||||
android:tooltipText="@string/title_info"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/etGeminiSummarize"
|
||||
app:layout_constraintTop_toBottomOf="@id/etGeminiAnswer"
|
||||
app:srcCompat="@drawable/twotone_info_24" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
|
|
@ -891,6 +891,7 @@
|
|||
<string name="title_advanced_gemini">Gemini integration</string>
|
||||
<string name="title_advanced_multi_modal">Multimodal</string>
|
||||
<string name="title_advanced_summarize_prompt">Summarize prompt</string>
|
||||
<string name="title_advanced_answer_prompt">Answer prompt</string>
|
||||
<string name="title_advanced_sdcard">I want to use an SD card</string>
|
||||
<string name="title_advanced_watchdog">Periodically check if FairEmail is still active</string>
|
||||
<string name="title_advanced_updates">Check for GitHub updates</string>
|
||||
|
|
Loading…
Reference in New Issue