diff --git a/rdagent/core/conf.py b/rdagent/core/conf.py index 04d97f788..9f57d32dd 100644 --- a/rdagent/core/conf.py +++ b/rdagent/core/conf.py @@ -15,16 +15,6 @@ class RDAgentSettings(BaseSettings): # TODO: (xiao) think it can be a separate config. log_trace_path: str | None = None - # Behavior of returning answers to the same question when caching is enabled - use_auto_chat_cache_seed_gen: bool = False - """ - `_create_chat_completion_inner_function` provdies a feature to pass in a seed to affect the cache hash key - We want to enable a auto seed generator to get different default seed for `_create_chat_completion_inner_function` - if seed is not given. - So the cache will only not miss you ask the same question on same round. - """ - init_chat_cache_seed: int = 42 - # azure document intelligence configs azure_document_intelligence_key: str = "" azure_document_intelligence_endpoint: str = "" diff --git a/rdagent/core/utils.py b/rdagent/core/utils.py index f22904b0a..3967f5070 100644 --- a/rdagent/core/utils.py +++ b/rdagent/core/utils.py @@ -14,6 +14,7 @@ from fuzzywuzzy import fuzz # type: ignore[import-untyped] from rdagent.core.conf import RD_AGENT_SETTINGS +from rdagent.oai.llm_conf import LLM_SETTINGS class RDAgentException(Exception): # noqa: N818 @@ -98,7 +99,7 @@ class CacheSeedGen: """ def __init__(self) -> None: - self.set_seed(RD_AGENT_SETTINGS.init_chat_cache_seed) + self.set_seed(LLM_SETTINGS.init_chat_cache_seed) def set_seed(self, seed: int) -> None: random.seed(seed) diff --git a/rdagent/oai/llm_conf.py b/rdagent/oai/llm_conf.py index 8244a921e..ce40135d3 100644 --- a/rdagent/oai/llm_conf.py +++ b/rdagent/oai/llm_conf.py @@ -20,6 +20,16 @@ class LLMSettings(BaseSettings): prompt_cache_path: str = str(Path.cwd() / "prompt_cache.db") max_past_message_include: int = 10 + # Behavior of returning answers to the same question when caching is enabled + use_auto_chat_cache_seed_gen: bool = False + """ + `_create_chat_completion_inner_function` provdies a feature to pass in a seed to affect the cache hash key + We want to enable a auto seed generator to get different default seed for `_create_chat_completion_inner_function` + if seed is not given. + So the cache will only not miss you ask the same question on same round. + """ + init_chat_cache_seed: int = 42 + # Chat configs openai_api_key: str = "" # TODO: simplify the key design. chat_openai_api_key: str = "" diff --git a/rdagent/oai/llm_utils.py b/rdagent/oai/llm_utils.py index 3b73f41b3..921a5b5eb 100644 --- a/rdagent/oai/llm_utils.py +++ b/rdagent/oai/llm_utils.py @@ -17,7 +17,6 @@ import numpy as np import tiktoken -from rdagent.core.conf import RD_AGENT_SETTINGS from rdagent.core.utils import LLM_CACHE_SEED_GEN, SingletonBaseClass from rdagent.log import LogColors from rdagent.log import rdagent_logger as logger @@ -596,7 +595,7 @@ def _create_chat_completion_inner_function( # noqa: C901, PLR0912, PLR0915 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. """ - if seed is None and RD_AGENT_SETTINGS.use_auto_chat_cache_seed_gen: + if seed is None and LLM_SETTINGS.use_auto_chat_cache_seed_gen: seed = LLM_CACHE_SEED_GEN.get_next_seed() # TODO: we can add this function back to avoid so much `self.cfg.log_llm_chat_content` diff --git a/test/oai/test_completion.py b/test/oai/test_completion.py index fce5cc3f5..3b60f0f9b 100644 --- a/test/oai/test_completion.py +++ b/test/oai/test_completion.py @@ -60,7 +60,6 @@ def test_chat_cache(self) -> None: - 2 pass - cache is not missed & same question get different answer. """ - from rdagent.core.conf import RD_AGENT_SETTINGS from rdagent.core.utils import LLM_CACHE_SEED_GEN from rdagent.oai.llm_conf import LLM_SETTINGS @@ -68,7 +67,7 @@ def test_chat_cache(self) -> None: user_prompt = f"Give me {2} random country names, list {2} cities in each country, and introduce them" origin_value = ( - RD_AGENT_SETTINGS.use_auto_chat_cache_seed_gen, + LLM_SETTINGS.use_auto_chat_cache_seed_gen, LLM_SETTINGS.use_chat_cache, LLM_SETTINGS.dump_chat_cache, ) @@ -76,7 +75,7 @@ def test_chat_cache(self) -> None: LLM_SETTINGS.use_chat_cache = True LLM_SETTINGS.dump_chat_cache = True - RD_AGENT_SETTINGS.use_auto_chat_cache_seed_gen = True + LLM_SETTINGS.use_auto_chat_cache_seed_gen = True LLM_CACHE_SEED_GEN.set_seed(10) response1 = APIBackend().build_messages_and_create_chat_completion( @@ -110,7 +109,7 @@ def test_chat_cache(self) -> None: # Reset, for other tests ( - RD_AGENT_SETTINGS.use_auto_chat_cache_seed_gen, + LLM_SETTINGS.use_auto_chat_cache_seed_gen, LLM_SETTINGS.use_chat_cache, LLM_SETTINGS.dump_chat_cache, ) = origin_value @@ -132,7 +131,6 @@ def test_chat_cache_multiprocess(self) -> None: - 2 pass - cache is not missed & same question get different answer. """ - from rdagent.core.conf import RD_AGENT_SETTINGS from rdagent.core.utils import LLM_CACHE_SEED_GEN, multiprocessing_wrapper from rdagent.oai.llm_conf import LLM_SETTINGS @@ -140,7 +138,7 @@ def test_chat_cache_multiprocess(self) -> None: user_prompt = f"Give me {2} random country names, list {2} cities in each country, and introduce them" origin_value = ( - RD_AGENT_SETTINGS.use_auto_chat_cache_seed_gen, + LLM_SETTINGS.use_auto_chat_cache_seed_gen, LLM_SETTINGS.use_chat_cache, LLM_SETTINGS.dump_chat_cache, ) @@ -148,7 +146,7 @@ def test_chat_cache_multiprocess(self) -> None: LLM_SETTINGS.use_chat_cache = True LLM_SETTINGS.dump_chat_cache = True - RD_AGENT_SETTINGS.use_auto_chat_cache_seed_gen = True + LLM_SETTINGS.use_auto_chat_cache_seed_gen = True func_calls = [(_worker, (system_prompt, user_prompt)) for _ in range(4)] @@ -161,7 +159,7 @@ def test_chat_cache_multiprocess(self) -> None: # Reset, for other tests ( - RD_AGENT_SETTINGS.use_auto_chat_cache_seed_gen, + LLM_SETTINGS.use_auto_chat_cache_seed_gen, LLM_SETTINGS.use_chat_cache, LLM_SETTINGS.dump_chat_cache, ) = origin_value