Agent Zero AI framework
settings .env+json config, logging fix
frdel8a6355aa63cc
diff --git a/python/helpers/settings.py b/python/helpers/settings.pyindex be6571f0e..0b0c154bb 100644--- a/python/helpers/settings.py+++ b/python/helpers/settings.py@@ -12,6 +12,7 @@ from . import files, dotenvfrom python.helpers.print_style import PrintStylefrom python.helpers.providers import get_providersfrom python.helpers.secrets import SecretsManager+from python.helpers import dirty_jsonclass Settings(TypedDict):@@ -20,7 +21,7 @@ class Settings(TypedDict):chat_model_provider: strchat_model_name: strchat_model_api_base: str- chat_model_kwargs: dict[str, str]+ chat_model_kwargs: dict[str, Any]chat_model_ctx_length: intchat_model_ctx_history: floatchat_model_vision: bool@@ -31,7 +32,7 @@ class Settings(TypedDict):util_model_provider: strutil_model_name: strutil_model_api_base: str- util_model_kwargs: dict[str, str]+ util_model_kwargs: dict[str, Any]util_model_ctx_length: intutil_model_ctx_input: floatutil_model_rl_requests: int@@ -41,7 +42,7 @@ class Settings(TypedDict):embed_model_provider: strembed_model_name: strembed_model_api_base: str- embed_model_kwargs: dict[str, str]+ embed_model_kwargs: dict[str, Any]embed_model_rl_requests: intembed_model_rl_input: int@@ -52,8 +53,8 @@ class Settings(TypedDict):browser_model_rl_requests: intbrowser_model_rl_input: intbrowser_model_rl_output: int- browser_model_kwargs: dict[str, str]- browser_http_headers: dict[str, str]+ browser_model_kwargs: dict[str, Any]+ browser_http_headers: dict[str, Any]agent_profile: stragent_memory_subdir: str@@ -108,7 +109,7 @@ class Settings(TypedDict):secrets: str# LiteLLM global kwargs applied to all model calls- litellm_global_kwargs: dict[str, str]+ litellm_global_kwargs: dict[str, Any]class PartialSettings(Settings, total=False):pass@@ -264,7 +265,7 @@ def convert_out(settings: Settings) -> SettingsOutput:{"id": "chat_model_kwargs","title": "Chat model additional parameters",- "description": "Any other parameters supported by <a href='https://docs.litellm.ai/docs/set_keys' target='_blank'>LiteLLM</a>. Format is KEY=VALUE on individual lines, just like .env file.",+ "description": "Any other parameters supported by <a href='https://docs.litellm.ai/docs/set_keys' target='_blank'>LiteLLM</a>. Format is KEY=VALUE on individual lines, like .env file. Value can also contain JSON objects - when unquoted, it is treated as object, number etc., when quoted, it is treated as string.","type": "textarea","value": _dict_to_env(settings["chat_model_kwargs"]),}@@ -344,7 +345,7 @@ def convert_out(settings: Settings) -> SettingsOutput:{"id": "util_model_kwargs","title": "Utility model additional parameters",- "description": "Any other parameters supported by <a href='https://docs.litellm.ai/docs/set_keys' target='_blank'>LiteLLM</a>. Format is KEY=VALUE on individual lines, just like .env file.",+ "description": "Any other parameters supported by <a href='https://docs.litellm.ai/docs/set_keys' target='_blank'>LiteLLM</a>. Format is KEY=VALUE on individual lines, like .env file. Value can also contain JSON objects - when unquoted, it is treated as object, number etc., when quoted, it is treated as string.","type": "textarea","value": _dict_to_env(settings["util_model_kwargs"]),}@@ -414,7 +415,7 @@ def convert_out(settings: Settings) -> SettingsOutput:{"id": "embed_model_kwargs","title": "Embedding model additional parameters",- "description": "Any other parameters supported by <a href='https://docs.litellm.ai/docs/set_keys' target='_blank'>LiteLLM</a>. Format is KEY=VALUE on individual lines, just like .env file.",+ "description": "Any other parameters supported by <a href='https://docs.litellm.ai/docs/set_keys' target='_blank'>LiteLLM</a>. Format is KEY=VALUE on individual lines, like .env file. Value can also contain JSON objects - when unquoted, it is treated as object, number etc., when quoted, it is treated as string.","type": "textarea","value": _dict_to_env(settings["embed_model_kwargs"]),}@@ -504,7 +505,7 @@ def convert_out(settings: Settings) -> SettingsOutput:{"id": "browser_model_kwargs","title": "Web Browser model additional parameters",- "description": "Any other parameters supported by <a href='https://docs.litellm.ai/docs/set_keys' target='_blank'>LiteLLM</a>. Format is KEY=VALUE on individual lines, just like .env file.",+ "description": "Any other parameters supported by <a href='https://docs.litellm.ai/docs/set_keys' target='_blank'>LiteLLM</a>. Format is KEY=VALUE on individual lines, like .env file. Value can also contain JSON objects - when unquoted, it is treated as object, number etc., when quoted, it is treated as string.","type": "textarea","value": _dict_to_env(settings["browser_model_kwargs"]),}@@ -514,7 +515,7 @@ def convert_out(settings: Settings) -> SettingsOutput:{"id": "browser_http_headers","title": "HTTP Headers",- "description": "HTTP headers to include with all browser requests. Format is KEY=VALUE on individual lines, just like .env file. Example: Authorization=Bearer token123",+ "description": "HTTP headers to include with all browser requests. Format is KEY=VALUE on individual lines, like .env file. Value can also contain JSON objects - when unquoted, it is treated as object, number etc., when quoted, it is treated as string. Example: Authorization=Bearer token123","type": "textarea","value": _dict_to_env(settings.get("browser_http_headers", {})),}@@ -1603,26 +1604,48 @@ def _apply_settings(previous: Settings | None):def _env_to_dict(data: str):- env_dict = {}- line_pattern = re.compile(r"\s*([^#][^=]*)\s*=\s*(.*)")+ result = {}for line in data.splitlines():- match = line_pattern.match(line)- if match:- key, value = match.groups()- # Remove optional surrounding quotes (single or double)- value = value.strip().strip('"').strip("'")- env_dict[key.strip()] = value- return env_dict+ line = line.strip()+ if not line or line.startswith('#'):+ continue++ if '=' not in line:+ continue++ key, value = line.split('=', 1)+ key = key.strip()+ value = value.strip()++ # If quoted, treat as string+ if value.startswith('"') and value.endswith('"'):+ result[key] = value[1:-1].replace('\\"', '"') # Unescape quotes+ elif value.startswith("'") and value.endswith("'"):+ result[key] = value[1:-1].replace("\\'", "'") # Unescape quotes+ else:+ # Not quoted, try JSON parse+ try:+ result[key] = json.loads(value)+ except (json.JSONDecodeError, ValueError):+ result[key] = value++ return resultdef _dict_to_env(data_dict):lines = []for key, value in data_dict.items():- if "\n" in value:- value = f"'{value}'"- elif " " in value or value == "" or any(c in value for c in "\"'"):- value = f'"{value}"'- lines.append(f"{key}={value}")+ if isinstance(value, str):+ # Quote strings and escape internal quotes+ escaped_value = value.replace('"', '\\"')+ lines.append(f'{key}="{escaped_value}"')+ elif isinstance(value, (dict, list, bool)) or value is None:+ # Serialize as unquoted JSON+ lines.append(f'{key}={json.dumps(value, separators=(",", ":"))}')+ else:+ # Numbers and other types as unquoted strings+ lines.append(f'{key}={value}')+return "\n".join(lines)diff --git a/requirements.txt b/requirements.txtindex b2b8e2fd2..17856f8b7 100644--- a/requirements.txt+++ b/requirements.txt@@ -33,7 +33,7 @@ unstructured-client==0.31.0webcolors==24.6.0nest-asyncio==1.6.0crontab==1.0.1-litellm==1.75.3+litellm==1.75.0markdownify==1.1.0pymupdf==1.25.3pytesseract==0.3.13diff --git a/run_ui.py b/run_ui.pyindex 42b87cfa8..442feee2d 100644--- a/run_ui.py+++ b/run_ui.py@@ -16,6 +16,10 @@ from python.helpers.extract_tools import load_classes_from_folderfrom python.helpers.api import ApiHandlerfrom python.helpers.print_style import PrintStyle+# disable logging+import logging+logging.getLogger().setLevel(logging.WARNING)+# Set the new timezone to 'UTC'os.environ["TZ"] = "UTC"