|
1 | 1 | import os
|
2 | 2 | import pickle
|
| 3 | +import uuid |
3 | 4 |
|
4 | 5 |
|
5 |
| -def load_config_from_file(file_path: str='./.config.pkl',) -> dict: |
| 6 | +def load_config_from_file(config_file): |
| 7 | + """Load settings from a UUID.pkl file.""" |
6 | 8 | try:
|
7 |
| - with open(file_path, 'rb') as file: |
8 |
| - loaded_config = pickle.load(file) |
9 |
| - except FileNotFoundError as FNFE: |
10 |
| - from dotenv import load_dotenv |
11 |
| - load_dotenv() |
12 |
| - return { |
13 |
| - "agent_type": "custom", |
14 |
| - "max_steps": 100, |
15 |
| - "max_actions_per_step": 10, |
16 |
| - "use_vision": True, |
17 |
| - "tool_call_in_content": True, |
18 |
| - "llm_provider": "openai", |
19 |
| - "llm_model_name": "gpt-4o", |
20 |
| - "llm_temperature": 1.0, |
21 |
| - "llm_base_url": '', |
22 |
| - "llm_api_key": '', |
23 |
| - "use_own_browser": False, |
24 |
| - "keep_browser_open": os.getenv("CHROME_PERSISTENT_SESSION", "False").lower() == "true", |
25 |
| - "headless": False, |
26 |
| - "disable_security": True, |
27 |
| - "enable_recording": True, |
28 |
| - "window_w": 1280, |
29 |
| - "window_h": 1100, |
30 |
| - "save_recording_path": "./tmp/record_videos", |
31 |
| - "save_trace_path": "./tmp/traces", |
32 |
| - "save_agent_history_path": "./tmp/agent_history", |
33 |
| - "task": "go to google.com and type 'OpenAI' click search and give me the first url", |
34 |
| - } |
35 |
| - return loaded_config |
| 9 | + with open(config_file, 'rb') as f: |
| 10 | + settings = pickle.load(f) |
| 11 | + return settings |
| 12 | + except Exception as e: |
| 13 | + return f"Error loading configuration: {str(e)}" |
36 | 14 |
|
37 | 15 |
|
38 |
| -def save_config_to_file(config, file_path: str='./.config.pkl',) -> None: |
39 |
| - with open(file_path, 'wb') as file: |
40 |
| - pickle.dump(config, file) |
| 16 | +def save_config_to_file(settings, save_dir="./tmp/webui_settings"): |
| 17 | + """Save the current settings to a UUID.pkl file with a UUID name.""" |
| 18 | + os.makedirs(save_dir, exist_ok=True) |
| 19 | + config_file = os.path.join(save_dir, f"{uuid.uuid4()}.pkl") |
| 20 | + with open(config_file, 'wb') as f: |
| 21 | + pickle.dump(settings, f) |
| 22 | + return f"Configuration saved to {config_file}" |
0 commit comments