Skip to content

Commit 5accec3

Browse files
authored
feat: add extra_eval config and import_class for custom evaluators (#1097)
* feat: add extra_eval config and import_class for custom evaluators * lint * build: update litellm requirement to >=1.73 for get_valid_models * refactor: remove *args/**kwargs from _create_embedding_inner_function signature
1 parent 152a70f commit 5accec3

File tree

6 files changed

+21
-12
lines changed

6 files changed

+21
-12
lines changed

rdagent/components/coder/data_science/conf.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ class Config:
2323
env_type: str = "docker"
2424
# TODO: extract a function for env and conf.
2525

26+
extra_eval: list[str] = []
27+
"""
28+
Extra evaluators
29+
30+
The evaluator follows the following assumptions:
31+
- It runs after previous evaluator (So the running results are alreadly there)
32+
33+
It is not a complete feature due to it is only implemented in DS Pipeline & Coder.
34+
35+
TODO: The complete version should be implemented in the CoSTEERSettings.
36+
"""
37+
2638

2739
def get_ds_env(
2840
conf_type: Literal["kaggle", "mlebench"] = "kaggle",

rdagent/components/coder/data_science/pipeline/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from rdagent.core.exception import CoderError
4444
from rdagent.core.experiment import FBWorkspace
4545
from rdagent.core.scenario import Scenario
46+
from rdagent.core.utils import import_class
4647
from rdagent.oai.llm_utils import APIBackend
4748
from rdagent.utils.agent.ret import PythonAgentOut
4849
from rdagent.utils.agent.tpl import T
@@ -143,6 +144,10 @@ def __init__(
143144
if DS_RD_SETTING.enable_model_dump:
144145
eval_l.append(ModelDumpEvaluator(scen=scen, data_type="sample"))
145146

147+
for extra_eval in DSCoderCoSTEERSettings().extra_eval:
148+
kls = import_class(extra_eval)
149+
eval_l.append(kls(scen=scen))
150+
146151
eva = CoSTEERMultiEvaluator(
147152
single_evaluator=eval_l, scen=scen
148153
) # Please specify whether you agree running your eva in parallel or not

rdagent/oai/backend/base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,7 @@ def _calculate_token_from_messages(self, messages: list[dict[str, Any]]) -> int:
654654
raise NotImplementedError("Subclasses must implement this method")
655655

656656
@abstractmethod
657-
def _create_embedding_inner_function( # type: ignore[no-untyped-def]
658-
self, input_content_list: list[str], *args, **kwargs
659-
) -> list[list[float]]: # noqa: ARG002
657+
def _create_embedding_inner_function(self, input_content_list: list[str]) -> list[list[float]]:
660658
"""
661659
Call the embedding function
662660
"""

rdagent/oai/backend/deprec.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,7 @@ def supports_response_schema(self) -> bool:
269269
"""
270270
return False
271271

272-
def _create_embedding_inner_function( # type: ignore[no-untyped-def]
273-
self, input_content_list: list[str], *args, **kwargs
274-
) -> list[list[float]]: # noqa: ARG002
272+
def _create_embedding_inner_function(self, input_content_list: list[str]) -> list[list[float]]:
275273
content_to_embedding_dict = {}
276274
for sliced_filtered_input_content_list in [
277275
input_content_list[i : i + LLM_SETTINGS.embedding_max_str_num]

rdagent/oai/backend/litellm.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ def _calculate_token_from_messages(self, messages: list[dict[str, Any]]) -> int:
6666
logger.info(f"{LogColors.CYAN}Token count: {LogColors.END} {num_tokens}", tag="debug_litellm_token")
6767
return num_tokens
6868

69-
def _create_embedding_inner_function(
70-
self, input_content_list: list[str], *args: Any, **kwargs: Any
71-
) -> list[list[float]]: # noqa: ARG002
69+
def _create_embedding_inner_function(self, input_content_list: list[str]) -> list[list[float]]:
7270
"""
7371
Call the embedding function
7472
"""
@@ -82,8 +80,6 @@ def _create_embedding_inner_function(
8280
response = embedding(
8381
model=model_name,
8482
input=input_content_list,
85-
*args,
86-
**kwargs,
8783
)
8884
response_list = [data["embedding"] for data in response.data]
8985
return response_list

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ loguru
88
fire
99
fuzzywuzzy
1010
openai
11-
litellm==1.72.4
11+
litellm>=1.73 # to support `from litellm import get_valid_models`
1212
azure.identity
1313
pyarrow
1414
rich

0 commit comments

Comments
 (0)