mirror of https://github.com/M66B/FairEmail.git
Refactoring
This commit is contained in:
parent
1a9748191b
commit
6edffb9a61
|
@ -2685,7 +2685,8 @@ public class FragmentCompose extends FragmentBase {
|
||||||
List<OpenAI.Message> result = new ArrayList<>();
|
List<OpenAI.Message> result = new ArrayList<>();
|
||||||
|
|
||||||
if (inreplyto.size() > 0 && inreplyto.get(0).content) {
|
if (inreplyto.size() > 0 && inreplyto.get(0).content) {
|
||||||
String role = (MessageHelper.equalEmail(draft.from, inreplyto.get(0).from) ? "assistant" : "user");
|
String role = (MessageHelper.equalEmail(draft.from, inreplyto.get(0).from)
|
||||||
|
? OpenAI.ASSISTANT : OpenAI.USER);
|
||||||
Document parsed = JsoupEx.parse(inreplyto.get(0).getFile(context));
|
Document parsed = JsoupEx.parse(inreplyto.get(0).getFile(context));
|
||||||
Document document = HtmlHelper.sanitizeView(context, parsed, false);
|
Document document = HtmlHelper.sanitizeView(context, parsed, false);
|
||||||
Spanned spanned = HtmlHelper.fromDocument(context, document, null, null);
|
Spanned spanned = HtmlHelper.fromDocument(context, document, null, null);
|
||||||
|
@ -2693,7 +2694,7 @@ public class FragmentCompose extends FragmentBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(body))
|
if (!TextUtils.isEmpty(body))
|
||||||
result.add(new OpenAI.Message("assistant", OpenAI.truncateParagraphs(body)));
|
result.add(new OpenAI.Message(OpenAI.ASSISTANT, OpenAI.truncateParagraphs(body)));
|
||||||
|
|
||||||
if (result.size() == 0)
|
if (result.size() == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -118,8 +118,8 @@ public class FragmentDialogSummarize extends FragmentDialogBase {
|
||||||
float temperature = prefs.getFloat("openai_temperature", 0.5f);
|
float temperature = prefs.getFloat("openai_temperature", 0.5f);
|
||||||
|
|
||||||
List<OpenAI.Message> result = new ArrayList<>();
|
List<OpenAI.Message> result = new ArrayList<>();
|
||||||
result.add(new OpenAI.Message("assistant", OpenAI.SUMMARY_PROMPT));
|
result.add(new OpenAI.Message(OpenAI.ASSISTANT, OpenAI.SUMMARY_PROMPT));
|
||||||
result.add(new OpenAI.Message("user", text));
|
result.add(new OpenAI.Message(OpenAI.USER, text));
|
||||||
OpenAI.Message[] completions =
|
OpenAI.Message[] completions =
|
||||||
OpenAI.completeChat(context, model, result.toArray(new OpenAI.Message[0]), temperature, 1);
|
OpenAI.completeChat(context, model, result.toArray(new OpenAI.Message[0]), temperature, 1);
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
|
@ -43,6 +43,8 @@ import java.util.Objects;
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
|
||||||
public class OpenAI {
|
public class OpenAI {
|
||||||
|
static final String ASSISTANT = "assistant";
|
||||||
|
static final String USER = "user";
|
||||||
static final String SUMMARY_PROMPT = "Summarize the following text:";
|
static final String SUMMARY_PROMPT = "Summarize the following text:";
|
||||||
|
|
||||||
private static final int MAX_OPENAI_LEN = 1000; // characters
|
private static final int MAX_OPENAI_LEN = 1000; // characters
|
||||||
|
|
Loading…
Reference in New Issue