mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-30 01:04:48 +08:00
chore: use ruff to lint and auto-format
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from langchain.agents import create_agent
|
||||
|
||||
from src.agents.lead_agent.prompt import apply_prompt_template
|
||||
from src.models import create_chat_model
|
||||
from src.tools import get_available_tools
|
||||
|
||||
@@ -71,7 +71,4 @@ All temporary work happens in `{MOUNT_POINT}/user-data/workspace`. Final deliver
|
||||
|
||||
|
||||
def apply_prompt_template() -> str:
|
||||
return (
|
||||
SYSTEM_PROMPT
|
||||
+ f"\n<current_date>{datetime.now().strftime("%Y-%m-%d, %A")}</current_date>"
|
||||
)
|
||||
return SYSTEM_PROMPT + f"\n<current_date>{datetime.now().strftime('%Y-%m-%d, %A')}</current_date>"
|
||||
|
||||
@@ -13,14 +13,10 @@ from src.config.tool_config import ToolConfig, ToolGroupConfig
|
||||
class AppConfig(BaseModel):
|
||||
"""Config for the DeerFlow application"""
|
||||
|
||||
models: list[ModelConfig] = Field(
|
||||
default_factory=list, description="Available models"
|
||||
)
|
||||
models: list[ModelConfig] = Field(default_factory=list, description="Available models")
|
||||
sandbox: SandboxConfig = Field(description="Sandbox configuration")
|
||||
tools: list[ToolConfig] = Field(default_factory=list, description="Available tools")
|
||||
tool_groups: list[ToolGroupConfig] = Field(
|
||||
default_factory=list, description="Available tool groups"
|
||||
)
|
||||
tool_groups: list[ToolGroupConfig] = Field(default_factory=list, description="Available tool groups")
|
||||
model_config = ConfigDict(extra="allow", frozen=False)
|
||||
|
||||
@classmethod
|
||||
@@ -35,16 +31,12 @@ class AppConfig(BaseModel):
|
||||
if config_path:
|
||||
path = Path(config_path)
|
||||
if not Path.exists(path):
|
||||
raise FileNotFoundError(
|
||||
f"Config file specified by param `config_path` not found at {path}"
|
||||
)
|
||||
raise FileNotFoundError(f"Config file specified by param `config_path` not found at {path}")
|
||||
return path
|
||||
elif os.getenv("DEER_FLOW_CONFIG_PATH"):
|
||||
path = Path(os.getenv("DEER_FLOW_CONFIG_PATH"))
|
||||
if not Path.exists(path):
|
||||
raise FileNotFoundError(
|
||||
f"Config file specified by environment variable `DEER_FLOW_CONFIG_PATH` not found at {path}"
|
||||
)
|
||||
raise FileNotFoundError(f"Config file specified by environment variable `DEER_FLOW_CONFIG_PATH` not found at {path}")
|
||||
return path
|
||||
else:
|
||||
# Check if the config.yaml is in the parent directory of CWD
|
||||
@@ -66,7 +58,7 @@ class AppConfig(BaseModel):
|
||||
AppConfig: The loaded config.
|
||||
"""
|
||||
resolved_path = cls.resolve_config_path(config_path)
|
||||
with open(resolved_path, "r") as f:
|
||||
with open(resolved_path) as f:
|
||||
config_data = yaml.safe_load(f)
|
||||
cls.resolve_env_variables(config_data)
|
||||
result = cls.model_validate(config_data)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
from importlib import import_module
|
||||
from typing import Type, TypeVar
|
||||
from typing import TypeVar
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
def resolve_variable[T](
|
||||
variable_path: str,
|
||||
expected_type: Type[T] | tuple[Type, ...] | None = None,
|
||||
expected_type: type[T] | tuple[type, ...] | None = None,
|
||||
) -> T:
|
||||
"""Resolve a variable from a path.
|
||||
|
||||
@@ -25,9 +25,7 @@ def resolve_variable[T](
|
||||
try:
|
||||
module_path, variable_name = variable_path.rsplit(":", 1)
|
||||
except ValueError as err:
|
||||
raise ImportError(
|
||||
f"{variable_path} doesn't look like a variable path. Example: parent_package_name.sub_package_name.module_name:variable_name"
|
||||
) from err
|
||||
raise ImportError(f"{variable_path} doesn't look like a variable path. Example: parent_package_name.sub_package_name.module_name:variable_name") from err
|
||||
|
||||
try:
|
||||
module = import_module(module_path)
|
||||
@@ -37,26 +35,18 @@ def resolve_variable[T](
|
||||
try:
|
||||
variable = getattr(module, variable_name)
|
||||
except AttributeError as err:
|
||||
raise ImportError(
|
||||
f"Module {module_path} does not define a {variable_name} attribute/class"
|
||||
) from err
|
||||
raise ImportError(f"Module {module_path} does not define a {variable_name} attribute/class") from err
|
||||
|
||||
# Type validation
|
||||
if expected_type is not None:
|
||||
if not isinstance(variable, expected_type):
|
||||
type_name = (
|
||||
expected_type.__name__
|
||||
if isinstance(expected_type, type)
|
||||
else " or ".join(t.__name__ for t in expected_type)
|
||||
)
|
||||
raise ValueError(
|
||||
f"{variable_path} is not an instance of {type_name}, got {type(variable).__name__}"
|
||||
)
|
||||
type_name = expected_type.__name__ if isinstance(expected_type, type) else " or ".join(t.__name__ for t in expected_type)
|
||||
raise ValueError(f"{variable_path} is not an instance of {type_name}, got {type(variable).__name__}")
|
||||
|
||||
return variable
|
||||
|
||||
|
||||
def resolve_class(class_path: str, base_class: Type[T] | None = None) -> Type[T]:
|
||||
def resolve_class[T](class_path: str, base_class: type[T] | None = None) -> type[T]:
|
||||
"""Resolve a class from a module path and class name.
|
||||
|
||||
Args:
|
||||
|
||||
@@ -29,7 +29,7 @@ class LocalSandbox(Sandbox):
|
||||
return list_dir(path, max_depth)
|
||||
|
||||
def read_file(self, path: str) -> str:
|
||||
with open(path, "r") as f:
|
||||
with open(path) as f:
|
||||
return f.read()
|
||||
|
||||
def write_file(self, path: str, content: str, append: bool = False) -> None:
|
||||
|
||||
Reference in New Issue
Block a user