ForcePilot/backend/package/yuxi/channel/extensions/confluence/streaming.py

30 lines
801 B
Python
Raw Normal View History

class ConfluenceStreaming:
streaming_mode = "block"
block_streaming_enabled = True
MIN_CHARS = 200
MAX_CHARS = 2000
CHUNK_BREAK = "paragraph"
COALESCE_MIN = 80
COALESCE_MAX = 400
COALESCE_IDLE_MS = 500
MAX_BLOCKS = 5
FINISH_MARK = "..."
@classmethod
def should_stream(cls, estimated_length: int) -> bool:
return estimated_length > cls.MIN_CHARS
@classmethod
def build_chunk(cls, text: str, is_final: bool) -> str:
if is_final:
return text
return f"{text}\n\n{cls.FINISH_MARK}"
@classmethod
def create_chunker(cls):
return {
"mode": "paragraph",
"min_chars": cls.COALESCE_MIN,
"max_chars": cls.MAX_CHARS,
"break_on": cls.CHUNK_BREAK,
}