From dcfe10a7faabfd5c1d068f061301a80879e3e0dc Mon Sep 17 00:00:00 2001 From: liwenrui Date: Mon, 10 Jul 2023 14:28:45 +0800 Subject: [PATCH] * handle empty inputs. --- module/ai/model.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/module/ai/model.php b/module/ai/model.php index 08d9267f6a..e023dcbb3c 100644 --- a/module/ai/model.php +++ b/module/ai/model.php @@ -648,8 +648,9 @@ class aiModel extends model */ private static function autoPrependNewline($text) { - preg_match('/\n[^$]/', $text, $matches); + if(empty($text)) return ''; + preg_match('/\n[^$]/', $text, $matches); return empty($matches) ? $text : "\n$text"; } @@ -663,6 +664,8 @@ class aiModel extends model */ private static function tryPunctuate($sentence, $newline = false) { + if(empty($sentence)) return ''; + preg_match('/\p{P}$/u', $sentence, $matches); if(empty($matches)) $sentence .= '.';