diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java
index 647eccd76a..ad66affc94 100644
--- a/app/src/main/java/eu/faircode/email/FragmentCompose.java
+++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java
@@ -2450,8 +2450,9 @@ public class FragmentCompose extends FragmentBase {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String model = prefs.getString("openai_model", "gpt-3.5-turbo");
+ float temperatur = prefs.getFloat("openai_temperature", 1.0f);
- return OpenAI.completeChat(context, model, result.toArray(new OpenAI.Message[0]), 1);
+ return OpenAI.completeChat(context, model, result.toArray(new OpenAI.Message[0]), temperatur, 1);
}
@Override
diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java
index 88c4b3549d..33932c11e0 100644
--- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java
+++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java
@@ -145,6 +145,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private TextView tvOpenAiPrivacy;
private TextInputLayout tilOpenAi;
private EditText etOpenAiModel;
+ private TextView tvOpenAiTemperature;
+ private SeekBar sbOpenAiTemperature;
private ImageButton ibOpenAi;
private SwitchCompat swUpdates;
private TextView tvGithubPrivacy;
@@ -269,7 +271,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
"deepl_enabled",
"vt_enabled", "vt_apikey",
"send_enabled", "send_host",
- "openai_enabled", "openai_apikey", "openai_model",
+ "openai_enabled", "openai_apikey", "openai_model", "openai_temperature",
"updates", "weekly", "beta", "show_changelog", "announcements",
"crash_reports", "cleanup_attachments",
"watchdog", "experiments", "main_log", "main_log_memory", "protocol", "log_level", "debug", "leak_canary",
@@ -376,6 +378,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
tvOpenAiPrivacy = view.findViewById(R.id.tvOpenAiPrivacy);
tilOpenAi = view.findViewById(R.id.tilOpenAi);
etOpenAiModel = view.findViewById(R.id.etOpenAiModel);
+ tvOpenAiTemperature = view.findViewById(R.id.tvOpenAiTemperature);
+ sbOpenAiTemperature = view.findViewById(R.id.sbOpenAiTemperature);
ibOpenAi = view.findViewById(R.id.ibOpenAi);
swUpdates = view.findViewById(R.id.swUpdates);
tvGithubPrivacy = view.findViewById(R.id.tvGithubPrivacy);
@@ -940,6 +944,23 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
}
});
+ sbOpenAiTemperature.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ prefs.edit().putFloat("openai_temperature", progress / 10f).apply();
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ // Do nothing
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ // Do nothing
+ }
+ });
+
ibOpenAi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -2304,6 +2325,11 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swOpenAi.setChecked(prefs.getBoolean("openai_enabled", false));
tilOpenAi.getEditText().setText(prefs.getString("openai_apikey", null));
etOpenAiModel.setText(prefs.getString("openai_model", null));
+
+ float temperature = prefs.getFloat("openai_temperature", 1f);
+ tvOpenAiTemperature.setText(getString(R.string.title_advanced_openai_temperature, NF.format(temperature)));
+ sbOpenAiTemperature.setProgress(Math.round(temperature * 10));
+
swUpdates.setChecked(prefs.getBoolean("updates", true));
swCheckWeekly.setChecked(prefs.getBoolean("weekly", Helper.hasPlayStore(getContext())));
swCheckWeekly.setEnabled(swUpdates.isChecked());
diff --git a/app/src/main/java/eu/faircode/email/OpenAI.java b/app/src/main/java/eu/faircode/email/OpenAI.java
index 44716738d6..b113444b9f 100644
--- a/app/src/main/java/eu/faircode/email/OpenAI.java
+++ b/app/src/main/java/eu/faircode/email/OpenAI.java
@@ -53,7 +53,7 @@ public class OpenAI {
return (enabled && !TextUtils.isEmpty(apikey));
}
- static Message[] completeChat(Context context, String model, Message[] messages, int n) throws JSONException, IOException {
+ static Message[] completeChat(Context context, String model, Message[] messages, Float temperature, int n) throws JSONException, IOException {
// https://platform.openai.com/docs/guides/chat/introduction
// https://platform.openai.com/docs/api-reference/chat/create
@@ -68,6 +68,8 @@ public class OpenAI {
JSONObject jquestion = new JSONObject();
jquestion.put("model", model);
jquestion.put("messages", jmessages);
+ if (temperature != null)
+ jquestion.put("temperature", temperature);
jquestion.put("n", n);
JSONObject jresponse = call(context, "v1/chat/completions", jquestion);
diff --git a/app/src/main/res/layout/fragment_options_misc.xml b/app/src/main/res/layout/fragment_options_misc.xml
index 420383486c..ecc7409d21 100644
--- a/app/src/main/res/layout/fragment_options_misc.xml
+++ b/app/src/main/res/layout/fragment_options_misc.xml
@@ -633,6 +633,31 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvOpenAiModel" />
+
+
+
+
+ app:constraint_referenced_ids="swOpenAi,tvOpenAiPrivacy,tilOpenAi,ibOpenAi,etOpenAiModel,tvOpenAiTemperature,sbOpenAiTemperature" />
\'Send\' integration
OpenAI (ChatGPT) integration
Model
+ Temperature: %1$s
I want to use an sdcard
Periodically check if FairEmail is still active
Check for GitHub updates