* handle empty inputs.

This commit is contained in:
liwenrui
2023-07-10 14:28:45 +08:00
parent 2b799c6598
commit dcfe10a7fa
+4 -1
View File
@@ -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 .= '.';