From ff9e9a8016674d565360900156dd1d85fd372a9c Mon Sep 17 00:00:00 2001 From: Xuchen Pan <32844285+pan-x-c@users.noreply.github.com> Date: Thu, 29 Aug 2024 16:06:17 +0800 Subject: [PATCH] [HOTFIX] Fix the bug in distribution mode where model configurations are missing (#428) --- src/agentscope/manager/_manager.py | 3 ++- tests/custom/test_model_config.json | 11 +++++++++++ tests/rpc_agent_test.py | 17 +++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 tests/custom/test_model_config.json diff --git a/src/agentscope/manager/_manager.py b/src/agentscope/manager/_manager.py index fdf6e37a5..d9a08f63a 100644 --- a/src/agentscope/manager/_manager.py +++ b/src/agentscope/manager/_manager.py @@ -2,6 +2,7 @@ """A manager for AgentScope.""" import os from typing import Union, Any +from copy import deepcopy from loguru import logger @@ -166,7 +167,7 @@ def state_dict(self) -> dict: serialized_data["studio"] = _studio_client.state_dict() serialized_data["monitor"] = self.monitor.state_dict() - return serialized_data + return deepcopy(serialized_data) def load_dict(self, data: dict) -> None: """Load the runtime information from a dictionary""" diff --git a/tests/custom/test_model_config.json b/tests/custom/test_model_config.json new file mode 100644 index 000000000..5123a729c --- /dev/null +++ b/tests/custom/test_model_config.json @@ -0,0 +1,11 @@ +[ + { + "config_name": "qwen", + "model_type": "dashscope_chat", + "model_name": "qwen-max", + "api_key": "xxx", + "generate_args": { + "temperature": 0.5 + } + } +] \ No newline at end of file diff --git a/tests/rpc_agent_test.py b/tests/rpc_agent_test.py index ab3673124..bda005882 100644 --- a/tests/rpc_agent_test.py +++ b/tests/rpc_agent_test.py @@ -180,6 +180,13 @@ def setUp(self) -> None: agentscope.init( project="test", name="rpc_agent", + model_configs=os.path.abspath( + os.path.join( + os.path.abspath(os.path.dirname(__file__)), + "custom", + "test_model_config.json", + ), + ), save_dir="./.unittest_runs", save_log=True, ) @@ -677,6 +684,16 @@ def test_agent_server_management_funcs(self) -> None: self.assertEqual(remote_content, local_content) agent_lists = client.get_agent_list() self.assertEqual(len(agent_lists), 2) + # test existing model config + DialogAgent( + name="dialogue", + sys_prompt="You are a helful assistant.", + model_config_name="qwen", + to_dist={ + "host": "localhost", + "port": launcher.port, + }, + ) # model not exists error self.assertRaises( Exception,