🐫 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: Refactor OpenAIFunction to FunctionTool (#966)
Tom Dörr0b6734e78b14
diff --git a/camel/agents/chat_agent.py b/camel/agents/chat_agent.pyindex 8621a9448..db3b256f3 100644--- a/camel/agents/chat_agent.py+++ b/camel/agents/chat_agent.py@@ -63,7 +63,7 @@ if TYPE_CHECKING:from openai import Streamfrom camel.terminators import ResponseTerminator- from camel.toolkits import OpenAIFunction+ from camel.toolkits import FunctionToollogger = logging.getLogger(__name__)@@ -131,10 +131,10 @@ class ChatAgent(BaseAgent):(default: :obj:`None`)output_language (str, optional): The language to be output by theagent. (default: :obj:`None`)- tools (List[OpenAIFunction], optional): List of available- :obj:`OpenAIFunction`. (default: :obj:`None`)- external_tools (List[OpenAIFunction], optional): List of external tools- (:obj:`OpenAIFunction`) bind to one chat agent. When these tools+ tools (List[FunctionTool], optional): List of available+ :obj:`FunctionTool`. (default: :obj:`None`)+ external_tools (List[FunctionTool], optional): List of external tools+ (:obj:`FunctionTool`) bind to one chat agent. When these toolsare called, the agent will directly return the request instead ofprocessing it. (default: :obj:`None`)response_terminators (List[ResponseTerminator], optional): List of@@ -150,8 +150,8 @@ class ChatAgent(BaseAgent):message_window_size: Optional[int] = None,token_limit: Optional[int] = None,output_language: Optional[str] = None,- tools: Optional[List[OpenAIFunction]] = None,- external_tools: Optional[List[OpenAIFunction]] = None,+ tools: Optional[List[FunctionTool]] = None,+ external_tools: Optional[List[FunctionTool]] = None,response_terminators: Optional[List[ResponseTerminator]] = None,) -> None:self.orig_sys_message: BaseMessage = system_message@@ -795,12 +795,12 @@ class ChatAgent(BaseAgent):r"""Internal function of structuring the output of the agent based onthe given output schema."""- from camel.toolkits import OpenAIFunction+ from camel.toolkits import FunctionToolschema_json = get_pydantic_object_schema(output_schema)func_str = json_to_function_code(schema_json)func_callable = func_string_to_callable(func_str)- func = OpenAIFunction(func_callable)+ func = FunctionTool(func_callable)original_func_dict = self.func_dictoriginal_model_dict = self.model_backend.model_config_dictdiff --git a/camel/configs/base_config.py b/camel/configs/base_config.pyindex 3d6c95bdc..8ce9ff24a 100644--- a/camel/configs/base_config.py+++ b/camel/configs/base_config.py@@ -39,13 +39,13 @@ class BaseConfig(ABC, BaseModel):@classmethoddef fields_type_checking(cls, tools):if tools is not None:- from camel.toolkits import OpenAIFunction+ from camel.toolkits import FunctionToolfor tool in tools:- if not isinstance(tool, OpenAIFunction):+ if not isinstance(tool, FunctionTool):raise ValueError(f"The tool {tool} should "- "be an instance of `OpenAIFunction`."+ "be an instance of `FunctionTool`.")return tools@@ -54,14 +54,14 @@ class BaseConfig(ABC, BaseModel):tools_schema = Noneif self.tools:- from camel.toolkits import OpenAIFunction+ from camel.toolkits import FunctionTooltools_schema = []for tool in self.tools:- if not isinstance(tool, OpenAIFunction):+ if not isinstance(tool, FunctionTool):raise ValueError(f"The tool {tool} should "- "be an instance of `OpenAIFunction`."+ "be an instance of `FunctionTool`.")tools_schema.append(tool.get_openai_tool_schema())config_dict["tools"] = tools_schemadiff --git a/camel/configs/groq_config.py b/camel/configs/groq_config.pyindex fe3f2f90a..43fe2e076 100644--- a/camel/configs/groq_config.py+++ b/camel/configs/groq_config.py@@ -73,7 +73,7 @@ class GroqConfig(BaseConfig):user (str, optional): A unique identifier representing your end-user,which can help OpenAI to monitor and detect abuse.(default: :obj:`""`)- tools (list[OpenAIFunction], optional): A list of tools the model may+ tools (list[FunctionTool], optional): A list of tools the model maycall. Currently, only functions are supported as a tool. Use thisto provide a list of functions the model may generate JSON inputsfor. A max of 128 functions are supported.diff --git a/camel/configs/openai_config.py b/camel/configs/openai_config.pyindex 1adb8cc3f..971232ad8 100644--- a/camel/configs/openai_config.py+++ b/camel/configs/openai_config.py@@ -81,7 +81,7 @@ class ChatGPTConfig(BaseConfig):user (str, optional): A unique identifier representing your end-user,which can help OpenAI to monitor and detect abuse.(default: :obj:`""`)- tools (list[OpenAIFunction], optional): A list of tools the model may+ tools (list[FunctionTool], optional): A list of tools the model maycall. Currently, only functions are supported as a tool. Use thisto provide a list of functions the model may generate JSON inputsfor. A max of 128 functions are supported.diff --git a/camel/configs/samba_config.py b/camel/configs/samba_config.pyindex 444172270..409f939cf 100644--- a/camel/configs/samba_config.py+++ b/camel/configs/samba_config.py@@ -172,7 +172,7 @@ class SambaCloudAPIConfig(BaseConfig):user (str, optional): A unique identifier representing your end-user,which can help OpenAI to monitor and detect abuse.(default: :obj:`""`)- tools (list[OpenAIFunction], optional): A list of tools the model may+ tools (list[FunctionTool], optional): A list of tools the model maycall. Currently, only functions are supported as a tool. Use thisto provide a list of functions the model may generate JSON inputsfor. A max of 128 functions are supported.diff --git a/camel/configs/zhipuai_config.py b/camel/configs/zhipuai_config.pyindex 89f2061df..21bbec1e7 100644--- a/camel/configs/zhipuai_config.py+++ b/camel/configs/zhipuai_config.py@@ -45,7 +45,7 @@ class ZhipuAIConfig(BaseConfig):in the chat completion. The total length of input tokens andgenerated tokens is limited by the model's context length.(default: :obj:`None`)- tools (list[OpenAIFunction], optional): A list of tools the model may+ tools (list[FunctionTool], optional): A list of tools the model maycall. Currently, only functions are supported as a tool. Use thisto provide a list of functions the model may generate JSON inputsfor. A max of 128 functions are supported.diff --git a/camel/messages/__init__.py b/camel/messages/__init__.pyindex 6e93b5c43..870626024 100644--- a/camel/messages/__init__.py+++ b/camel/messages/__init__.py@@ -32,6 +32,7 @@ __all__ = ['OpenAISystemMessage','OpenAIAssistantMessage','OpenAIUserMessage',+ 'OpenAIFunctionMessage','OpenAIMessage','BaseMessage','FunctionCallingMessage',diff --git a/camel/toolkits/__init__.py b/camel/toolkits/__init__.pyindex 87f2326ff..164f38b49 100644--- a/camel/toolkits/__init__.py+++ b/camel/toolkits/__init__.py@@ -12,7 +12,8 @@# limitations under the License.# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========# ruff: noqa: I001-from .openai_function import (+from .function_tool import (+ FunctionTool,OpenAIFunction,get_openai_function_schema,get_openai_tool_schema,@@ -35,6 +36,7 @@ from .code_execution import CodeExecutionToolkitfrom .github_toolkit import GithubToolkit__all__ = [+ 'FunctionTool','OpenAIFunction','get_openai_function_schema','get_openai_tool_schema',diff --git a/camel/toolkits/base.py b/camel/toolkits/base.pyindex 6e6ee2f6b..65495f3c7 100644--- a/camel/toolkits/base.py+++ b/camel/toolkits/base.py@@ -16,9 +16,9 @@ from typing import Listfrom camel.utils import AgentOpsMeta-from .openai_function import OpenAIFunction+from .function_tool import FunctionToolclass BaseToolkit(metaclass=AgentOpsMeta):- def get_tools(self) -> List[OpenAIFunction]:+ def get_tools(self) -> List[FunctionTool]:raise NotImplementedError("Subclasses must implement this method.")diff --git a/camel/toolkits/code_execution.py b/camel/toolkits/code_execution.pyindex 0fcc3243b..9d4b073aa 100644--- a/camel/toolkits/code_execution.py+++ b/camel/toolkits/code_execution.py@@ -14,7 +14,7 @@from typing import List, Literalfrom camel.interpreters import InternalPythonInterpreter-from camel.toolkits import OpenAIFunction+from camel.toolkits import FunctionToolfrom .base import BaseToolkit@@ -58,12 +58,12 @@ class CodeExecutionToolkit(BaseToolkit):print(content)return content- def get_tools(self) -> List[OpenAIFunction]:- r"""Returns a list of OpenAIFunction objects representing the+ def get_tools(self) -> List[FunctionTool]:+ r"""Returns a list of FunctionTool objects representing thefunctions in the toolkit.Returns:- List[OpenAIFunction]: A list of OpenAIFunction objects+ List[FunctionTool]: A list of FunctionTool objectsrepresenting the functions in the toolkit."""- return [OpenAIFunction(self.execute_code)]+ return [FunctionTool(self.execute_code)]diff --git a/camel/toolkits/dalle_toolkit.py b/camel/toolkits/dalle_toolkit.pyindex 4898f0d69..29b4bf7a8 100644--- a/camel/toolkits/dalle_toolkit.py+++ b/camel/toolkits/dalle_toolkit.py@@ -20,7 +20,7 @@ from typing import List, Optionalfrom openai import OpenAIfrom PIL import Image-from camel.toolkits import OpenAIFunction+from camel.toolkits import FunctionToolfrom camel.toolkits.base import BaseToolkit@@ -132,15 +132,15 @@ class DalleToolkit(BaseToolkit):return image_path- def get_tools(self) -> List[OpenAIFunction]:- r"""Returns a list of OpenAIFunction objects representing the+ def get_tools(self) -> List[FunctionTool]:+ r"""Returns a list of FunctionTool objects representing thefunctions in the toolkit.Returns:- List[OpenAIFunction]: A list of OpenAIFunction objects+ List[FunctionTool]: A list of FunctionTool objectsrepresenting the functions in the toolkit."""- return [OpenAIFunction(self.get_dalle_img)]+ return [FunctionTool(self.get_dalle_img)]-DALLE_FUNCS: List[OpenAIFunction] = DalleToolkit().get_tools()+DALLE_FUNCS: List[FunctionTool] = DalleToolkit().get_tools()diff --git a/camel/toolkits/openai_function.py b/camel/toolkits/function_tool.pysimilarity index 96%rename from camel/toolkits/openai_function.pyrename to camel/toolkits/function_tool.pyindex e2b35a884..804bc894e 100644--- a/camel/toolkits/openai_function.py+++ b/camel/toolkits/function_tool.py@@ -11,6 +11,7 @@# See the License for the specific language governing permissions and# limitations under the License.# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========+import warningsfrom inspect import Parameter, signaturefrom typing import Any, Callable, Dict, Mapping, Optional, Tuple@@ -142,7 +143,7 @@ def get_openai_tool_schema(func: Callable) -> Dict[str, Any]:return openai_tool_schema-class OpenAIFunction:+class FunctionTool:r"""An abstraction of a function that OpenAI chat models can call. Seehttps://platform.openai.com/docs/api-reference/chat/create.@@ -387,3 +388,23 @@ class OpenAIFunction:except SchemaError as e:raise eself.openai_tool_schema["function"]["parameters"]["properties"] = value+++warnings.simplefilter('always', DeprecationWarning)+++# Alias for backwards compatibility+class OpenAIFunction(FunctionTool):+ def __init__(self, *args, **kwargs):+ PURPLE = '\033[95m'+ RESET = '\033[0m'++ def purple_warning(msg):+ warnings.warn(+ PURPLE + msg + RESET, DeprecationWarning, stacklevel=2+ )++ purple_warning(+ "OpenAIFunction is deprecated, please use FunctionTool instead."+ )+ super().__init__(*args, **kwargs)diff --git a/camel/toolkits/github_toolkit.py b/camel/toolkits/github_toolkit.pyindex 141d7706b..d8b66633d 100644--- a/camel/toolkits/github_toolkit.py+++ b/camel/toolkits/github_toolkit.py@@ -21,7 +21,7 @@ from pydantic import BaseModelfrom camel.utils import dependencies_requiredfrom .base import BaseToolkit-from .openai_function import OpenAIFunction+from .function_tool import FunctionToolclass GithubIssue(BaseModel):@@ -131,19 +131,19 @@ class GithubToolkit(BaseToolkit):self.github = Github(auth=Auth.Token(access_token))self.repo = self.github.get_repo(repo_name)- def get_tools(self) -> List[OpenAIFunction]:- r"""Returns a list of OpenAIFunction objects representing the+ def get_tools(self) -> List[FunctionTool]:+ r"""Returns a list of FunctionTool objects representing thefunctions in the toolkit.Returns:- List[OpenAIFunction]: A list of OpenAIFunction objects+ List[FunctionTool]: A list of FunctionTool objectsrepresenting the functions in the toolkit."""return [- OpenAIFunction(self.retrieve_issue_list),- OpenAIFunction(self.retrieve_issue),- OpenAIFunction(self.create_pull_request),- OpenAIFunction(self.retrieve_pull_requests),+ FunctionTool(self.retrieve_issue_list),+ FunctionTool(self.retrieve_issue),+ FunctionTool(self.create_pull_request),+ FunctionTool(self.retrieve_pull_requests),]def get_github_access_token(self) -> str:diff --git a/camel/toolkits/google_maps_toolkit.py b/camel/toolkits/google_maps_toolkit.pyindex 9b15fba5e..6b5ff04a5 100644--- a/camel/toolkits/google_maps_toolkit.py+++ b/camel/toolkits/google_maps_toolkit.py@@ -16,7 +16,7 @@ from functools import wrapsfrom typing import Any, Callable, List, Optional, Unionfrom camel.toolkits.base import BaseToolkit-from camel.toolkits.openai_function import OpenAIFunction+from camel.toolkits.function_tool import FunctionToolfrom camel.utils import dependencies_required@@ -287,16 +287,16 @@ class GoogleMapsToolkit(BaseToolkit):return description- def get_tools(self) -> List[OpenAIFunction]:- r"""Returns a list of OpenAIFunction objects representing the+ def get_tools(self) -> List[FunctionTool]:+ r"""Returns a list of FunctionTool objects representing thefunctions in the toolkit.Returns:- List[OpenAIFunction]: A list of OpenAIFunction objects+ List[FunctionTool]: A list of FunctionTool objectsrepresenting the functions in the toolkit."""return [- OpenAIFunction(self.get_address_description),- OpenAIFunction(self.get_elevation),- OpenAIFunction(self.get_timezone),+ FunctionTool(self.get_address_description),+ FunctionTool(self.get_elevation),+ FunctionTool(self.get_timezone),]diff --git a/camel/toolkits/linkedin_toolkit.py b/camel/toolkits/linkedin_toolkit.pyindex 1993849ce..3ed063b53 100644--- a/camel/toolkits/linkedin_toolkit.py+++ b/camel/toolkits/linkedin_toolkit.py@@ -19,7 +19,7 @@ from typing import Listimport requests-from camel.toolkits import OpenAIFunction+from camel.toolkits import FunctionToolfrom camel.toolkits.base import BaseToolkitfrom camel.utils import handle_http_error@@ -194,18 +194,18 @@ class LinkedInToolkit(BaseToolkit):return profile_report- def get_tools(self) -> List[OpenAIFunction]:- r"""Returns a list of OpenAIFunction objects representing the+ def get_tools(self) -> List[FunctionTool]:+ r"""Returns a list of FunctionTool objects representing thefunctions in the toolkit.Returns:- List[OpenAIFunction]: A list of OpenAIFunction objects+ List[FunctionTool]: A list of FunctionTool objectsrepresenting the functions in the toolkit."""return [- OpenAIFunction(self.create_post),- OpenAIFunction(self.delete_post),- OpenAIFunction(self.get_profile),+ FunctionTool(self.create_post),+ FunctionTool(self.delete_post),+ FunctionTool(self.get_profile),]def _get_access_token(self) -> str:diff --git a/camel/toolkits/math_toolkit.py b/camel/toolkits/math_toolkit.pyindex 398f0070d..0f3762f74 100644--- a/camel/toolkits/math_toolkit.py+++ b/camel/toolkits/math_toolkit.py@@ -15,7 +15,7 @@from typing import Listfrom camel.toolkits.base import BaseToolkit-from camel.toolkits.openai_function import OpenAIFunction+from camel.toolkits.function_tool import FunctionToolclass MathToolkit(BaseToolkit):@@ -61,19 +61,19 @@ class MathToolkit(BaseToolkit):"""return a * b- def get_tools(self) -> List[OpenAIFunction]:- r"""Returns a list of OpenAIFunction objects representing the+ def get_tools(self) -> List[FunctionTool]:+ r"""Returns a list of FunctionTool objects representing thefunctions in the toolkit.Returns:- List[OpenAIFunction]: A list of OpenAIFunction objects+ List[FunctionTool]: A list of FunctionTool objectsrepresenting the functions in the toolkit."""return [- OpenAIFunction(self.add),- OpenAIFunction(self.sub),- OpenAIFunction(self.mul),+ FunctionTool(self.add),+ FunctionTool(self.sub),+ FunctionTool(self.mul),]-MATH_FUNCS: List[OpenAIFunction] = MathToolkit().get_tools()+MATH_FUNCS: List[FunctionTool] = MathToolkit().get_tools()diff --git a/camel/toolkits/open_api_toolkit.py b/camel/toolkits/open_api_toolkit.pyindex 10f90f4bb..bca387c31 100644--- a/camel/toolkits/open_api_toolkit.py+++ b/camel/toolkits/open_api_toolkit.py@@ -17,7 +17,7 @@ from typing import Any, Callable, Dict, List, Optional, Tupleimport requests-from camel.toolkits import OpenAIFunction, openapi_security_config+from camel.toolkits import FunctionTool, openapi_security_configfrom camel.types import OpenAPIName@@ -526,12 +526,12 @@ class OpenAPIToolkit:apinames_filepaths.append((api_name.value, file_path))return apinames_filepaths- def get_tools(self) -> List[OpenAIFunction]:- r"""Returns a list of OpenAIFunction objects representing the+ def get_tools(self) -> List[FunctionTool]:+ r"""Returns a list of FunctionTool objects representing thefunctions in the toolkit.Returns:- List[OpenAIFunction]: A list of OpenAIFunction objects+ List[FunctionTool]: A list of FunctionTool objectsrepresenting the functions in the toolkit."""apinames_filepaths = self.generate_apinames_filepaths()@@ -539,6 +539,6 @@ class OpenAPIToolkit:self.apinames_filepaths_to_funs_schemas(apinames_filepaths))return [- OpenAIFunction(a_func, a_schema)+ FunctionTool(a_func, a_schema)for a_func, a_schema in zip(all_funcs_lst, all_schemas_lst)]diff --git a/camel/toolkits/reddit_toolkit.py b/camel/toolkits/reddit_toolkit.pyindex 5a9e7d5da..85df479ba 100644--- a/camel/toolkits/reddit_toolkit.py+++ b/camel/toolkits/reddit_toolkit.py@@ -18,7 +18,7 @@ from typing import Any, Dict, List, Unionfrom requests.exceptions import RequestException-from camel.toolkits import OpenAIFunction+from camel.toolkits import FunctionToolfrom camel.toolkits.base import BaseToolkit@@ -219,16 +219,16 @@ class RedditToolkit(BaseToolkit):data = self.perform_sentiment_analysis(data)return data- def get_tools(self) -> List[OpenAIFunction]:- r"""Returns a list of OpenAIFunction objects representing the+ def get_tools(self) -> List[FunctionTool]:+ r"""Returns a list of FunctionTool objects representing thefunctions in the toolkit.Returns:- List[OpenAIFunction]: A list of OpenAIFunction objects for the+ List[FunctionTool]: A list of FunctionTool objects for thetoolkit methods."""return [- OpenAIFunction(self.collect_top_posts),- OpenAIFunction(self.perform_sentiment_analysis),- OpenAIFunction(self.track_keyword_discussions),+ FunctionTool(self.collect_top_posts),+ FunctionTool(self.perform_sentiment_analysis),+ FunctionTool(self.track_keyword_discussions),]diff --git a/camel/toolkits/retrieval_toolkit.py b/camel/toolkits/retrieval_toolkit.pyindex 370b2c66a..c595d35a3 100644--- a/camel/toolkits/retrieval_toolkit.py+++ b/camel/toolkits/retrieval_toolkit.py@@ -14,7 +14,7 @@from typing import List, Optional, Unionfrom camel.retrievers import AutoRetriever-from camel.toolkits import OpenAIFunction+from camel.toolkits import FunctionToolfrom camel.toolkits.base import BaseToolkitfrom camel.types import StorageTypefrom camel.utils import Constants@@ -75,14 +75,14 @@ class RetrievalToolkit(BaseToolkit):)return str(retrieved_info)- def get_tools(self) -> List[OpenAIFunction]:- r"""Returns a list of OpenAIFunction objects representing the+ def get_tools(self) -> List[FunctionTool]:+ r"""Returns a list of FunctionTool objects representing thefunctions in the toolkit.Returns:- List[OpenAIFunction]: A list of OpenAIFunction objects+ List[FunctionTool]: A list of FunctionTool objectsrepresenting the functions in the toolkit."""return [- OpenAIFunction(self.information_retrieval),+ FunctionTool(self.information_retrieval),]diff --git a/camel/toolkits/search_toolkit.py b/camel/toolkits/search_toolkit.pyindex bac9423cb..c92add676 100644--- a/camel/toolkits/search_toolkit.py+++ b/camel/toolkits/search_toolkit.py@@ -15,7 +15,7 @@ import osfrom typing import Any, Dict, Listfrom camel.toolkits.base import BaseToolkit-from camel.toolkits.openai_function import OpenAIFunction+from camel.toolkits.function_tool import FunctionToolclass SearchToolkit(BaseToolkit):@@ -307,20 +307,20 @@ class SearchToolkit(BaseToolkit):return result.rstrip() # Remove trailing whitespace- def get_tools(self) -> List[OpenAIFunction]:- r"""Returns a list of OpenAIFunction objects representing the+ def get_tools(self) -> List[FunctionTool]:+ r"""Returns a list of FunctionTool objects representing thefunctions in the toolkit.Returns:- List[OpenAIFunction]: A list of OpenAIFunction objects+ List[FunctionTool]: A list of FunctionTool objectsrepresenting the functions in the toolkit."""return [- OpenAIFunction(self.search_wiki),- OpenAIFunction(self.search_google),- OpenAIFunction(self.search_duckduckgo),- OpenAIFunction(self.query_wolfram_alpha),+ FunctionTool(self.search_wiki),+ FunctionTool(self.search_google),+ FunctionTool(self.search_duckduckgo),+ FunctionTool(self.query_wolfram_alpha),]-SEARCH_FUNCS: List[OpenAIFunction] = SearchToolkit().get_tools()+SEARCH_FUNCS: List[FunctionTool] = SearchToolkit().get_tools()diff --git a/camel/toolkits/slack_toolkit.py b/camel/toolkits/slack_toolkit.pyindex f386397d4..2eb2c2446 100644--- a/camel/toolkits/slack_toolkit.py+++ b/camel/toolkits/slack_toolkit.py@@ -26,7 +26,7 @@ if TYPE_CHECKING:from slack_sdk import WebClient-from camel.toolkits import OpenAIFunction+from camel.toolkits import FunctionToollogger = logging.getLogger(__name__)@@ -286,20 +286,20 @@ class SlackToolkit(BaseToolkit):except SlackApiError as e:return f"Error creating conversation: {e.response['error']}"- def get_tools(self) -> List[OpenAIFunction]:- r"""Returns a list of OpenAIFunction objects representing the+ def get_tools(self) -> List[FunctionTool]:+ r"""Returns a list of FunctionTool objects representing thefunctions in the toolkit.Returns:- List[OpenAIFunction]: A list of OpenAIFunction objects+ List[FunctionTool]: A list of FunctionTool objectsrepresenting the functions in the toolkit."""return [- OpenAIFunction(self.create_slack_channel),- OpenAIFunction(self.join_slack_channel),- OpenAIFunction(self.leave_slack_channel),- OpenAIFunction(self.get_slack_channel_information),- OpenAIFunction(self.get_slack_channel_message),- OpenAIFunction(self.send_slack_message),- OpenAIFunction(self.delete_slack_message),+ FunctionTool(self.create_slack_channel),+ FunctionTool(self.join_slack_channel),+ FunctionTool(self.leave_slack_channel),+ FunctionTool(self.get_slack_channel_information),+ FunctionTool(self.get_slack_channel_message),+ FunctionTool(self.send_slack_message),+ FunctionTool(self.delete_slack_message),]diff --git a/camel/toolkits/twitter_toolkit.py b/camel/toolkits/twitter_toolkit.pyindex b5a744f89..9effa833a 100644--- a/camel/toolkits/twitter_toolkit.py+++ b/camel/toolkits/twitter_toolkit.py@@ -19,7 +19,7 @@ from typing import List, Optional, Tuple, Unionimport requests-from camel.toolkits import OpenAIFunction+from camel.toolkits import FunctionToolfrom camel.toolkits.base import BaseToolkitTWEET_TEXT_LIMIT = 280@@ -365,18 +365,18 @@ class TwitterToolkit(BaseToolkit):return user_report- def get_tools(self) -> List[OpenAIFunction]:- r"""Returns a list of OpenAIFunction objects representing the+ def get_tools(self) -> List[FunctionTool]:+ r"""Returns a list of FunctionTool objects representing thefunctions in the toolkit.Returns:- List[OpenAIFunction]: A list of OpenAIFunction objects+ List[FunctionTool]: A list of FunctionTool objectsrepresenting the functions in the toolkit."""return [- OpenAIFunction(self.create_tweet),- OpenAIFunction(self.delete_tweet),- OpenAIFunction(self.get_my_user_profile),+ FunctionTool(self.create_tweet),+ FunctionTool(self.delete_tweet),+ FunctionTool(self.get_my_user_profile),]def _get_twitter_api_key(self) -> Tuple[str, str]:diff --git a/camel/toolkits/weather_toolkit.py b/camel/toolkits/weather_toolkit.pyindex 72980da5a..84e795fbc 100644--- a/camel/toolkits/weather_toolkit.py+++ b/camel/toolkits/weather_toolkit.py@@ -15,7 +15,7 @@ import osfrom typing import List, Literalfrom camel.toolkits.base import BaseToolkit-from camel.toolkits.openai_function import OpenAIFunction+from camel.toolkits.function_tool import FunctionToolclass WeatherToolkit(BaseToolkit):@@ -157,17 +157,17 @@ class WeatherToolkit(BaseToolkit):)return error_message- def get_tools(self) -> List[OpenAIFunction]:- r"""Returns a list of OpenAIFunction objects representing the+ def get_tools(self) -> List[FunctionTool]:+ r"""Returns a list of FunctionTool objects representing thefunctions in the toolkit.Returns:- List[OpenAIFunction]: A list of OpenAIFunction objects+ List[FunctionTool]: A list of FunctionTool objectsrepresenting the functions in the toolkit."""return [- OpenAIFunction(self.get_weather_data),+ FunctionTool(self.get_weather_data),]-WEATHER_FUNCS: List[OpenAIFunction] = WeatherToolkit().get_tools()+WEATHER_FUNCS: List[FunctionTool] = WeatherToolkit().get_tools()diff --git a/camel/utils/async_func.py b/camel/utils/async_func.pyindex 377bca4f5..77caf4e9e 100644--- a/camel/utils/async_func.py+++ b/camel/utils/async_func.py@@ -14,20 +14,20 @@import asynciofrom copy import deepcopy-from camel.toolkits import OpenAIFunction+from camel.toolkits import FunctionTool-def sync_funcs_to_async(funcs: list[OpenAIFunction]) -> list[OpenAIFunction]:+def sync_funcs_to_async(funcs: list[FunctionTool]) -> list[FunctionTool]:r"""Convert a list of Python synchronous functions to Pythonasynchronous functions.Args:- funcs (list[OpenAIFunction]): List of Python synchronous- functions in the :obj:`OpenAIFunction` format.+ funcs (list[FunctionTool]): List of Python synchronous+ functions in the :obj:`FunctionTool` format.Returns:- list[OpenAIFunction]: List of Python asynchronous functions- in the :obj:`OpenAIFunction` format.+ list[FunctionTool]: List of Python asynchronous functions+ in the :obj:`FunctionTool` format."""async_funcs = []for func in funcs:@@ -37,6 +37,6 @@ def sync_funcs_to_async(funcs: list[OpenAIFunction]) -> list[OpenAIFunction]:return asyncio.to_thread(sync_func, *args, **kwargs) # noqa: B023async_funcs.append(- OpenAIFunction(async_callable, deepcopy(func.openai_tool_schema))+ FunctionTool(async_callable, deepcopy(func.openai_tool_schema)))return async_funcsdiff --git a/docs/camel.toolkits.rst b/docs/camel.toolkits.rstindex c5647e8fd..d8c134730 100644--- a/docs/camel.toolkits.rst+++ b/docs/camel.toolkits.rst@@ -71,7 +71,7 @@ camel.toolkits.open\_api\_toolkit modulecamel.toolkits.openai\_function module---------------------------------------.. automodule:: camel.toolkits.openai_function+.. automodule:: camel.toolkits.function_tool:members::undoc-members::show-inheritance:diff --git a/docs/key_modules/tools.md b/docs/key_modules/tools.mdindex d1b14e0ce..4018b7f9c 100644--- a/docs/key_modules/tools.md+++ b/docs/key_modules/tools.md@@ -14,7 +14,7 @@ To enhance your agents' capabilities with CAMEL tools, start by installing our apip install 'camel-ai[tools]'```-In CAMEL, a tool is an `OpenAIFunction` that LLMs can call.+In CAMEL, a tool is an `FunctionTool` that LLMs can call.### 2.1 How to Define Your Own Tool?@@ -22,7 +22,7 @@ In CAMEL, a tool is an `OpenAIFunction` that LLMs can call.Developers can create custom tools tailored to their agent’s specific needs:```python-from camel.toolkits import OpenAIFunction+from camel.toolkits import FunctionTooldef add(a: int, b: int) -> int:r"""Adds two numbers.@@ -36,7 +36,7 @@ def add(a: int, b: int) -> int:"""return a + b-add_tool = OpenAIFunction(add)+add_tool = FunctionTool(add)``````python@@ -105,8 +105,8 @@ To utilize specific tools from the toolkits, you can implement code like the fol```pythonfrom camel.toolkits import SearchToolkit-google_tool = OpenAIFunction(SearchToolkit().search_google)-wiki_tool = OpenAIFunction(SearchToolkit().search_wiki)+google_tool = FunctionTool(SearchToolkit().search_google)+wiki_tool = FunctionTool(SearchToolkit().search_wiki)```Here is a list of the available CAMEL tools and their descriptions:diff --git a/examples/function_call/github_examples.py b/examples/function_call/github_examples.pyindex 48ac5b5aa..833b0c712 100644--- a/examples/function_call/github_examples.py+++ b/examples/function_call/github_examples.py@@ -19,7 +19,7 @@ from camel.agents import ChatAgentfrom camel.configs import ChatGPTConfigfrom camel.messages import BaseMessagefrom camel.models import ModelFactory-from camel.toolkits import GithubToolkit, OpenAIFunction+from camel.toolkits import FunctionTool, GithubToolkitfrom camel.types import ModelPlatformType, ModelTypefrom camel.utils import print_text_animated@@ -70,7 +70,7 @@ def write_weekly_pr_summary(repo_name, model=None):agent = ChatAgent(assistant_sys_msg,model=assistant_model,- tools=[OpenAIFunction(toolkit.retrieve_pull_requests)],+ tools=[FunctionTool(toolkit.retrieve_pull_requests)],)agent.reset()diff --git a/examples/workforce/hackathon_judges.py b/examples/workforce/hackathon_judges.pyindex ed993b219..8aeb42216 100644--- a/examples/workforce/hackathon_judges.py+++ b/examples/workforce/hackathon_judges.py@@ -18,7 +18,7 @@ from camel.configs import ChatGPTConfigfrom camel.messages import BaseMessagefrom camel.models import ModelFactoryfrom camel.tasks import Task-from camel.toolkits import OpenAIFunction, SearchToolkit+from camel.toolkits import FunctionTool, SearchToolkitfrom camel.types import ModelPlatformType, ModelTypefrom camel.workforce import Workforce@@ -76,8 +76,8 @@ def main():search_toolkit = SearchToolkit()search_tools = [- OpenAIFunction(search_toolkit.search_google),- OpenAIFunction(search_toolkit.search_duckduckgo),+ FunctionTool(search_toolkit.search_google),+ FunctionTool(search_toolkit.search_duckduckgo),]researcher_model = ModelFactory.create(diff --git a/examples/workforce/multiple_single_agents.py b/examples/workforce/multiple_single_agents.pyindex 878bc6441..d18b50481 100644--- a/examples/workforce/multiple_single_agents.py+++ b/examples/workforce/multiple_single_agents.py@@ -19,8 +19,8 @@ from camel.models import ModelFactoryfrom camel.tasks.task import Taskfrom camel.toolkits import (WEATHER_FUNCS,+ FunctionTool,GoogleMapsToolkit,- OpenAIFunction,SearchToolkit,)from camel.types import ModelPlatformType, ModelType@@ -30,8 +30,8 @@ from camel.workforce import Workforcedef main():search_toolkit = SearchToolkit()search_tools = [- OpenAIFunction(search_toolkit.search_google),- OpenAIFunction(search_toolkit.search_duckduckgo),+ FunctionTool(search_toolkit.search_google),+ FunctionTool(search_toolkit.search_duckduckgo),]# Set up web searching agentdiff --git a/test/agents/test_chat_agent.py b/test/agents/test_chat_agent.pyindex 01f6860cc..ba5055d89 100644--- a/test/agents/test_chat_agent.py+++ b/test/agents/test_chat_agent.py@@ -33,8 +33,8 @@ from camel.messages import BaseMessagefrom camel.models import ModelFactoryfrom camel.terminators import ResponseWordsTerminatorfrom camel.toolkits import (+ FunctionTool,MathToolkit,- OpenAIFunction,SearchToolkit,)from camel.types import (@@ -554,7 +554,7 @@ async def test_tool_calling_async():agent = ChatAgent(system_message=system_message,model=model,- tools=[OpenAIFunction(async_sleep)],+ tools=[FunctionTool(async_sleep)],)assert len(agent.func_dict) == 1diff --git a/test/toolkits/test_openai_function.py b/test/toolkits/test_openai_function.pyindex 3df1b32a7..256345001 100644--- a/test/toolkits/test_openai_function.py+++ b/test/toolkits/test_openai_function.py@@ -19,7 +19,7 @@ from typing import Listimport pytestfrom jsonschema.exceptions import SchemaError-from camel.toolkits import OpenAIFunction, get_openai_tool_schema+from camel.toolkits import FunctionTool, get_openai_tool_schemafrom camel.types import RoleTypefrom camel.utils import get_pydantic_major_version@@ -336,13 +336,13 @@ tool_schema = {def test_correct_function():- add = OpenAIFunction(add_with_doc)+ add = FunctionTool(add_with_doc)add.set_function_name("add")assert add.get_openai_function_schema() == function_schemadef test_function_without_doc():- add = OpenAIFunction(add_without_doc)+ add = FunctionTool(add_without_doc)add.set_function_name("add")with pytest.raises(Exception, match="miss function description"):_ = add.get_openai_function_schema()@@ -351,7 +351,7 @@ def test_function_without_doc():def test_function_with_wrong_doc():- add = OpenAIFunction(add_with_wrong_doc)+ add = FunctionTool(add_with_wrong_doc)add.set_function_name("add")with pytest.raises(Exception, match="miss description of parameter \"b\""):_ = add.get_openai_function_schema()@@ -360,11 +360,11 @@ def test_function_with_wrong_doc():def test_validate_openai_tool_schema_valid():- OpenAIFunction.validate_openai_tool_schema(tool_schema)+ FunctionTool.validate_openai_tool_schema(tool_schema)def test_get_set_openai_tool_schema():- add = OpenAIFunction(add_with_doc)+ add = FunctionTool(add_with_doc)assert add.get_openai_tool_schema() is not Nonenew_schema = copy.deepcopy(tool_schema)new_schema["function"]["description"] = "New description"@@ -373,20 +373,20 @@ def test_get_set_openai_tool_schema():def test_get_set_parameter_description():- add = OpenAIFunction(add_with_doc)+ add = FunctionTool(add_with_doc)assert add.get_paramter_description("a") == "The first number to be added."add.set_paramter_description("a", "New description for a.")assert add.get_paramter_description("a") == "New description for a."def test_get_set_parameter_description_non_existing():- add = OpenAIFunction(add_with_doc)+ add = FunctionTool(add_with_doc)with pytest.raises(KeyError):add.get_paramter_description("non_existing")def test_get_set_openai_function_schema():- add = OpenAIFunction(add_with_doc)+ add = FunctionTool(add_with_doc)initial_schema = add.get_openai_function_schema()assert initial_schema is not None@@ -400,7 +400,7 @@ def test_get_set_openai_function_schema():def test_get_set_function_name():- add = OpenAIFunction(add_with_doc)+ add = FunctionTool(add_with_doc)assert add.get_function_name() == "add_with_doc"add.set_function_name("new_add")@@ -408,7 +408,7 @@ def test_get_set_function_name():def test_get_set_function_description():- add = OpenAIFunction(add_with_doc)+ add = FunctionTool(add_with_doc)initial_description = add.get_function_description()assert initial_description is not None@@ -418,7 +418,7 @@ def test_get_set_function_description():def test_get_set_parameter():- add = OpenAIFunction(add_with_doc)+ add = FunctionTool(add_with_doc)initial_param_schema = add.get_parameter("a")assert initial_param_schema is not None@@ -431,7 +431,7 @@ def test_get_set_parameter():def test_parameters_getter_setter():- add = OpenAIFunction(add_with_doc)+ add = FunctionTool(add_with_doc)initial_params = add.parametersassert initial_params is not Nonediff --git a/test/toolkits/test_reddit_functions.py b/test/toolkits/test_reddit_functions.pyindex 149b749b6..64c1370a1 100644--- a/test/toolkits/test_reddit_functions.py+++ b/test/toolkits/test_reddit_functions.py@@ -120,8 +120,8 @@ def test_track_keyword_discussions(reddit_toolkit):def test_get_tools(reddit_toolkit):- from camel.toolkits import OpenAIFunction+ from camel.toolkits import FunctionTooltools = reddit_toolkit.get_tools()assert len(tools) == 3- assert all(isinstance(tool, OpenAIFunction) for tool in tools)+ assert all(isinstance(tool, FunctionTool) for tool in tools)