improve xiaoniu reply chunk splitting
This commit is contained in:
@@ -608,7 +608,7 @@ class AIAutoResponsePlugin(MessagePluginInterface):
|
|||||||
first = parts[0].strip() if parts and parts[0].strip() else text.strip()
|
first = parts[0].strip() if parts and parts[0].strip() else text.strip()
|
||||||
if len(first) <= limit:
|
if len(first) <= limit:
|
||||||
return first
|
return first
|
||||||
clipped = first[:limit].rstrip(",,、;;::")
|
clipped = AIAutoResponsePlugin._smart_clip(first, limit)
|
||||||
return clipped
|
return clipped
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -616,18 +616,40 @@ class AIAutoResponsePlugin(MessagePluginInterface):
|
|||||||
parts = [item.strip() for item in re.split(r"(?<=[。!?!?;;])", text) if item.strip()]
|
parts = [item.strip() for item in re.split(r"(?<=[。!?!?;;])", text) if item.strip()]
|
||||||
if not parts:
|
if not parts:
|
||||||
short = text.strip()
|
short = text.strip()
|
||||||
return [short[:char_limit].rstrip(",,、;;::").strip()] if short else []
|
clipped = AIAutoResponsePlugin._smart_clip(short, char_limit)
|
||||||
|
remainder = short[len(clipped):].strip(",,、;;:: ")
|
||||||
|
return [item for item in [clipped, AIAutoResponsePlugin._smart_clip(remainder, char_limit)] if item][:chunk_limit] if short else []
|
||||||
|
|
||||||
chunks: List[str] = []
|
chunks: List[str] = []
|
||||||
for part in parts[:sentence_limit]:
|
for part in parts[:sentence_limit]:
|
||||||
current = part
|
current = part.strip()
|
||||||
if len(current) > char_limit:
|
while current and len(chunks) < chunk_limit:
|
||||||
current = current[:char_limit].rstrip(",,、;;::")
|
if len(current) <= char_limit:
|
||||||
if current:
|
|
||||||
chunks.append(current.strip())
|
chunks.append(current.strip())
|
||||||
if len(chunks) >= chunk_limit:
|
|
||||||
break
|
break
|
||||||
return chunks[:chunk_limit] or [text[:char_limit].strip()]
|
clipped = AIAutoResponsePlugin._smart_clip(current, char_limit)
|
||||||
|
if not clipped:
|
||||||
|
clipped = current[:char_limit].rstrip(",,、;;:: ").strip()
|
||||||
|
if clipped:
|
||||||
|
chunks.append(clipped)
|
||||||
|
current = current[len(clipped):].strip(",,、;;:: ")
|
||||||
|
return chunks[:chunk_limit] or [AIAutoResponsePlugin._smart_clip(text, char_limit)]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _smart_clip(text: str, limit: int) -> str:
|
||||||
|
text = str(text or "").strip()
|
||||||
|
if len(text) <= limit:
|
||||||
|
return text
|
||||||
|
window = text[:limit]
|
||||||
|
punctuation = ",,、;;::。!?!?))】]」』 "
|
||||||
|
split_at = -1
|
||||||
|
for idx in range(len(window) - 1, max(len(window) - 10, 0) - 1, -1):
|
||||||
|
if window[idx] in punctuation:
|
||||||
|
split_at = idx
|
||||||
|
break
|
||||||
|
if split_at >= 0:
|
||||||
|
return window[:split_at].rstrip(",,、;;::。!?!? ").strip()
|
||||||
|
return window.rstrip(",,、;;:: ").strip()
|
||||||
|
|
||||||
def _sync_member_memory(self, room_id: str, sender: str, sender_name: str, member_context: Dict) -> None:
|
def _sync_member_memory(self, room_id: str, sender: str, sender_name: str, member_context: Dict) -> None:
|
||||||
if not member_context:
|
if not member_context:
|
||||||
|
|||||||
Reference in New Issue
Block a user