From 69253850746a805cefb4edf8f7d64e59f64217a2 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 31 May 2024 08:26:47 +0200 Subject: [PATCH] Use message text as prompt when using default prompt --- app/src/main/java/eu/faircode/email/AI.java | 21 ++++++++++++------- .../eu/faircode/email/FragmentCompose.java | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AI.java b/app/src/main/java/eu/faircode/email/AI.java index b8c708b053..aba4a49121 100644 --- a/app/src/main/java/eu/faircode/email/AI.java +++ b/app/src/main/java/eu/faircode/email/AI.java @@ -46,9 +46,7 @@ public class AI { static Spanned completeChat(Context context, long id, CharSequence body, long template) throws JSONException, IOException { String reply = null; - if (body == null || TextUtils.isEmpty(body.toString().trim())) { - body = "?"; - + if (body == null || body.length() == 0 || template < 0L /* Default */) { File file = EntityMessage.getFile(context, id); if (file.exists()) { Document d = JsoupEx.parse(file); @@ -68,13 +66,20 @@ public class AI { } String prompt = null; - DB db = DB.getInstance(context); - EntityAnswer t = db.answer().getAnswer(template); - if (t != null) { - String html = t.getHtml(context, null); - prompt = JsoupEx.parse(html).body().text(); + if (template < 0L) + prompt = (body == null ? null : body.toString()); + else { + DB db = DB.getInstance(context); + EntityAnswer t = db.answer().getAnswer(template); + if (t != null) { + String html = t.getHtml(context, null); + prompt = JsoupEx.parse(html).body().text(); + } } + if (body == null || body.length() == 0) + body = "?"; + StringBuilder sb = new StringBuilder(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (OpenAI.isAvailable(context)) { diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 6eb67cd33c..110d2373d7 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -2697,7 +2697,7 @@ public class FragmentCompose extends FragmentBase { Bundle args = new Bundle(); args.putLong("id", working); args.putCharSequence("body", body); - args.putLong("template", template == null ? -1L : template); + args.putLong("template", template == null ? 0L : template); new SimpleTask() { @Override