OpenAI: refactoring

This commit is contained in:
M66B
2023-03-10 11:54:31 +01:00
parent b075824fd7
commit a50ae9d0cf
2 changed files with 14 additions and 15 deletions

View File

@@ -229,6 +229,18 @@ public class OpenAI {
}
}
static String truncateParagraphs(@NonNull String text, int maxlen) {
String[] paragraphs = text.split("[\\r\\n]+");
int i = 0;
StringBuilder sb = new StringBuilder();
while (i < paragraphs.length &&
sb.length() + paragraphs[i].length() + 1 < maxlen)
sb.append(paragraphs[i++]).append('\n');
return sb.toString();
}
static class Message {
private final String role; // // system, user, assistant
private final String content;