diff --git a/rdagent/components/coder/factor_coder/CoSTEER/evaluators.py b/rdagent/components/coder/factor_coder/CoSTEER/evaluators.py index ccd08b456..ef480b4b1 100644 --- a/rdagent/components/coder/factor_coder/CoSTEER/evaluators.py +++ b/rdagent/components/coder/factor_coder/CoSTEER/evaluators.py @@ -505,6 +505,7 @@ def evaluate( user_prompt=user_prompt, system_prompt=system_prompt, json_mode=True, + seed=attempts, # in case of useless retrying when cache enabled. ), ) final_decision = final_evaluation_dict["final_decision"] diff --git a/rdagent/components/coder/factor_coder/factor.py b/rdagent/components/coder/factor_coder/factor.py index f794e4c1f..95c0b53d3 100644 --- a/rdagent/components/coder/factor_coder/factor.py +++ b/rdagent/components/coder/factor_coder/factor.py @@ -89,7 +89,7 @@ def __init__( @staticmethod def link_data_to_workspace(data_path: Path, workspace_path: Path): - data_path = Path(data_path) + data_path = Path(data_path).absolute() # in case of relative path that will be invalid when we change cwd. workspace_path = Path(workspace_path) for data_file_path in data_path.iterdir(): workspace_data_file_path = workspace_path / data_file_path.name diff --git a/rdagent/oai/llm_utils.py b/rdagent/oai/llm_utils.py index 427ff0ab5..8cf410b61 100644 --- a/rdagent/oai/llm_utils.py +++ b/rdagent/oai/llm_utils.py @@ -13,7 +13,7 @@ import uuid from copy import deepcopy from pathlib import Path -from typing import Any +from typing import Any, Optional import numpy as np import tiktoken @@ -401,7 +401,10 @@ def build_messages( *, shrink_multiple_break: bool = False, ) -> list[dict]: - """build the messages to avoid implementing several redundant lines of code""" + """ + build the messages to avoid implementing several redundant lines of code + + """ if former_messages is None: former_messages = [] # shrink multiple break will recursively remove multiple breaks(more than 2) @@ -440,7 +443,10 @@ def build_messages_and_create_chat_completion( if former_messages is None: former_messages = [] messages = self.build_messages( - user_prompt, system_prompt, former_messages, shrink_multiple_break=shrink_multiple_break + user_prompt, + system_prompt, + former_messages, + shrink_multiple_break=shrink_multiple_break, ) return self._try_create_chat_completion_or_embedding( messages=messages, @@ -567,14 +573,21 @@ def _create_chat_completion_inner_function( # noqa: C901, PLR0912, PLR0915 *, json_mode: bool = False, add_json_in_prompt: bool = False, + seed: Optional[int] = None, ) -> str: + """ + seed : Optional[int] + When retrying with cache enabled, it will keep returning the same results. + To make retries useful, we need to enable a seed. + This seed is different from `self.chat_seed` for GPT. It is for the local cache mechanism enabled by RD-Agent locally. + """ # TODO: we can add this function back to avoid so much `self.cfg.log_llm_chat_content` if self.cfg.log_llm_chat_content: logger.info(self._build_log_messages(messages), tag="llm_messages") # TODO: fail to use loguru adaptor due to stream response input_content_json = json.dumps(messages) input_content_json = ( - chat_cache_prefix + input_content_json + chat_cache_prefix + input_content_json + f"" ) # FIXME this is a hack to make sure the cache represents the round index if self.use_chat_cache: cache_result = self.cache.chat_get(input_content_json)