31 lines
858 B
Python
31 lines
858 B
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import logging
|
||
|
|
|
||
|
|
logger = logging.getLogger(__name__)
|
||
|
|
|
||
|
|
|
||
|
|
class TwitterStreaming:
|
||
|
|
streaming_mode = "block"
|
||
|
|
|
||
|
|
block_streaming_enabled = True
|
||
|
|
block_streaming_break = "text_end"
|
||
|
|
block_streaming_chunk_min_chars = 800
|
||
|
|
block_streaming_chunk_max_chars = 4000
|
||
|
|
block_streaming_chunk_break_preference = "paragraph"
|
||
|
|
block_streaming_coalesce_defaults = {
|
||
|
|
"min_chars": 400,
|
||
|
|
"max_chars": 2000,
|
||
|
|
"idle_ms": 1000,
|
||
|
|
}
|
||
|
|
|
||
|
|
def create_draft_stream_session(self, target_id: str) -> dict:
|
||
|
|
return {"target_id": target_id, "mode": "block", "chunks_sent": 0}
|
||
|
|
|
||
|
|
def create_block_chunker(self) -> dict:
|
||
|
|
return {
|
||
|
|
"mode": "length",
|
||
|
|
"min_chars": self.block_streaming_chunk_min_chars,
|
||
|
|
"max_chars": self.block_streaming_chunk_max_chars,
|
||
|
|
}
|