|
|
""" |
|
|
Streaming Configuration for Research Paper Generator with Yield Support and AStream |
|
|
|
|
|
This file contains all the streaming settings that can be modified at runtime. |
|
|
Adjust these values to control the streaming behavior, yield processing, and AStream functionality. |
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
STREAM_DELAY = 0.05 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
YIELD_CHUNK_SIZES = { |
|
|
"topic_analyzer": 50, |
|
|
"research_retriever": 100, |
|
|
"outline_builder": 75, |
|
|
"outline_revision": 75, |
|
|
"draft_writer": 150, |
|
|
"bibliography_generator": 100 |
|
|
} |
|
|
|
|
|
|
|
|
TOKEN_CHUNK_SIZE = 50 |
|
|
|
|
|
|
|
|
PROGRESS_UPDATE_FREQUENCY = 5 |
|
|
|
|
|
|
|
|
ENABLE_YIELD_PROCESSING = True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ENABLE_ASTREAM_PROCESSING = True |
|
|
|
|
|
|
|
|
ASTREAM_CHUNK_SIZES = { |
|
|
"topic_analyzer": 25, |
|
|
"research_retriever": 50, |
|
|
"outline_builder": 40, |
|
|
"outline_revision": 40, |
|
|
"draft_writer": 75, |
|
|
"bibliography_generator": 50 |
|
|
} |
|
|
|
|
|
|
|
|
ASTREAM_DELAY = 0.01 |
|
|
|
|
|
|
|
|
ASTREAM_BUFFER_SIZE = 100 |
|
|
|
|
|
|
|
|
ASTREAM_REALTIME = True |
|
|
|
|
|
|
|
|
ASTREAM_EVENT_FREQUENCY = 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
STREAMING_CONFIG = { |
|
|
"enabled": True, |
|
|
|
|
|
|
|
|
"show_topic_analysis": False, |
|
|
"show_research_retrieval": False, |
|
|
"show_outline_building": True, |
|
|
"show_outline_revision": True, |
|
|
"show_draft_writing": True, |
|
|
"show_bibliography": False, |
|
|
|
|
|
|
|
|
"show_progress_bars": True, |
|
|
"show_word_counts": True, |
|
|
"show_previews": True, |
|
|
"show_chunks": True, |
|
|
"show_yield_events": True, |
|
|
"show_astream": True, |
|
|
"show_astream_tokens": False, |
|
|
"show_astream_chunks": True, |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FAST_STREAMING = { |
|
|
"stream_delay": 0.01, |
|
|
"show_topic_analysis": False, |
|
|
"show_research_retrieval": False, |
|
|
"show_outline_building": True, |
|
|
"show_outline_revision": True, |
|
|
"show_draft_writing": True, |
|
|
"show_bibliography": False, |
|
|
"show_chunks": True, |
|
|
"show_yield_events": True, |
|
|
"show_astream": True, |
|
|
"show_astream_tokens": False, |
|
|
"show_astream_chunks": True, |
|
|
} |
|
|
|
|
|
|
|
|
SLOW_STREAMING = { |
|
|
"stream_delay": 0.1, |
|
|
"show_topic_analysis": True, |
|
|
"show_research_retrieval": True, |
|
|
"show_outline_building": True, |
|
|
"show_outline_revision": True, |
|
|
"show_draft_writing": True, |
|
|
"show_bibliography": True, |
|
|
"show_chunks": True, |
|
|
"show_yield_events": True, |
|
|
"show_astream": True, |
|
|
"show_astream_tokens": True, |
|
|
"show_astream_chunks": True, |
|
|
} |
|
|
|
|
|
|
|
|
NO_STREAMING = { |
|
|
"enabled": False, |
|
|
"stream_delay": 0.0, |
|
|
"show_chunks": False, |
|
|
"show_yield_events": False, |
|
|
"show_astream": False, |
|
|
"show_astream_tokens": False, |
|
|
"show_astream_chunks": False, |
|
|
} |
|
|
|
|
|
|
|
|
YIELD_STREAMING = { |
|
|
"stream_delay": 0.02, |
|
|
"show_topic_analysis": True, |
|
|
"show_research_retrieval": True, |
|
|
"show_outline_building": True, |
|
|
"show_outline_revision": True, |
|
|
"show_draft_writing": True, |
|
|
"show_bibliography": True, |
|
|
"show_chunks": True, |
|
|
"show_yield_events": True, |
|
|
"show_astream": True, |
|
|
"show_astream_tokens": False, |
|
|
"show_astream_chunks": True, |
|
|
"chunk_sizes": { |
|
|
"topic_analyzer": 25, |
|
|
"research_retriever": 50, |
|
|
"outline_builder": 40, |
|
|
"outline_revision": 40, |
|
|
"draft_writer": 75, |
|
|
"bibliography_generator": 50 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ASTREAM_STREAMING = { |
|
|
"stream_delay": 0.005, |
|
|
"show_topic_analysis": True, |
|
|
"show_research_retrieval": True, |
|
|
"show_outline_building": True, |
|
|
"show_outline_revision": True, |
|
|
"show_draft_writing": True, |
|
|
"show_bibliography": True, |
|
|
"show_chunks": True, |
|
|
"show_yield_events": True, |
|
|
"show_astream": True, |
|
|
"show_astream_tokens": True, |
|
|
"show_astream_chunks": True, |
|
|
"astream_delay": 0.005, |
|
|
"astream_realtime": True, |
|
|
"astream_event_frequency": 5, |
|
|
"chunk_sizes": { |
|
|
"topic_analyzer": 15, |
|
|
"research_retriever": 30, |
|
|
"outline_builder": 25, |
|
|
"outline_revision": 25, |
|
|
"draft_writer": 50, |
|
|
"bibliography_generator": 30 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_streaming_config(preset=None): |
|
|
""" |
|
|
Get streaming configuration with optional preset |
|
|
|
|
|
Args: |
|
|
preset (str): 'fast', 'slow', 'none', 'yield', 'astream', or None for default |
|
|
|
|
|
Returns: |
|
|
dict: Streaming configuration |
|
|
""" |
|
|
if preset == "fast": |
|
|
return {**STREAMING_CONFIG, **FAST_STREAMING} |
|
|
elif preset == "slow": |
|
|
return {**STREAMING_CONFIG, **SLOW_STREAMING} |
|
|
elif preset == "none": |
|
|
return {**STREAMING_CONFIG, **NO_STREAMING} |
|
|
elif preset == "yield": |
|
|
return {**STREAMING_CONFIG, **YIELD_STREAMING} |
|
|
elif preset == "astream": |
|
|
return {**STREAMING_CONFIG, **ASTREAM_STREAMING} |
|
|
else: |
|
|
return {**STREAMING_CONFIG, "stream_delay": STREAM_DELAY} |
|
|
|
|
|
def get_chunk_size(step_name: str, preset: str = None) -> int: |
|
|
""" |
|
|
Get chunk size for a specific step |
|
|
|
|
|
Args: |
|
|
step_name: Name of the processing step |
|
|
preset: Optional preset name |
|
|
|
|
|
Returns: |
|
|
int: Chunk size for the step |
|
|
""" |
|
|
if preset == "yield": |
|
|
return YIELD_STREAMING.get("chunk_sizes", {}).get(step_name, 50) |
|
|
elif preset == "astream": |
|
|
return ASTREAM_STREAMING.get("chunk_sizes", {}).get(step_name, 30) |
|
|
else: |
|
|
return YIELD_CHUNK_SIZES.get(step_name, 100) |
|
|
|
|
|
def get_astream_chunk_size(step_name: str, preset: str = None) -> int: |
|
|
""" |
|
|
Get AStream chunk size for a specific step |
|
|
|
|
|
Args: |
|
|
step_name: Name of the processing step |
|
|
preset: Optional preset name |
|
|
|
|
|
Returns: |
|
|
int: AStream chunk size for the step |
|
|
""" |
|
|
if preset == "astream": |
|
|
return ASTREAM_STREAMING.get("chunk_sizes", {}).get(step_name, 30) |
|
|
else: |
|
|
return ASTREAM_CHUNK_SIZES.get(step_name, 50) |
|
|
|
|
|
def is_yield_enabled(preset: str = None) -> bool: |
|
|
""" |
|
|
Check if yield processing is enabled |
|
|
|
|
|
Args: |
|
|
preset: Optional preset name |
|
|
|
|
|
Returns: |
|
|
bool: True if yield processing is enabled |
|
|
""" |
|
|
if preset == "none": |
|
|
return False |
|
|
return ENABLE_YIELD_PROCESSING |
|
|
|
|
|
def is_astream_enabled(preset: str = None) -> bool: |
|
|
""" |
|
|
Check if AStream processing is enabled |
|
|
|
|
|
Args: |
|
|
preset: Optional preset name |
|
|
|
|
|
Returns: |
|
|
bool: True if AStream processing is enabled |
|
|
""" |
|
|
if preset == "none": |
|
|
return False |
|
|
return ENABLE_ASTREAM_PROCESSING |
|
|
|
|
|
def get_astream_config(preset: str = None) -> dict: |
|
|
""" |
|
|
Get AStream-specific configuration |
|
|
|
|
|
Args: |
|
|
preset: Optional preset name |
|
|
|
|
|
Returns: |
|
|
dict: AStream configuration |
|
|
""" |
|
|
base_config = { |
|
|
"enabled": ENABLE_ASTREAM_PROCESSING, |
|
|
"delay": ASTREAM_DELAY, |
|
|
"buffer_size": ASTREAM_BUFFER_SIZE, |
|
|
"realtime": ASTREAM_REALTIME, |
|
|
"event_frequency": ASTREAM_EVENT_FREQUENCY |
|
|
} |
|
|
|
|
|
if preset == "astream": |
|
|
return {**base_config, **ASTREAM_STREAMING} |
|
|
else: |
|
|
return base_config |
|
|
|
|
|
def print_streaming_help(): |
|
|
"""Print help information about streaming configuration""" |
|
|
print("\n" + "="*60) |
|
|
print("STREAMING CONFIGURATION HELP") |
|
|
print("="*60) |
|
|
print("To modify streaming behavior, edit streaming_config.py:") |
|
|
print() |
|
|
print("1. Change STREAM_DELAY for speed control:") |
|
|
print(" - 0.0 = Instant") |
|
|
print(" - 0.05 = Medium (default)") |
|
|
print(" - 0.1 = Slow") |
|
|
print() |
|
|
print("2. Enable/disable steps in STREAMING_CONFIG:") |
|
|
print(" - show_topic_analysis: True/False") |
|
|
print(" - show_outline_building: True/False") |
|
|
print(" - show_draft_writing: True/False") |
|
|
print(" - show_chunks: True/False") |
|
|
print(" - show_yield_events: True/False") |
|
|
print(" - show_astream: True/False") |
|
|
print(" - show_astream_tokens: True/False") |
|
|
print(" - show_astream_chunks: True/False") |
|
|
print() |
|
|
print("3. Configure yield processing:") |
|
|
print(" - YIELD_CHUNK_SIZES: Control chunk sizes per step") |
|
|
print(" - ENABLE_YIELD_PROCESSING: Enable/disable yield generators") |
|
|
print(" - TOKEN_CHUNK_SIZE: Control token chunking") |
|
|
print() |
|
|
print("4. Configure AStream processing:") |
|
|
print(" - ENABLE_ASTREAM_PROCESSING: Enable/disable AStream") |
|
|
print(" - ASTREAM_CHUNK_SIZES: Control AStream chunk sizes") |
|
|
print(" - ASTREAM_DELAY: Control AStream processing delay") |
|
|
print(" - ASTREAM_REALTIME: Enable real-time AStream processing") |
|
|
print() |
|
|
print("5. Use presets in main.py:") |
|
|
print(" - streaming_config = get_streaming_config('fast')") |
|
|
print(" - streaming_config = get_streaming_config('slow')") |
|
|
print(" - streaming_config = get_streaming_config('none')") |
|
|
print(" - streaming_config = get_streaming_config('yield')") |
|
|
print(" - streaming_config = get_streaming_config('astream')") |
|
|
print() |
|
|
print("6. Yield Generator Features:") |
|
|
print(" - Progressive text processing") |
|
|
print(" - Memory-efficient streaming") |
|
|
print(" - Real-time chunk updates") |
|
|
print(" - Configurable chunk sizes") |
|
|
print() |
|
|
print("7. AStream Features:") |
|
|
print(" - Async streaming with better performance") |
|
|
print(" - Real-time token processing") |
|
|
print(" - Configurable async delays") |
|
|
print(" - Buffer-based token accumulation") |
|
|
print("="*60) |