44std::optional<std::string>
StoryPrompt(std::string_view words) {
45 std::vector<std::string> kept;
46 for (
const std::string_view word :
47 absl::StrSplit(words, absl::ByAnyChar(
" ,"), absl::SkipEmpty())) {
52 kept.push_back(absl::AsciiStrToLower(word));
57 return absl::StrCat(
"Words: ", absl::StrJoin(kept,
", "),
"\nStory:");
60std::vector<std::string>
StoryLines(std::string_view story) {
61 std::size_t end = story.find_last_of(kSentenceEnds);
62 if (end != std::string_view::npos) {
64 if (end + 1 < story.size() && story[end + 1] ==
'"') {
67 story = story.substr(0, end + 1);
69 std::vector<std::string> lines;
72 std::size_t sentences = 0;
73 for (std::string_view word :
74 absl::StrSplit(story, absl::ByAsciiWhitespace(), absl::SkipEmpty())) {
77 lines.push_back(line);
81 const std::size_t cut = Cut(word);
82 lines.emplace_back(word.substr(0, cut));
83 word.remove_prefix(cut);
85 while (!line.empty() && line.size() + 1 + word.size() >
kMaxChatLength) {
86 const std::size_t cut = sentences > 0 ? sentences : line.size();
87 lines.push_back(line.substr(0, cut));
88 line.erase(0, std::min(cut + 1, line.size()));
95 if (EndsSentence(word)) {
96 sentences = line.size();
100 lines.push_back(line);