Update src/utils/default_config_settings.py
Browse files- src/utils/default_config_settings.py +117 -122
src/utils/default_config_settings.py
CHANGED
|
@@ -1,122 +1,117 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import pickle
|
| 3 |
-
import uuid
|
| 4 |
-
import gradio as gr
|
| 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 |
-
gr.update(value=loaded_config.get("
|
| 86 |
-
gr.update(value=loaded_config.get("
|
| 87 |
-
gr.update(value=loaded_config.get("
|
| 88 |
-
gr.update(value=loaded_config.get("
|
| 89 |
-
gr.update(value=loaded_config.get("
|
| 90 |
-
gr.update(value=loaded_config.get("
|
| 91 |
-
gr.update(value=loaded_config.get("
|
| 92 |
-
gr.update(value=loaded_config.get("
|
| 93 |
-
gr.update(value=loaded_config.get("
|
| 94 |
-
gr.update(value=loaded_config.get("
|
| 95 |
-
gr.update(value=loaded_config.get("
|
| 96 |
-
gr.update(value=loaded_config.get("
|
| 97 |
-
gr.update(value=loaded_config.get("
|
| 98 |
-
gr.update(value=loaded_config.get("
|
| 99 |
-
gr.update(value=loaded_config.get("
|
| 100 |
-
gr.update(value=loaded_config.get("
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
gr.update(
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
gr.update(), gr.update(), gr.update(), gr.update(), gr.update(),
|
| 119 |
-
gr.update(), gr.update(), gr.update(), gr.update(), gr.update(),
|
| 120 |
-
gr.update(), gr.update(), gr.update(), gr.update(), gr.update(),
|
| 121 |
-
gr.update(), "No file selected."
|
| 122 |
-
)
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import pickle
|
| 3 |
+
import uuid
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
def default_config():
|
| 7 |
+
return {
|
| 8 |
+
"agent_type": "custom",
|
| 9 |
+
"max_steps": 100,
|
| 10 |
+
"max_actions_per_step": 10,
|
| 11 |
+
"use_vision": True,
|
| 12 |
+
"tool_call_in_content": True,
|
| 13 |
+
"llm_provider": "openai",
|
| 14 |
+
"llm_model_name": "gpt-4o",
|
| 15 |
+
"llm_temperature": 1.0,
|
| 16 |
+
"llm_base_url": "",
|
| 17 |
+
"llm_api_key": "",
|
| 18 |
+
"use_own_browser": os.getenv("CHROME_PERSISTENT_SESSION", "false").lower() == "true",
|
| 19 |
+
"keep_browser_open": False,
|
| 20 |
+
"headless": False,
|
| 21 |
+
"disable_security": True,
|
| 22 |
+
"enable_recording": True,
|
| 23 |
+
"window_w": 1280,
|
| 24 |
+
"window_h": 1100,
|
| 25 |
+
"save_recording_path": "./tmp/record_videos",
|
| 26 |
+
"save_trace_path": "./tmp/traces",
|
| 27 |
+
"save_agent_history_path": "./tmp/agent_history",
|
| 28 |
+
"task": "go to google.com and type 'OpenAI' click search and give me the first url",
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
def load_config_from_file(config_file):
|
| 32 |
+
try:
|
| 33 |
+
with open(config_file, 'rb') as f:
|
| 34 |
+
settings = pickle.load(f)
|
| 35 |
+
return settings
|
| 36 |
+
except Exception as e:
|
| 37 |
+
return f"Error loading configuration: {str(e)}"
|
| 38 |
+
|
| 39 |
+
def save_config_to_file(settings, save_dir="./tmp/webui_settings"):
|
| 40 |
+
os.makedirs(save_dir, exist_ok=True)
|
| 41 |
+
config_file = os.path.join(save_dir, f"{uuid.uuid4()}.pkl")
|
| 42 |
+
try:
|
| 43 |
+
with open(config_file, 'wb') as f:
|
| 44 |
+
pickle.dump(settings, f)
|
| 45 |
+
return f"Configuration saved to {config_file}"
|
| 46 |
+
except Exception as e:
|
| 47 |
+
return f"Error saving configuration: {str(e)}"
|
| 48 |
+
|
| 49 |
+
def save_current_config(*args):
|
| 50 |
+
current_config = {
|
| 51 |
+
"agent_type": args[0],
|
| 52 |
+
"max_steps": args[1],
|
| 53 |
+
"max_actions_per_step": args[2],
|
| 54 |
+
"use_vision": args[3],
|
| 55 |
+
"tool_call_in_content": args[4],
|
| 56 |
+
"llm_provider": args[5],
|
| 57 |
+
"llm_model_name": args[6],
|
| 58 |
+
"llm_temperature": args[7],
|
| 59 |
+
"llm_base_url": args[8],
|
| 60 |
+
"llm_api_key": args[9],
|
| 61 |
+
"use_own_browser": args[10],
|
| 62 |
+
"keep_browser_open": args[11],
|
| 63 |
+
"headless": args[12],
|
| 64 |
+
"disable_security": args[13],
|
| 65 |
+
"enable_recording": args[14],
|
| 66 |
+
"window_w": args[15],
|
| 67 |
+
"window_h": args[16],
|
| 68 |
+
"save_recording_path": args[17],
|
| 69 |
+
"save_trace_path": args[18],
|
| 70 |
+
"save_agent_history_path": args[19],
|
| 71 |
+
"task": args[20],
|
| 72 |
+
}
|
| 73 |
+
return save_config_to_file(current_config)
|
| 74 |
+
|
| 75 |
+
def update_ui_from_config(config_file):
|
| 76 |
+
if config_file is not None:
|
| 77 |
+
loaded_config = load_config_from_file(config_file.name)
|
| 78 |
+
if isinstance(loaded_config, dict):
|
| 79 |
+
return (
|
| 80 |
+
gr.update(value=loaded_config.get("agent_type", "custom")),
|
| 81 |
+
gr.update(value=loaded_config.get("max_steps", 100)),
|
| 82 |
+
gr.update(value=loaded_config.get("max_actions_per_step", 10)),
|
| 83 |
+
gr.update(value=loaded_config.get("use_vision", True)),
|
| 84 |
+
gr.update(value=loaded_config.get("tool_call_in_content", True)),
|
| 85 |
+
gr.update(value=loaded_config.get("llm_provider", "openai")),
|
| 86 |
+
gr.update(value=loaded_config.get("llm_model_name", "gpt-4o")),
|
| 87 |
+
gr.update(value=loaded_config.get("llm_temperature", 1.0)),
|
| 88 |
+
gr.update(value=loaded_config.get("llm_base_url", "")),
|
| 89 |
+
gr.update(value=loaded_config.get("llm_api_key", "")),
|
| 90 |
+
gr.update(value=loaded_config.get("use_own_browser", False)),
|
| 91 |
+
gr.update(value=loaded_config.get("keep_browser_open", False)),
|
| 92 |
+
gr.update(value=loaded_config.get("headless", False)),
|
| 93 |
+
gr.update(value=loaded_config.get("disable_security", True)),
|
| 94 |
+
gr.update(value=loaded_config.get("enable_recording", True)),
|
| 95 |
+
gr.update(value=loaded_config.get("window_w", 1280)),
|
| 96 |
+
gr.update(value=loaded_config.get("window_h", 1100)),
|
| 97 |
+
gr.update(value=loaded_config.get("save_recording_path", "./tmp/record_videos")),
|
| 98 |
+
gr.update(value=loaded_config.get("save_trace_path", "./tmp/traces")),
|
| 99 |
+
gr.update(value=loaded_config.get("save_agent_history_path", "./tmp/agent_history")),
|
| 100 |
+
gr.update(value=loaded_config.get("task", "")),
|
| 101 |
+
"Configuration loaded successfully."
|
| 102 |
+
)
|
| 103 |
+
else:
|
| 104 |
+
return (
|
| 105 |
+
gr.update(), gr.update(), gr.update(), gr.update(), gr.update(),
|
| 106 |
+
gr.update(), gr.update(), gr.update(), gr.update(), gr.update(),
|
| 107 |
+
gr.update(), gr.update(), gr.update(), gr.update(), gr.update(),
|
| 108 |
+
gr.update(), gr.update(), gr.update(), gr.update(), gr.update(),
|
| 109 |
+
gr.update(), "Error: Invalid configuration file."
|
| 110 |
+
)
|
| 111 |
+
return (
|
| 112 |
+
gr.update(), gr.update(), gr.update(), gr.update(), gr.update(),
|
| 113 |
+
gr.update(), gr.update(), gr.update(), gr.update(), gr.update(),
|
| 114 |
+
gr.update(), gr.update(), gr.update(), gr.update(), gr.update(),
|
| 115 |
+
gr.update(), gr.update(), gr.update(), gr.update(), gr.update(),
|
| 116 |
+
gr.update(), "No file selected."
|
| 117 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|