-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
172 lines (135 loc) · 5.62 KB
/
config.py
File metadata and controls
172 lines (135 loc) · 5.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
"""
Configuration management for Notebook-BCC.
"""
import os
from pathlib import Path
# Load .env file if it exists
try:
from dotenv import load_dotenv
load_dotenv()
except ImportError:
# python-dotenv not installed, skip
pass
class Config:
"""
Configuration for the workflow system.
Supports runtime configuration updates.
"""
# ==============================================
# API Endpoints
# ==============================================
# Backend base URL (from environment or default)
BACKEND_BASE_URL = os.getenv('BACKEND_BASE_URL', 'http://localhost:18600')
# DSLC (Data Science Lifecycle) base URL
DSLC_BASE_URL = os.getenv('DSLC_BASE_URL', 'http://localhost:28600')
# Initial notebook ID (can be overridden)
NOTEBOOK_ID = os.getenv('NOTEBOOK_ID', None)
@classmethod
def set_backend_url(cls, url: str):
"""Update backend URL at runtime."""
cls.BACKEND_BASE_URL = url
cls._rebuild_api_urls()
@classmethod
def set_dslc_url(cls, url: str):
"""Update DSLC URL at runtime."""
cls.DSLC_BASE_URL = url
cls._rebuild_api_urls()
@classmethod
def set_notebook_id(cls, notebook_id: str):
"""Set notebook ID at runtime."""
cls.NOTEBOOK_ID = notebook_id
@classmethod
def _rebuild_api_urls(cls):
"""Rebuild API URLs after base URL changes."""
# Workflow API endpoints
cls.FEEDBACK_API_URL = f"{cls.DSLC_BASE_URL}/planning"
cls.BEHAVIOR_API_URL = f"{cls.DSLC_BASE_URL}/generating"
cls.REFLECTING_API_URL = f"{cls.DSLC_BASE_URL}/reflecting"
cls.GENERATE_API_URL = f"{cls.DSLC_BASE_URL}/generate"
# Code execution API endpoints
cls.NOTEBOOK_INITIALIZE_URL = f"{cls.BACKEND_BASE_URL}/initialize"
cls.NOTEBOOK_EXECUTE_URL = f"{cls.BACKEND_BASE_URL}/execute"
cls.NOTEBOOK_STATUS_URL = f"{cls.BACKEND_BASE_URL}/get_status"
cls.NOTEBOOK_CANCEL_URL = f"{cls.BACKEND_BASE_URL}/cancel"
cls.NOTEBOOK_RESTART_URL = f"{cls.BACKEND_BASE_URL}/restart_kernel"
# Workflow API endpoints
FEEDBACK_API_URL = f"{DSLC_BASE_URL}/planning"
BEHAVIOR_API_URL = f"{DSLC_BASE_URL}/generating"
REFLECTING_API_URL = f"{DSLC_BASE_URL}/reflecting"
GENERATE_API_URL = f"{DSLC_BASE_URL}/generate"
# Code execution API endpoints
NOTEBOOK_INITIALIZE_URL = f"{BACKEND_BASE_URL}/initialize"
NOTEBOOK_EXECUTE_URL = f"{BACKEND_BASE_URL}/execute"
NOTEBOOK_STATUS_URL = f"{BACKEND_BASE_URL}/get_status"
NOTEBOOK_CANCEL_URL = f"{BACKEND_BASE_URL}/cancel"
NOTEBOOK_RESTART_URL = f"{BACKEND_BASE_URL}/restart_kernel"
# ==============================================
# Context Compression Settings
# ==============================================
MAX_CONTEXT_LENGTH = 18600 # Maximum context length for API calls
MAX_HISTORY_ITEMS = 50 # Maximum history items to keep
# ==============================================
# Execution Settings
# ==============================================
# Code execution polling interval (seconds)
STATUS_CHECK_INTERVAL = 1.0
# Execution timeout (seconds)
EXECUTION_TIMEOUT = 300
# ==============================================
# Storage Settings
# ==============================================
# Notebooks directory
NOTEBOOKS_DIR = Path('notebooks')
# Logs directory
LOGS_DIR = Path('logs')
# ==============================================
# Logging Settings
# ==============================================
LOG_LEVEL = os.getenv('LOG_LEVEL', 'INFO')
LOG_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
# ==============================================
# Workflow Control Settings
# ==============================================
# Maximum steps to execute (0 = unlimited)
MAX_EXECUTION_STEPS = int(os.getenv('MAX_EXECUTION_STEPS', '0'))
# Enable interactive mode (pause at breakpoints)
INTERACTIVE_MODE = os.getenv('INTERACTIVE_MODE', 'false').lower() == 'true'
# ==============================================
# Feature Flags
# ==============================================
# Use remote code execution (True) or local execution (False)
USE_REMOTE_EXECUTION = os.getenv('USE_REMOTE_EXECUTION', 'true').lower() == 'true'
# Enable API call compression
ENABLE_CONTEXT_COMPRESSION = True
# Enable streaming for behavior API
ENABLE_STREAMING = True
@classmethod
def ensure_directories(cls):
"""Ensure required directories exist."""
cls.NOTEBOOKS_DIR.mkdir(parents=True, exist_ok=True)
cls.LOGS_DIR.mkdir(parents=True, exist_ok=True)
@classmethod
def get_api_config(cls):
"""Get API configuration as a dictionary."""
return {
'backend_base_url': cls.BACKEND_BASE_URL,
'dslc_base_url': cls.DSLC_BASE_URL,
'feedback_api_url': cls.FEEDBACK_API_URL,
'behavior_api_url': cls.BEHAVIOR_API_URL,
'reflecting_api_url': cls.REFLECTING_API_URL,
'generate_api_url': cls.GENERATE_API_URL,
}
@classmethod
def get_execution_config(cls):
"""Get code execution configuration."""
return {
'initialize_url': cls.NOTEBOOK_INITIALIZE_URL,
'execute_url': cls.NOTEBOOK_EXECUTE_URL,
'status_url': cls.NOTEBOOK_STATUS_URL,
'cancel_url': cls.NOTEBOOK_CANCEL_URL,
'restart_url': cls.NOTEBOOK_RESTART_URL,
'use_remote': cls.USE_REMOTE_EXECUTION,
'timeout': cls.EXECUTION_TIMEOUT,
}
# Initialize on import
Config.ensure_directories()