Refactoring

pull/212/head
M66B 2 years ago
parent 5e55ed50bf
commit f4fa965469

@ -313,8 +313,6 @@ public class FragmentCompose extends FragmentBase {
private static final int MAX_QUOTE_LEVEL = 5;
private static final int MAX_OPENAI_LEN = 1000; // characters
private static final int REQUEST_CONTACT_TO = 1;
private static final int REQUEST_CONTACT_CC = 2;
private static final int REQUEST_CONTACT_BCC = 3;
@ -2432,11 +2430,11 @@ public class FragmentCompose extends FragmentBase {
Document parsed = JsoupEx.parse(inreplyto.get(0).getFile(context));
Document document = HtmlHelper.sanitizeView(context, parsed, false);
Spanned spanned = HtmlHelper.fromDocument(context, document, null, null);
result.add(new OpenAI.Message(role, OpenAI.truncateParagraphs(spanned.toString(), MAX_OPENAI_LEN)));
result.add(new OpenAI.Message(role, OpenAI.truncateParagraphs(spanned.toString())));
}
if (!TextUtils.isEmpty(body))
result.add(new OpenAI.Message("assistant", OpenAI.truncateParagraphs(body, MAX_OPENAI_LEN)));
result.add(new OpenAI.Message("assistant", OpenAI.truncateParagraphs(body)));
if (result.size() == 0)
return null;

@ -42,6 +42,7 @@ import java.util.Iterator;
import java.util.List;
public class OpenAI {
private static final int MAX_OPENAI_LEN = 1000; // characters
private static final int TIMEOUT = 30; // seconds
static boolean isAvailable(Context context) {
@ -229,6 +230,10 @@ public class OpenAI {
}
}
static String truncateParagraphs(@NonNull String text) {
return truncateParagraphs(text, MAX_OPENAI_LEN);
}
static String truncateParagraphs(@NonNull String text, int maxlen) {
String[] paragraphs = text.split("[\\r\\n]+");

Loading…
Cancel
Save