mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-01 09:16:00 +00:00
OpenAI: added system instructions option
This commit is contained in:
parent
1c7277d4e8
commit
a51315ca69
4 changed files with 60 additions and 2 deletions
|
@ -87,9 +87,14 @@ public class AI {
|
|||
float temperature = prefs.getFloat("openai_temperature", OpenAI.DEFAULT_TEMPERATURE);
|
||||
boolean multimodal = prefs.getBoolean("openai_multimodal", false);
|
||||
String answer = prefs.getString("openai_answer", OpenAI.DEFAULT_ANSWER_PROMPT);
|
||||
String system = prefs.getString("openai_system", null);
|
||||
|
||||
List<OpenAI.Message> messages = new ArrayList<>();
|
||||
|
||||
if (!TextUtils.isEmpty(system))
|
||||
messages.add(new OpenAI.Message(OpenAI.SYSTEM, new OpenAI.Content[]{
|
||||
new OpenAI.Content(OpenAI.CONTENT_TEXT, system)}));
|
||||
|
||||
if (reply == null) {
|
||||
if (body instanceof Spannable && multimodal)
|
||||
messages.add(new OpenAI.Message(OpenAI.USER,
|
||||
|
|
|
@ -85,6 +85,7 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
|
|||
private SeekBar sbOpenAiTemperature;
|
||||
private EditText etOpenAiSummarize;
|
||||
private EditText etOpenAiAnswer;
|
||||
private EditText etOpenAiSystem;
|
||||
private ImageButton ibOpenAi;
|
||||
private SwitchCompat swGemini;
|
||||
private TextView tvGeminiPrivacy;
|
||||
|
@ -109,7 +110,7 @@ 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", "openai_answer",
|
||||
"openai_enabled", "openai_uri", "openai_model", "openai_multimodal", "openai_temperature", "openai_summarize", "openai_answer", "openai_system",
|
||||
"gemini_enabled", "gemini_uri", "gemini_model", "gemini_temperature", "gemini_summarize", "gemini_answer"
|
||||
));
|
||||
|
||||
|
@ -160,6 +161,7 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
|
|||
sbOpenAiTemperature = view.findViewById(R.id.sbOpenAiTemperature);
|
||||
etOpenAiSummarize = view.findViewById(R.id.etOpenAiSummarize);
|
||||
etOpenAiAnswer = view.findViewById(R.id.etOpenAiAnswer);
|
||||
etOpenAiSystem = view.findViewById(R.id.etOpenAiSystem);
|
||||
ibOpenAi = view.findViewById(R.id.ibOpenAi);
|
||||
|
||||
swGemini = view.findViewById(R.id.swGemini);
|
||||
|
@ -429,6 +431,7 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
|
|||
sbOpenAiTemperature.setEnabled(checked);
|
||||
etOpenAiSummarize.setEnabled(checked);
|
||||
etOpenAiAnswer.setEnabled(checked);
|
||||
etOpenAiSystem.setEnabled(checked);
|
||||
if (checked)
|
||||
swGemini.setChecked(false);
|
||||
}
|
||||
|
@ -576,6 +579,27 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
|
|||
}
|
||||
});
|
||||
|
||||
etOpenAiSystem.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_system").apply();
|
||||
else
|
||||
prefs.edit().putString("openai_system", prompt).apply();
|
||||
}
|
||||
});
|
||||
|
||||
ibOpenAi.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -770,6 +794,7 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
|
|||
"openai_model".equals(key) ||
|
||||
"openai_summarize".equals(key) ||
|
||||
"openai_answer".equals(key) ||
|
||||
"openai_system".equals(key) ||
|
||||
"gemini_uri".equals(key) ||
|
||||
"gemini_apikey".equals(key) ||
|
||||
"gemini_model".equals(key) ||
|
||||
|
@ -850,6 +875,8 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
|
|||
etOpenAiSummarize.setEnabled(swOpenAi.isChecked());
|
||||
etOpenAiAnswer.setText(prefs.getString("openai_answer", null));
|
||||
etOpenAiAnswer.setEnabled(swOpenAi.isChecked());
|
||||
etOpenAiSystem.setText(prefs.getString("openai_system", null));
|
||||
etOpenAiSystem.setEnabled(swOpenAi.isChecked());
|
||||
|
||||
swGemini.setChecked(prefs.getBoolean("gemini_enabled", false));
|
||||
etGemini.setText(prefs.getString("gemini_uri", null));
|
||||
|
|
|
@ -743,6 +743,31 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvOpenAiAnswer" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvOpenAiSystem"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_advanced_system_instructions"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/etOpenAiAnswer" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etOpenAiSystem"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:gravity="top"
|
||||
android:inputType="textCapSentences|textMultiLine"
|
||||
android:lines="5"
|
||||
android:scrollbars="vertical"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvOpenAiSystem" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/ibOpenAi"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -752,7 +777,7 @@
|
|||
android:contentDescription="@string/title_info"
|
||||
android:tooltipText="@string/title_info"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/etOpenAiAnswer"
|
||||
app:layout_constraintTop_toBottomOf="@id/etOpenAiSystem"
|
||||
app:srcCompat="@drawable/twotone_info_24" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
|
|
@ -892,6 +892,7 @@
|
|||
<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_system_instructions">System instructions</string>
|
||||
<string name="title_advanced_default_prompt">Default prompt</string>
|
||||
<string name="title_advanced_entered_text">Entered text</string>
|
||||
<string name="title_advanced_sdcard">I want to use an SD card</string>
|
||||
|
|
Loading…
Reference in a new issue