🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
feat: set structured output from ChatAgent using openai beta client (#1206)
Wendong-Fand9fec49ac9ab
diff --git a/camel/agents/chat_agent.py b/camel/agents/chat_agent.pyindex 78ec45685..ddbf0233a 100644--- a/camel/agents/chat_agent.py+++ b/camel/agents/chat_agent.py@@ -499,6 +499,13 @@ class ChatAgent(BaseAgent):"the model configuration and in the ChatAgent step.")+ original_model_dict = self.model_backend.model_config_dict+ if response_format and self.model_type in {"gpt-4o", "gpt-4o-mini"}:+ self.model_backend.model_config_dict = original_model_dict.copy()+ self.model_backend.model_config_dict["response_format"] = (+ response_format+ )+if isinstance(input_message, str):input_message = BaseMessage.make_user_message(role_name='User', content=input_message@@ -632,6 +639,7 @@ class ChatAgent(BaseAgent):try:openai_messages, num_tokens = self.memory.get_context()except RuntimeError as e:+ self.model_backend.model_config_dict = original_model_dictreturn self._step_token_exceed(e.args[1], tool_call_records, "max_tokens_exceeded")@@ -667,6 +675,8 @@ class ChatAgent(BaseAgent):num_tokens,tool_call_request,)++ self.model_backend.model_config_dict = original_model_dictreturn ChatAgentResponse(msgs=output_messages,terminated=self.terminated,@@ -681,6 +691,7 @@ class ChatAgent(BaseAgent):if (response_format is not Noneand self.model_type.support_native_tool_calling+ and self.model_type not in {"gpt-4o", "gpt-4o-mini"}):(output_messages,@@ -711,6 +722,7 @@ class ChatAgent(BaseAgent):"to record the selected message manually.")+ self.model_backend.model_config_dict = original_model_dictreturn ChatAgentResponse(msgs=output_messages, terminated=self.terminated, info=info)@@ -930,7 +942,7 @@ class ChatAgent(BaseAgent):)for base_message_item in output_messages:- base_message_item.content = str(tool_call_record.result)+ base_message_item.content = json.dumps(tool_call_record.result)# Recover the original toolsself.func_dict = original_func_dictdiff --git a/camel/personas/persona_hub.py b/camel/personas/persona_hub.pyindex d282d8a27..bcacd67dc 100644--- a/camel/personas/persona_hub.py+++ b/camel/personas/persona_hub.py@@ -11,7 +11,7 @@# See the License for the specific language governing permissions and# limitations under the License.# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========-import ast+import jsonimport reimport uuidfrom functools import lru_cache@@ -130,7 +130,7 @@ class PersonaHub:text_to_persona_prompt_instruction,response_format=PersonaResponse, # type: ignore[arg-type])- parsed_content = ast.literal_eval(response.msg.content)+ parsed_content = json.loads(response.msg.content)persona.name = parsed_content["persona_name"]persona.description = parsed_content["persona_description"]except Exception as e:diff --git a/camel/societies/workforce/role_playing_worker.py b/camel/societies/workforce/role_playing_worker.pyindex 5040848a7..4d50bbf7f 100644--- a/camel/societies/workforce/role_playing_worker.py+++ b/camel/societies/workforce/role_playing_worker.py@@ -13,7 +13,7 @@# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========from __future__ import annotations-import ast+import jsonfrom typing import Dict, List, Optionalfrom colorama import Fore@@ -173,7 +173,7 @@ class RolePlayingWorker(Worker):content=prompt,)response = self.summarize_agent.step(req, response_format=TaskResult)- result_dict = ast.literal_eval(response.msg.content)+ result_dict = json.loads(response.msg.content)task_result = TaskResult(**result_dict)task.result = task_result.contentdiff --git a/camel/societies/workforce/single_agent_worker.py b/camel/societies/workforce/single_agent_worker.pyindex 3ab102d32..1cae7618e 100644--- a/camel/societies/workforce/single_agent_worker.py+++ b/camel/societies/workforce/single_agent_worker.py@@ -13,7 +13,7 @@# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========from __future__ import annotations-import ast+import jsonfrom typing import Any, Listfrom colorama import Fore@@ -87,7 +87,7 @@ class SingleAgentWorker(Worker):print(f"======\n{Fore.GREEN}Reply from {self}:{Fore.RESET}")- result_dict = ast.literal_eval(response.msg.content)+ result_dict = json.loads(response.msg.content)task_result = TaskResult(**result_dict)color = Fore.RED if task_result.failed else Fore.GREENdiff --git a/camel/societies/workforce/workforce.py b/camel/societies/workforce/workforce.pyindex ec7c6764e..1c283caa0 100644--- a/camel/societies/workforce/workforce.py+++ b/camel/societies/workforce/workforce.py@@ -13,8 +13,8 @@# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========from __future__ import annotations-import astimport asyncio+import jsonimport loggingfrom collections import dequefrom typing import Deque, Dict, List, Optional@@ -289,7 +289,7 @@ class Workforce(BaseNode):response = self.coordinator_agent.step(req, response_format=TaskAssignResult)- result_dict = ast.literal_eval(response.msg.content)+ result_dict = json.loads(response.msg.content)task_assign_result = TaskAssignResult(**result_dict)return task_assign_result.assignee_id@@ -320,7 +320,7 @@ class Workforce(BaseNode):content=prompt,)response = self.coordinator_agent.step(req, response_format=WorkerConf)- result_dict = ast.literal_eval(response.msg.content)+ result_dict = json.loads(response.msg.content)new_node_conf = WorkerConf(**result_dict)new_agent = self._create_new_agent(diff --git a/camel/toolkits/function_tool.py b/camel/toolkits/function_tool.pyindex ef123cbac..aad14cdd7 100644--- a/camel/toolkits/function_tool.py+++ b/camel/toolkits/function_tool.py@@ -165,9 +165,15 @@ def get_openai_tool_schema(func: Callable) -> Dict[str, Any]:else:func_description = short_description+ # OpenAI client.beta.chat.completions.parse for structured output has+ # additional requirements for the schema, refer:+ # https://platform.openai.com/docs/guides/structured-outputs/some-type-specific-keywords-are-not-yet-supported#supported-schemas+ parameters_dict["additionalProperties"] = False+openai_function_schema = {"name": func.__name__,"description": func_description,+ "strict": True,"parameters": parameters_dict,}@@ -175,9 +181,44 @@ def get_openai_tool_schema(func: Callable) -> Dict[str, Any]:"type": "function","function": openai_function_schema,}++ openai_tool_schema = sanitize_and_enforce_required(openai_tool_schema)return openai_tool_schema+def sanitize_and_enforce_required(parameters_dict):+ r"""Cleans and updates the function schema to conform with OpenAI's+ requirements:+ - Removes invalid 'default' fields from the parameters schema.+ - Ensures all fields or function parameters are marked as required.++ Args:+ parameters_dict (dict): The dictionary representing the function+ schema.++ Returns:+ dict: The updated dictionary with invalid defaults removed and all+ fields set as required.+ """+ # Check if 'function' and 'parameters' exist+ if (+ 'function' in parameters_dict+ and 'parameters' in parameters_dict['function']+ ):+ # Access the 'parameters' section+ parameters = parameters_dict['function']['parameters']+ properties = parameters.get('properties', {})++ # Remove 'default' key from each property+ for field in properties.values():+ field.pop('default', None)++ # Mark all keys in 'properties' as required+ parameters['required'] = list(properties.keys())++ return parameters_dict++def generate_docstring(code: str,model: Optional[BaseModelBackend] = None,diff --git a/examples/models/openai_structured_output_example.py b/examples/models/openai_structured_output_example.pyindex 62ac81e1a..038a2080d 100644--- a/examples/models/openai_structured_output_example.py+++ b/examples/models/openai_structured_output_example.py@@ -16,6 +16,7 @@ from pydantic import BaseModelfrom camel.agents import ChatAgentfrom camel.configs import ChatGPTConfigfrom camel.models import ModelFactory+from camel.toolkits import FunctionTool, MathToolkit, SearchToolkitfrom camel.types import ModelPlatformType, ModelType@@ -31,19 +32,27 @@ class StudentList(BaseModel):openai_model = ModelFactory.create(model_platform=ModelPlatformType.OPENAI,model_type=ModelType.GPT_4O_MINI,- model_config_dict=ChatGPTConfig(- temperature=0.0, response_format=StudentList- ).as_dict(),+ model_config_dict=ChatGPTConfig(temperature=0.0).as_dict(),)# Set agent-camel_agent = ChatAgent(model=openai_model)+camel_agent = ChatAgent(+ model=openai_model,+ tools=[+ *MathToolkit().get_tools(),+ FunctionTool(SearchToolkit().search_duckduckgo),+ ],+)# Set user message-user_msg = """give me some student infos."""+user_msg = """give me some student infos, use 2024 minus 1996 as their age+"""++user_msg_2 = """give me some student infos, use 2024 minus 1996 as their age,+search internet to get the most famous peoples in 2024 as their name"""# Get response information-response = camel_agent.step(user_msg)+response = camel_agent.step(user_msg, response_format=StudentList)print(response.msgs[0].content)print(response.msgs[0].parsed)'''diff --git a/poetry.lock b/poetry.lockindex 6718f2597..4eeb61c9e 100644--- a/poetry.lock+++ b/poetry.lock@@ -1,4 +1,4 @@-# This file is automatically @generated by Poetry 1.8.4 and should not be changed by hand.+# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand.[[package]]name = "accelerate"@@ -3836,52 +3836,52 @@ tests = ["pytest", "simplejson"][[package]]name = "matplotlib"-version = "3.9.3"+version = "3.9.4"description = "Python plotting package"optional = falsepython-versions = ">=3.9"files = [- {file = "matplotlib-3.9.3-cp310-cp310-macosx_10_12_x86_64.whl", hash = "sha256:41b016e3be4e740b66c79a031a0a6e145728dbc248142e751e8dab4f3188ca1d"},- {file = "matplotlib-3.9.3-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:8e0143975fc2a6d7136c97e19c637321288371e8f09cff2564ecd73e865ea0b9"},- {file = "matplotlib-3.9.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9f459c8ee2c086455744723628264e43c884be0c7d7b45d84b8cd981310b4815"},- {file = "matplotlib-3.9.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:687df7ceff57b8f070d02b4db66f75566370e7ae182a0782b6d3d21b0d6917dc"},- {file = "matplotlib-3.9.3-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:edd14cf733fdc4f6e6fe3f705af97676a7e52859bf0044aa2c84e55be739241c"},- {file = "matplotlib-3.9.3-cp310-cp310-win_amd64.whl", hash = "sha256:1c40c244221a1adbb1256692b1133c6fb89418df27bf759a31a333e7912a4010"},- {file = "matplotlib-3.9.3-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:cf2a60daf6cecff6828bc608df00dbc794380e7234d2411c0ec612811f01969d"},- {file = "matplotlib-3.9.3-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:213d6dc25ce686516208d8a3e91120c6a4fdae4a3e06b8505ced5b716b50cc04"},- {file = "matplotlib-3.9.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c52f48eb75fcc119a4fdb68ba83eb5f71656999420375df7c94cc68e0e14686e"},- {file = "matplotlib-3.9.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d3c93796b44fa111049b88a24105e947f03c01966b5c0cc782e2ee3887b790a3"},- {file = "matplotlib-3.9.3-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:cd1077b9a09b16d8c3c7075a8add5ffbfe6a69156a57e290c800ed4d435bef1d"},- {file = "matplotlib-3.9.3-cp311-cp311-win_amd64.whl", hash = "sha256:c96eeeb8c68b662c7747f91a385688d4b449687d29b691eff7068a4602fe6dc4"},- {file = "matplotlib-3.9.3-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:0a361bd5583bf0bcc08841df3c10269617ee2a36b99ac39d455a767da908bbbc"},- {file = "matplotlib-3.9.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:e14485bb1b83eeb3d55b6878f9560240981e7bbc7a8d4e1e8c38b9bd6ec8d2de"},- {file = "matplotlib-3.9.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4a8d279f78844aad213c4935c18f8292a9432d51af2d88bca99072c903948045"},- {file = "matplotlib-3.9.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b6c12514329ac0d03128cf1dcceb335f4fbf7c11da98bca68dca8dcb983153a9"},- {file = "matplotlib-3.9.3-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:6e9de2b390d253a508dd497e9b5579f3a851f208763ed67fdca5dc0c3ea6849c"},- {file = "matplotlib-3.9.3-cp312-cp312-win_amd64.whl", hash = "sha256:d796272408f8567ff7eaa00eb2856b3a00524490e47ad505b0b4ca6bb8a7411f"},- {file = "matplotlib-3.9.3-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:203d18df84f5288973b2d56de63d4678cc748250026ca9e1ad8f8a0fd8a75d83"},- {file = "matplotlib-3.9.3-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:b651b0d3642991259109dc0351fc33ad44c624801367bb8307be9bfc35e427ad"},- {file = "matplotlib-3.9.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:66d7b171fecf96940ce069923a08ba3df33ef542de82c2ff4fe8caa8346fa95a"},- {file = "matplotlib-3.9.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6be0ba61f6ff2e6b68e4270fb63b6813c9e7dec3d15fc3a93f47480444fd72f0"},- {file = "matplotlib-3.9.3-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:9d6b2e8856dec3a6db1ae51aec85c82223e834b228c1d3228aede87eee2b34f9"},- {file = "matplotlib-3.9.3-cp313-cp313-win_amd64.whl", hash = "sha256:90a85a004fefed9e583597478420bf904bb1a065b0b0ee5b9d8d31b04b0f3f70"},- {file = "matplotlib-3.9.3-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:3119b2f16de7f7b9212ba76d8fe6a0e9f90b27a1e04683cd89833a991682f639"},- {file = "matplotlib-3.9.3-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:87ad73763d93add1b6c1f9fcd33af662fd62ed70e620c52fcb79f3ac427cf3a6"},- {file = "matplotlib-3.9.3-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:026bdf3137ab6022c866efa4813b6bbeddc2ed4c9e7e02f0e323a7bca380dfa0"},- {file = "matplotlib-3.9.3-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:760a5e89ebbb172989e8273024a1024b0f084510b9105261b3b00c15e9c9f006"},- {file = "matplotlib-3.9.3-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:a42b9dc42de2cfe357efa27d9c50c7833fc5ab9b2eb7252ccd5d5f836a84e1e4"},- {file = "matplotlib-3.9.3-cp313-cp313t-win_amd64.whl", hash = "sha256:e0fcb7da73fbf67b5f4bdaa57d85bb585a4e913d4a10f3e15b32baea56a67f0a"},- {file = "matplotlib-3.9.3-cp39-cp39-macosx_10_12_x86_64.whl", hash = "sha256:031b7f5b8e595cc07def77ec5b58464e9bb67dc5760be5d6f26d9da24892481d"},- {file = "matplotlib-3.9.3-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:9fa6e193c14d6944e0685cdb527cb6b38b0e4a518043e7212f214113af7391da"},- {file = "matplotlib-3.9.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4e6eefae6effa0c35bbbc18c25ee6e0b1da44d2359c3cd526eb0c9e703cf055d"},- {file = "matplotlib-3.9.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:10d3e5c7a99bd28afb957e1ae661323b0800d75b419f24d041ed1cc5d844a764"},- {file = "matplotlib-3.9.3-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:816a966d5d376bf24c92af8f379e78e67278833e4c7cbc9fa41872eec629a060"},- {file = "matplotlib-3.9.3-cp39-cp39-win_amd64.whl", hash = "sha256:3fb0b37c896172899a4a93d9442ffdc6f870165f59e05ce2e07c6fded1c15749"},- {file = "matplotlib-3.9.3-pp39-pypy39_pp73-macosx_10_15_x86_64.whl", hash = "sha256:5f2a4ea08e6876206d511365b0bc234edc813d90b930be72c3011bbd7898796f"},- {file = "matplotlib-3.9.3-pp39-pypy39_pp73-macosx_11_0_arm64.whl", hash = "sha256:9b081dac96ab19c54fd8558fac17c9d2c9cb5cc4656e7ed3261ddc927ba3e2c5"},- {file = "matplotlib-3.9.3-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0a0a63cb8404d1d1f94968ef35738900038137dab8af836b6c21bb6f03d75465"},- {file = "matplotlib-3.9.3-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:896774766fd6be4571a43bc2fcbcb1dcca0807e53cab4a5bf88c4aa861a08e12"},- {file = "matplotlib-3.9.3.tar.gz", hash = "sha256:cd5dbbc8e25cad5f706845c4d100e2c8b34691b412b93717ce38d8ae803bcfa5"},+ {file = "matplotlib-3.9.4-cp310-cp310-macosx_10_12_x86_64.whl", hash = "sha256:c5fdd7abfb706dfa8d307af64a87f1a862879ec3cd8d0ec8637458f0885b9c50"},+ {file = "matplotlib-3.9.4-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:d89bc4e85e40a71d1477780366c27fb7c6494d293e1617788986f74e2a03d7ff"},+ {file = "matplotlib-3.9.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ddf9f3c26aae695c5daafbf6b94e4c1a30d6cd617ba594bbbded3b33a1fcfa26"},+ {file = "matplotlib-3.9.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:18ebcf248030173b59a868fda1fe42397253f6698995b55e81e1f57431d85e50"},+ {file = "matplotlib-3.9.4-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:974896ec43c672ec23f3f8c648981e8bc880ee163146e0312a9b8def2fac66f5"},+ {file = "matplotlib-3.9.4-cp310-cp310-win_amd64.whl", hash = "sha256:4598c394ae9711cec135639374e70871fa36b56afae17bdf032a345be552a88d"},+ {file = "matplotlib-3.9.4-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:d4dd29641d9fb8bc4492420c5480398dd40a09afd73aebe4eb9d0071a05fbe0c"},+ {file = "matplotlib-3.9.4-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:30e5b22e8bcfb95442bf7d48b0d7f3bdf4a450cbf68986ea45fca3d11ae9d099"},+ {file = "matplotlib-3.9.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2bb0030d1d447fd56dcc23b4c64a26e44e898f0416276cac1ebc25522e0ac249"},+ {file = "matplotlib-3.9.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:aca90ed222ac3565d2752b83dbb27627480d27662671e4d39da72e97f657a423"},+ {file = "matplotlib-3.9.4-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:a181b2aa2906c608fcae72f977a4a2d76e385578939891b91c2550c39ecf361e"},+ {file = "matplotlib-3.9.4-cp311-cp311-win_amd64.whl", hash = "sha256:1f6882828231eca17f501c4dcd98a05abb3f03d157fbc0769c6911fe08b6cfd3"},+ {file = "matplotlib-3.9.4-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:dfc48d67e6661378a21c2983200a654b72b5c5cdbd5d2cf6e5e1ece860f0cc70"},+ {file = "matplotlib-3.9.4-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:47aef0fab8332d02d68e786eba8113ffd6f862182ea2999379dec9e237b7e483"},+ {file = "matplotlib-3.9.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:fba1f52c6b7dc764097f52fd9ab627b90db452c9feb653a59945de16752e965f"},+ {file = "matplotlib-3.9.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:173ac3748acaac21afcc3fa1633924609ba1b87749006bc25051c52c422a5d00"},+ {file = "matplotlib-3.9.4-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:320edea0cadc07007765e33f878b13b3738ffa9745c5f707705692df70ffe0e0"},+ {file = "matplotlib-3.9.4-cp312-cp312-win_amd64.whl", hash = "sha256:a4a4cfc82330b27042a7169533da7991e8789d180dd5b3daeaee57d75cd5a03b"},+ {file = "matplotlib-3.9.4-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:37eeffeeca3c940985b80f5b9a7b95ea35671e0e7405001f249848d2b62351b6"},+ {file = "matplotlib-3.9.4-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:3e7465ac859ee4abcb0d836137cd8414e7bb7ad330d905abced457217d4f0f45"},+ {file = "matplotlib-3.9.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f4c12302c34afa0cf061bea23b331e747e5e554b0fa595c96e01c7b75bc3b858"},+ {file = "matplotlib-3.9.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2b8c97917f21b75e72108b97707ba3d48f171541a74aa2a56df7a40626bafc64"},+ {file = "matplotlib-3.9.4-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:0229803bd7e19271b03cb09f27db76c918c467aa4ce2ae168171bc67c3f508df"},+ {file = "matplotlib-3.9.4-cp313-cp313-win_amd64.whl", hash = "sha256:7c0d8ef442ebf56ff5e206f8083d08252ee738e04f3dc88ea882853a05488799"},+ {file = "matplotlib-3.9.4-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:a04c3b00066a688834356d196136349cb32f5e1003c55ac419e91585168b88fb"},+ {file = "matplotlib-3.9.4-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:04c519587f6c210626741a1e9a68eefc05966ede24205db8982841826af5871a"},+ {file = "matplotlib-3.9.4-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:308afbf1a228b8b525fcd5cec17f246bbbb63b175a3ef6eb7b4d33287ca0cf0c"},+ {file = "matplotlib-3.9.4-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ddb3b02246ddcffd3ce98e88fed5b238bc5faff10dbbaa42090ea13241d15764"},+ {file = "matplotlib-3.9.4-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:8a75287e9cb9eee48cb79ec1d806f75b29c0fde978cb7223a1f4c5848d696041"},+ {file = "matplotlib-3.9.4-cp313-cp313t-win_amd64.whl", hash = "sha256:488deb7af140f0ba86da003e66e10d55ff915e152c78b4b66d231638400b1965"},+ {file = "matplotlib-3.9.4-cp39-cp39-macosx_10_12_x86_64.whl", hash = "sha256:3c3724d89a387ddf78ff88d2a30ca78ac2b4c89cf37f2db4bd453c34799e933c"},+ {file = "matplotlib-3.9.4-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:d5f0a8430ffe23d7e32cfd86445864ccad141797f7d25b7c41759a5b5d17cfd7"},+ {file = "matplotlib-3.9.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6bb0141a21aef3b64b633dc4d16cbd5fc538b727e4958be82a0e1c92a234160e"},+ {file = "matplotlib-3.9.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:57aa235109e9eed52e2c2949db17da185383fa71083c00c6c143a60e07e0888c"},+ {file = "matplotlib-3.9.4-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:b18c600061477ccfdd1e6fd050c33d8be82431700f3452b297a56d9ed7037abb"},+ {file = "matplotlib-3.9.4-cp39-cp39-win_amd64.whl", hash = "sha256:ef5f2d1b67d2d2145ff75e10f8c008bfbf71d45137c4b648c87193e7dd053eac"},+ {file = "matplotlib-3.9.4-pp39-pypy39_pp73-macosx_10_15_x86_64.whl", hash = "sha256:44e0ed786d769d85bc787b0606a53f2d8d2d1d3c8a2608237365e9121c1a338c"},+ {file = "matplotlib-3.9.4-pp39-pypy39_pp73-macosx_11_0_arm64.whl", hash = "sha256:09debb9ce941eb23ecdbe7eab972b1c3e0276dcf01688073faff7b0f61d6c6ca"},+ {file = "matplotlib-3.9.4-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bcc53cf157a657bfd03afab14774d54ba73aa84d42cfe2480c91bd94873952db"},+ {file = "matplotlib-3.9.4-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:ad45da51be7ad02387801fd154ef74d942f49fe3fcd26a64c94842ba7ec0d865"},+ {file = "matplotlib-3.9.4.tar.gz", hash = "sha256:1e00e8be7393cbdc6fedfa8a6fba02cf3e83814b285db1c60b906a023ba41bc3"},][package.dependencies]@@ -3896,7 +3896,7 @@ pyparsing = ">=2.3.1"python-dateutil = ">=2.7"[package.extras]-dev = ["meson-python (>=0.13.1)", "numpy (>=1.25)", "pybind11 (>=2.6,!=2.13.3)", "setuptools (>=64)", "setuptools_scm (>=7)"]+dev = ["meson-python (>=0.13.1,<0.17.0)", "numpy (>=1.25)", "pybind11 (>=2.6,!=2.13.3)", "setuptools (>=64)", "setuptools_scm (>=7)"][[package]]name = "matplotlib-inline"@@ -3951,6 +3951,7 @@ python-versions = ">=3.7"files = [{file = "milvus_lite-2.4.10-py3-none-macosx_10_9_x86_64.whl", hash = "sha256:fc4246d3ed7d1910847afce0c9ba18212e93a6e9b8406048436940578dfad5cb"},{file = "milvus_lite-2.4.10-py3-none-macosx_11_0_arm64.whl", hash = "sha256:74a8e07c5e3b057df17fbb46913388e84df1dc403a200f4e423799a58184c800"},+ {file = "milvus_lite-2.4.10-py3-none-manylinux2014_aarch64.whl", hash = "sha256:240c7386b747bad696ecb5bd1f58d491e86b9d4b92dccee3315ed7256256eddc"},{file = "milvus_lite-2.4.10-py3-none-manylinux2014_x86_64.whl", hash = "sha256:211d2e334a043f9282bdd9755f76b9b2d93b23bffa7af240919ffce6a8dfe325"},]@@ -5150,43 +5151,31 @@ python-versions = ">=3.9"files = [{file = "pandas-2.2.3-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:1948ddde24197a0f7add2bdc4ca83bf2b1ef84a1bc8ccffd95eda17fd836ecb5"},{file = "pandas-2.2.3-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:381175499d3802cde0eabbaf6324cce0c4f5d52ca6f8c377c29ad442f50f6348"},- {file = "pandas-2.2.3-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:d9c45366def9a3dd85a6454c0e7908f2b3b8e9c138f5dc38fed7ce720d8453ed"},{file = "pandas-2.2.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:86976a1c5b25ae3f8ccae3a5306e443569ee3c3faf444dfd0f41cda24667ad57"},- {file = "pandas-2.2.3-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:b8661b0238a69d7aafe156b7fa86c44b881387509653fdf857bebc5e4008ad42"},{file = "pandas-2.2.3-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:37e0aced3e8f539eccf2e099f65cdb9c8aa85109b0be6e93e2baff94264bdc6f"},{file = "pandas-2.2.3-cp310-cp310-win_amd64.whl", hash = "sha256:56534ce0746a58afaf7942ba4863e0ef81c9c50d3f0ae93e9497d6a41a057645"},{file = "pandas-2.2.3-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:66108071e1b935240e74525006034333f98bcdb87ea116de573a6a0dccb6c039"},{file = "pandas-2.2.3-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:7c2875855b0ff77b2a64a0365e24455d9990730d6431b9e0ee18ad8acee13dbd"},- {file = "pandas-2.2.3-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:cd8d0c3be0515c12fed0bdbae072551c8b54b7192c7b1fda0ba56059a0179698"},{file = "pandas-2.2.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c124333816c3a9b03fbeef3a9f230ba9a737e9e5bb4060aa2107a86cc0a497fc"},- {file = "pandas-2.2.3-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:63cc132e40a2e084cf01adf0775b15ac515ba905d7dcca47e9a251819c575ef3"},{file = "pandas-2.2.3-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:29401dbfa9ad77319367d36940cd8a0b3a11aba16063e39632d98b0e931ddf32"},{file = "pandas-2.2.3-cp311-cp311-win_amd64.whl", hash = "sha256:3fc6873a41186404dad67245896a6e440baacc92f5b716ccd1bc9ed2995ab2c5"},{file = "pandas-2.2.3-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:b1d432e8d08679a40e2a6d8b2f9770a5c21793a6f9f47fdd52c5ce1948a5a8a9"},{file = "pandas-2.2.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:a5a1595fe639f5988ba6a8e5bc9649af3baf26df3998a0abe56c02609392e0a4"},- {file = "pandas-2.2.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:5de54125a92bb4d1c051c0659e6fcb75256bf799a732a87184e5ea503965bce3"},{file = "pandas-2.2.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fffb8ae78d8af97f849404f21411c95062db1496aeb3e56f146f0355c9989319"},- {file = "pandas-2.2.3-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:6dfcb5ee8d4d50c06a51c2fffa6cff6272098ad6540aed1a76d15fb9318194d8"},{file = "pandas-2.2.3-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:062309c1b9ea12a50e8ce661145c6aab431b1e99530d3cd60640e255778bd43a"},{file = "pandas-2.2.3-cp312-cp312-win_amd64.whl", hash = "sha256:59ef3764d0fe818125a5097d2ae867ca3fa64df032331b7e0917cf5d7bf66b13"},{file = "pandas-2.2.3-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:f00d1345d84d8c86a63e476bb4955e46458b304b9575dcf71102b5c705320015"},{file = "pandas-2.2.3-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:3508d914817e153ad359d7e069d752cdd736a247c322d932eb89e6bc84217f28"},- {file = "pandas-2.2.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:22a9d949bfc9a502d320aa04e5d02feab689d61da4e7764b62c30b991c42c5f0"},{file = "pandas-2.2.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f3a255b2c19987fbbe62a9dfd6cff7ff2aa9ccab3fc75218fd4b7530f01efa24"},- {file = "pandas-2.2.3-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:800250ecdadb6d9c78eae4990da62743b857b470883fa27f652db8bdde7f6659"},{file = "pandas-2.2.3-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:6374c452ff3ec675a8f46fd9ab25c4ad0ba590b71cf0656f8b6daa5202bca3fb"},{file = "pandas-2.2.3-cp313-cp313-win_amd64.whl", hash = "sha256:61c5ad4043f791b61dd4752191d9f07f0ae412515d59ba8f005832a532f8736d"},{file = "pandas-2.2.3-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:3b71f27954685ee685317063bf13c7709a7ba74fc996b84fc6821c59b0f06468"},{file = "pandas-2.2.3-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:38cf8125c40dae9d5acc10fa66af8ea6fdf760b2714ee482ca691fc66e6fcb18"},- {file = "pandas-2.2.3-cp313-cp313t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:ba96630bc17c875161df3818780af30e43be9b166ce51c9a18c1feae342906c2"},{file = "pandas-2.2.3-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1db71525a1538b30142094edb9adc10be3f3e176748cd7acc2240c2f2e5aa3a4"},- {file = "pandas-2.2.3-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:15c0e1e02e93116177d29ff83e8b1619c93ddc9c49083f237d4312337a61165d"},{file = "pandas-2.2.3-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:ad5b65698ab28ed8d7f18790a0dc58005c7629f227be9ecc1072aa74c0c1d43a"},{file = "pandas-2.2.3-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:bc6b93f9b966093cb0fd62ff1a7e4c09e6d546ad7c1de191767baffc57628f39"},{file = "pandas-2.2.3-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:5dbca4c1acd72e8eeef4753eeca07de9b1db4f398669d5994086f788a5d7cc30"},- {file = "pandas-2.2.3-cp39-cp39-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:8cd6d7cc958a3910f934ea8dbdf17b2364827bb4dafc38ce6eef6bb3d65ff09c"},{file = "pandas-2.2.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:99df71520d25fade9db7c1076ac94eb994f4d2673ef2aa2e86ee039b6746d20c"},- {file = "pandas-2.2.3-cp39-cp39-musllinux_1_2_aarch64.whl", hash = "sha256:31d0ced62d4ea3e231a9f228366919a5ea0b07440d9d4dac345376fd8e1477ea"},{file = "pandas-2.2.3-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:7eee9e7cea6adf3e3d24e304ac6b8300646e2a5d1cd3a3c2abed9101b0846761"},{file = "pandas-2.2.3-cp39-cp39-win_amd64.whl", hash = "sha256:4850ba03528b6dd51d6c5d273c46f183f39a9baf3f0143e566b89450965b105e"},{file = "pandas-2.2.3.tar.gz", hash = "sha256:4f18ba62b61d7e192368b84517265a99b4d7ee8912f8708660fb4a366cc82667"},@@ -6039,6 +6028,7 @@ description = "Pure-Python implementation of ASN.1 types and DER/BER/CER codecsoptional = truepython-versions = ">=3.8"files = [+ {file = "pyasn1-0.6.1-py3-none-any.whl", hash = "sha256:0d632f46f2ba09143da3a8afe9e33fb6f92fa2320ab7e886e2d0f7672af84629"},{file = "pyasn1-0.6.1.tar.gz", hash = "sha256:6f580d2bdd84365380830acf45550f2511469f673cb4a5ae3857a3170128b034"},]@@ -6049,6 +6039,7 @@ description = "A collection of ASN.1-based protocols modules"optional = truepython-versions = ">=3.8"files = [+ {file = "pyasn1_modules-0.4.1-py3-none-any.whl", hash = "sha256:49bfa96b45a292b711e986f222502c1c9a5e1f4e568fc30e2574a6c7d07838fd"},{file = "pyasn1_modules-0.4.1.tar.gz", hash = "sha256:c28e2dbf9c06ad61c71a075c7e0f9fd0f1b0bb2d2ad4377f240d33ac2ab60a7c"},]diff --git a/test/agents/test_chat_agent.py b/test/agents/test_chat_agent.pyindex d43fb5608..cad238abe 100644--- a/test/agents/test_chat_agent.py+++ b/test/agents/test_chat_agent.py@@ -11,8 +11,8 @@# See the License for the specific language governing permissions and# limitations under the License.# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========-import astimport asyncio+import jsonfrom io import BytesIOfrom typing import Listfrom unittest.mock import Mock@@ -168,7 +168,7 @@ def test_chat_agent_step_with_structure_response():)response = assistant.step(user_msg, response_format=JokeResponse)- response_content_json = ast.literal_eval(response.msgs[0].content)+ response_content_json = json.loads(response.msg.content)joke_response_keys = set(JokeResponse.model_json_schema()["properties"].keys())@@ -528,7 +528,7 @@ def test_tool_calling_sync():assert str(tool_calls[0]).startswith("Function Execution")assert tool_calls[0].func_name == "multiply"- assert tool_calls[0].args == {"a": 2, "b": 8}+ assert tool_calls[0].args == {'a': 2, 'b': 8, 'decimal_places': 0}assert tool_calls[0].result == 16@@ -570,7 +570,7 @@ async def test_tool_calling_math_async():assert str(tool_calls[0]).startswith("Function Execution")assert tool_calls[0].func_name == "multiply"- assert tool_calls[0].args == {"a": 2, "b": 8}+ assert tool_calls[0].args == {'a': 2, 'b': 8, 'decimal_places': 0}assert tool_calls[0].result == 16diff --git a/test/toolkits/test_generate_openai_tool_schema.py b/test/toolkits/test_generate_openai_tool_schema.pyindex a484a18fa..f6f3c2ba9 100644--- a/test/toolkits/test_generate_openai_tool_schema.py+++ b/test/toolkits/test_generate_openai_tool_schema.py@@ -205,6 +205,7 @@ def test_function_tool_generate_schema_with_retries('This function checks if the integer is positive and\n''if the string is non-empty.'),+ 'strict': True,'parameters': {'type': 'object','properties': {@@ -217,10 +218,10 @@ def test_function_tool_generate_schema_with_retries('description': ("The string to verify. Default is 'default'."),- 'default': 'default',},},- 'required': ['a'],+ 'required': ['a', 'b'],+ 'additionalProperties': False,},},}diff --git a/test/toolkits/test_openai_function.py b/test/toolkits/test_openai_function.pyindex 9ef366ecd..9f733bb7b 100644--- a/test/toolkits/test_openai_function.py+++ b/test/toolkits/test_openai_function.py@@ -87,7 +87,6 @@ def test_get_openai_tool_schema():'description': 'datatime_para desc',},'default_enum_para': {- 'default': 'critic','allOf': [{'$ref': '#/definitions/RoleType'}],'description': 'default_enum_para desc',},@@ -120,6 +119,7 @@ def test_get_openai_tool_schema():'name': 'test_all_parameters','description': 'A function to test all parameter type.''\nThe parameters will be provided by user.',+ 'strict': True,'parameters': {'$defs': {'RoleType': {@@ -162,7 +162,6 @@ def test_get_openai_tool_schema():},'default_enum_para': {'$ref': '#/$defs/RoleType',- 'default': 'critic','description': 'default_enum_para desc',},},@@ -173,8 +172,10 @@ def test_get_openai_tool_schema():'list_para','float_para','datatime_para',+ 'default_enum_para',],'type': 'object',+ 'additionalProperties': False,},},}@@ -249,6 +250,7 @@ def test_different_docstring_style():"function": {"name": "mul","description": "Multiply two integers.",+ "strict": true,"parameters": {"properties": {"a": {@@ -262,7 +264,8 @@ def test_different_docstring_style():}},"required": ["a", "b"],- "type": "object"+ "type": "object",+ "additionalProperties": false}}}""")@@ -313,6 +316,7 @@ def add_with_wrong_doc(a: int, b: int) -> int:function_schema = {"name": "add","description": "Adds two numbers.",+ 'strict': True,"parameters": {'type': 'object','properties': {@@ -325,6 +329,7 @@ function_schema = {'description': 'The second number to be added.',},},+ 'additionalProperties': False,'required': ['a', 'b'],},}@@ -332,6 +337,7 @@ function_schema = {function_schema_without_docs = {"description": '',"name": "add",+ "strict": True,"parameters": {'type': 'object','properties': {@@ -343,12 +349,14 @@ function_schema_without_docs = {},},'required': ['a', 'b'],+ 'additionalProperties': False,},}function_schema_with_wrong_docs = {"name": "add","description": "Adds two numbers.",+ "strict": True,"parameters": {'type': 'object','properties': {@@ -361,6 +369,7 @@ function_schema_with_wrong_docs = {},},'required': ['a', 'b'],+ 'additionalProperties': False,},}diff --git a/test/toolkits/test_synthesize_output.py b/test/toolkits/test_synthesize_output.pyindex 1fcbc53e9..32753d356 100644--- a/test/toolkits/test_synthesize_output.py+++ b/test/toolkits/test_synthesize_output.py@@ -75,7 +75,7 @@ def test_synthesize_execution_output_with_synthesize_output_format():kwargs = {'a': 2, 'b': 3}output = function_tool.synthesize_execution_output(kwargs=kwargs)- assert output.strip() == "{'sum_value': 5}"+ assert output.strip() == '{"sum_value":5}'@pytest.mark.model_backend