Build and run agents you can see, understand and trust.
Python agentchatbotlarge-language-modelsllmllm-agentmcpmulti-agentmulti-modalreact-agentrealtime-agentvoice-agentvoice-assistant
[HOTFIX] Lazy import the Ray library in evaluator (#781)
ZiTao-Lif40cf8e0df25
diff --git a/src/agentscope/evaluate/_evaluator/_ray_evaluator.py b/src/agentscope/evaluate/_evaluator/_ray_evaluator.pyindex 1b7b86530..7920bf0ef 100644--- a/src/agentscope/evaluate/_evaluator/_ray_evaluator.py+++ b/src/agentscope/evaluate/_evaluator/_ray_evaluator.py@@ -3,11 +3,6 @@import asynciofrom typing import Callable, Awaitable, Coroutine, Any-try:- import ray-except ImportError:- ray = None-from .._benchmark_base import BenchmarkBasefrom .._evaluator._evaluator_base import EvaluatorBasefrom .._solution import SolutionOutput@@ -15,7 +10,31 @@ from .._task import Taskfrom .._evaluator_storage import EvaluatorStorageBase+def _check_ray_available() -> None:+ """Check if ray is available and raise ImportError if not."""+ try:+ import ray # noqa # pylint: disable=unused-import+ except ImportError as e:+ raise ImportError(+ "Ray is not installed. Please install it with `pip install ray` "+ "to use the RayEvaluator.",+ ) from e+++# Create a conditional decorator for ray.remote+def _ray_remote_decorator(cls: Any) -> Any:+ """+ Conditional ray.remote decorator that only applies when ray is available.+ """+ try:+ import ray++ return ray.remote(cls)+ except ImportError:+ return cls+++@_ray_remote_decoratorclass RayEvaluationActor:"""Actor class for running evaluation with ray remote.@@ -47,7 +66,7 @@ class RayEvaluationActor:)+@_ray_remote_decoratorclass RaySolutionActor:"""Actor class for running agent solutions with ray remote.@@ -141,6 +160,9 @@ class RayEvaluator(EvaluatorBase):storage=storage,)+ # Check ray availability early+ _check_ray_available()+assert isinstance(benchmark, BenchmarkBase)assert n_repeat >= 1, "n_repeat must be at least 1"