Added option to turn off multimodality

pull/215/head
M66B 7 months ago
parent 40daebe326
commit 0244ef3f82

@ -80,6 +80,7 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
private EditText etOpenAi;
private TextInputLayout tilOpenAi;
private EditText etOpenAiModel;
private SwitchCompat swOpenMultiModal;
private TextView tvOpenAiTemperature;
private SeekBar sbOpenAiTemperature;
private EditText etOpenAiSummarize;
@ -106,7 +107,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_temperature", "openai_summarize",
"openai_enabled", "openai_uri", "openai_model", "openai_multimodal", "openai_temperature", "openai_summarize",
"gemini_enabled", "gemini_uri", "gemini_model", "gemini_temperature", "gemini_summarize"
));
@ -152,6 +153,7 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
etOpenAi = view.findViewById(R.id.etOpenAi);
tilOpenAi = view.findViewById(R.id.tilOpenAi);
etOpenAiModel = view.findViewById(R.id.etOpenAiModel);
swOpenMultiModal = view.findViewById(R.id.swOpenMultiModal);
tvOpenAiTemperature = view.findViewById(R.id.tvOpenAiTemperature);
sbOpenAiTemperature = view.findViewById(R.id.sbOpenAiTemperature);
etOpenAiSummarize = view.findViewById(R.id.etOpenAiSummarize);
@ -419,6 +421,7 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("openai_enabled", checked).apply();
etOpenAiModel.setEnabled(checked);
swOpenMultiModal.setEnabled(checked);
sbOpenAiTemperature.setEnabled(checked);
etOpenAiSummarize.setEnabled(checked);
if (checked)
@ -499,6 +502,13 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
}
});
swOpenMultiModal.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
prefs.edit().putBoolean("openai_multimodal", checked).apply();
}
});
sbOpenAiTemperature.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
@ -779,6 +789,9 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP
etOpenAiModel.setText(prefs.getString("openai_model", null));
etOpenAiModel.setEnabled(swOpenAi.isChecked());
swOpenMultiModal.setChecked(prefs.getBoolean("openai_multimodal", true));
swOpenMultiModal.setEnabled(swOpenAi.isChecked());
float temperature = prefs.getFloat("openai_temperature", OpenAI.DEFAULT_TEMPERATURE);
tvOpenAiTemperature.setText(getString(R.string.title_advanced_openai_temperature, NF.format(temperature)));
sbOpenAiTemperature.setProgress(Math.round(temperature * 10));

@ -265,6 +265,9 @@ public class OpenAI {
}
static Content[] get(Spannable ssb, long id, Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean multimodal = prefs.getBoolean("openai_multimodal", true);
DB db = DB.getInstance(context);
List<OpenAI.Content> contents = new ArrayList<>();
int start = 0;
@ -276,28 +279,31 @@ public class OpenAI {
ImageSpanEx[] spans = ssb.getSpans(end, end, ImageSpanEx.class);
if (spans.length == 1) {
int e = ssb.getSpanEnd(spans[0]);
String src = spans[0].getSource();
String url = null;
if (src != null && src.startsWith("cid:")) {
String cid = '<' + src.substring(4) + '>';
EntityAttachment attachment = db.attachment().getAttachment(id, cid);
if (attachment != null && attachment.available) {
File file = attachment.getFile(context);
try (InputStream is = new FileInputStream(file)) {
Bitmap bm = ImageHelper.getScaledBitmap(is, null, null, SCALE2PIXELS);
Helper.ByteArrayInOutStream bos = new Helper.ByteArrayInOutStream();
bm.compress(Bitmap.CompressFormat.PNG, 90, bos);
url = ImageHelper.getDataUri(bos.getInputStream(), "image/png");
} catch (Throwable ex) {
Log.w(ex);
if (multimodal) {
String url = null;
String src = spans[0].getSource();
if (src != null && src.startsWith("cid:")) {
String cid = '<' + src.substring(4) + '>';
EntityAttachment attachment = db.attachment().getAttachment(id, cid);
if (attachment != null && attachment.available) {
File file = attachment.getFile(context);
try (InputStream is = new FileInputStream(file)) {
Bitmap bm = ImageHelper.getScaledBitmap(is, null, null, SCALE2PIXELS);
Helper.ByteArrayInOutStream bos = new Helper.ByteArrayInOutStream();
bm.compress(Bitmap.CompressFormat.PNG, 90, bos);
url = ImageHelper.getDataUri(bos.getInputStream(), "image/png");
} catch (Throwable ex) {
Log.w(ex);
}
}
}
} else
url = src;
} else
url = src;
if (url != null)
contents.add(new OpenAI.Content(OpenAI.CONTENT_IMAGE, url));
}
if (url != null)
contents.add(new OpenAI.Content(OpenAI.CONTENT_IMAGE, url));
end = e;
}
}

@ -564,6 +564,19 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvOpenAiModel" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swOpenMultiModal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:checked="true"
android:text="@string/title_advanced_multi_modal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etOpenAiModel"
app:switchPadding="12dp" />
<TextView
android:id="@+id/tvOpenAiTemperature"
android:layout_width="0dp"
@ -575,7 +588,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etOpenAiModel" />
app:layout_constraintTop_toBottomOf="@id/swOpenMultiModal" />
<SeekBar
android:id="@+id/sbOpenAiTemperature"

@ -888,6 +888,7 @@
<string name="title_advanced_openai_temperature">Temperature: %1$s</string>
<string name="title_advanced_openai_moderation">Content moderation</string>
<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_sdcard">I want to use an SD card</string>
<string name="title_advanced_watchdog">Periodically check if FairEmail is still active</string>

Loading…
Cancel
Save