mirror of https://github.com/M66B/FairEmail.git
OpenAI: option to turn on moderation
This commit is contained in:
parent
bc2eda5038
commit
239330e7ad
|
@ -164,6 +164,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
private EditText etOpenAiModel;
|
||||
private TextView tvOpenAiTemperature;
|
||||
private SeekBar sbOpenAiTemperature;
|
||||
private SwitchCompat swOpenAiModeration;
|
||||
private ImageButton ibOpenAi;
|
||||
|
||||
private CardView cardAdvanced;
|
||||
|
@ -272,7 +273,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_temperature",
|
||||
"openai_enabled", "openai_apikey", "openai_model", "openai_temperature", "openai_moderation",
|
||||
"updates", "weekly", "beta", "show_changelog", "announcements",
|
||||
"crash_reports", "cleanup_attachments",
|
||||
"watchdog", "experiments", "main_log", "main_log_memory", "protocol", "log_level", "debug", "leak_canary",
|
||||
|
@ -398,6 +399,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
etOpenAiModel = view.findViewById(R.id.etOpenAiModel);
|
||||
tvOpenAiTemperature = view.findViewById(R.id.tvOpenAiTemperature);
|
||||
sbOpenAiTemperature = view.findViewById(R.id.sbOpenAiTemperature);
|
||||
swOpenAiModeration = view.findViewById(R.id.swOpenAiModeration);
|
||||
ibOpenAi = view.findViewById(R.id.ibOpenAi);
|
||||
|
||||
cardAdvanced = view.findViewById(R.id.cardAdvanced);
|
||||
|
@ -1081,6 +1083,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
}
|
||||
});
|
||||
|
||||
swOpenAiModeration.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
prefs.edit().putBoolean("openai_moderation", checked).apply();
|
||||
}
|
||||
});
|
||||
|
||||
ibOpenAi.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -2342,6 +2351,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
float temperature = prefs.getFloat("openai_temperature", 0.5f);
|
||||
tvOpenAiTemperature.setText(getString(R.string.title_advanced_openai_temperature, NF.format(temperature)));
|
||||
sbOpenAiTemperature.setProgress(Math.round(temperature * 10));
|
||||
swOpenAiModeration.setChecked(prefs.getBoolean("openai_moderation", false));
|
||||
|
||||
swWatchdog.setChecked(prefs.getBoolean("watchdog", true));
|
||||
swMainLog.setChecked(prefs.getBoolean("main_log", true));
|
||||
|
|
|
@ -115,10 +115,13 @@ public class OpenAI {
|
|||
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
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean openai_moderation = prefs.getBoolean("openai_moderation", false);
|
||||
|
||||
JSONArray jmessages = new JSONArray();
|
||||
for (Message message : messages) {
|
||||
checkModeration(context, message.content);
|
||||
if (openai_moderation)
|
||||
checkModeration(context, message.content);
|
||||
JSONObject jmessage = new JSONObject();
|
||||
jmessage.put("role", message.role);
|
||||
jmessage.put("content", message.content);
|
||||
|
|
|
@ -984,6 +984,18 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvOpenAiTemperature" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/swOpenAiModeration"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_advanced_openai_moderation"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/sbOpenAiTemperature"
|
||||
app:switchPadding="12dp" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/ibOpenAi"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -993,7 +1005,7 @@
|
|||
android:contentDescription="@string/title_info"
|
||||
android:tooltipText="@string/title_info"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/sbOpenAiTemperature"
|
||||
app:layout_constraintTop_toBottomOf="@id/swOpenAiModeration"
|
||||
app:srcCompat="@drawable/twotone_info_24" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
|
|
|
@ -797,6 +797,7 @@
|
|||
<string name="title_advanced_openai">OpenAI (ChatGPT) integration</string>
|
||||
<string name="title_advanced_openai_model">Model</string>
|
||||
<string name="title_advanced_openai_temperature">Temperature: %1$s</string>
|
||||
<string name="title_advanced_openai_moderation">Content moderation</string>
|
||||
<string name="title_advanced_sdcard">I want to use an sdcard</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