Files
deer-flow/src/config/loader.py
CHANGXUBO dd9af1eb50 feat: Implement Milvus retriver for RAG (#516)
* feat: Implement MilvusRetriever with embedding model and resource management

* chore: Update configuration and loader files for consistency

* chore: Clean up test_milvus.py for improved readability and organization

* feat: Add tests for DashscopeEmbeddings query and document embedding methods

* feat: Add tests for embedding model initialization and example file loading in MilvusProvider

* chore: Remove unused imports and clean up test_milvus.py for better readability

* chore: Clean up test_milvus.py for improved readability and organization

* chore: Clean up test_milvus.py for improved readability and organization

* fix: replace print statements with logging in recursion limit function

* Implement feature X to enhance user experience and optimize performance

* refactor: clean up unused imports and comments in AboutTab component

* Implement feature X to enhance user experience and fix bug Y in module Z

---------

Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2025-09-12 22:20:55 +08:00

79 lines
2.1 KiB
Python

# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
# SPDX-License-Identifier: MIT
import os
from typing import Any, Dict
import yaml
def get_bool_env(name: str, default: bool = False) -> bool:
val = os.getenv(name)
if val is None:
return default
return str(val).strip().lower() in {"1", "true", "yes", "y", "on"}
def get_str_env(name: str, default: str = "") -> str:
val = os.getenv(name)
return default if val is None else str(val).strip()
def get_int_env(name: str, default: int = 0) -> int:
val = os.getenv(name)
if val is None:
return default
try:
return int(val.strip())
except ValueError:
print(f"Invalid integer value for {name}: {val}. Using default {default}.")
return default
def replace_env_vars(value: str) -> str:
"""Replace environment variables in string values."""
if not isinstance(value, str):
return value
if value.startswith("$"):
env_var = value[1:]
return os.getenv(env_var, env_var)
return value
def process_dict(config: Dict[str, Any]) -> Dict[str, Any]:
"""Recursively process dictionary to replace environment variables."""
if not config:
return {}
result = {}
for key, value in config.items():
if isinstance(value, dict):
result[key] = process_dict(value)
elif isinstance(value, str):
result[key] = replace_env_vars(value)
else:
result[key] = value
return result
_config_cache: Dict[str, Dict[str, Any]] = {}
def load_yaml_config(file_path: str) -> Dict[str, Any]:
"""Load and process YAML configuration file."""
# 如果文件不存在,返回{}
if not os.path.exists(file_path):
return {}
# 检查缓存中是否已存在配置
if file_path in _config_cache:
return _config_cache[file_path]
# 如果缓存中不存在,则加载并处理配置
with open(file_path, "r") as f:
config = yaml.safe_load(f)
processed_config = process_dict(config)
# 将处理后的配置存入缓存
_config_cache[file_path] = processed_config
return processed_config