🐫 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
Modify `ChatAgent` function call args json and make slack sdk optional (#661)
Zecheng Zhang28621b5552a4
diff --git a/camel/agents/chat_agent.py b/camel/agents/chat_agent.pyindex 805df53cb..e54937ab5 100644--- a/camel/agents/chat_agent.py+++ b/camel/agents/chat_agent.py@@ -643,7 +643,7 @@ class ChatAgent(BaseAgent):func = self.func_dict[func_name]args_str: str = choice.message.tool_calls[0].function.arguments- args = json.loads(args_str.replace("'", "\""))+ args = json.loads(args_str)# Pass the extracted arguments to the indicated functiontry:@@ -702,7 +702,7 @@ class ChatAgent(BaseAgent):func = self.func_dict[func_name]args_str: str = choice.message.tool_calls[0].function.arguments- args = json.loads(args_str.replace("'", "\""))+ args = json.loads(args_str)# Pass the extracted arguments to the indicated functiontry:diff --git a/camel/functions/open_api_function.py b/camel/functions/open_api_function.pyindex b4211553b..bf77829e2 100644--- a/camel/functions/open_api_function.py+++ b/camel/functions/open_api_function.py@@ -13,16 +13,15 @@# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========import jsonimport os-from typing import Any, Callable, Dict, List, Tuple+from typing import Any, Callable, Dict, List, Optional, Tuple-import pranceimport requestsfrom camel.functions import OpenAIFunction, openapi_security_configfrom camel.types import OpenAPIName-def parse_openapi_file(openapi_spec_path: str) -> Dict[str, Any]:+def parse_openapi_file(openapi_spec_path: str) -> Optional[Dict[str, Any]]:r"""Load and parse an OpenAPI specification file.This function utilizes the `prance.ResolvingParser` to parse and resolve@@ -34,8 +33,14 @@ def parse_openapi_file(openapi_spec_path: str) -> Dict[str, Any]:specification.Returns:- Dict[str, Any]: The parsed OpenAPI specification as a dictionary.+ Optional[Dict[str, Any]]: The parsed OpenAPI specification+ as a dictionary. :obj:`None` if the package is not installed."""+ try:+ import prance+ except Exception:+ return None+# Load the OpenAPI specparser = prance.ResolvingParser(openapi_spec_path, backend="openapi-spec-validator", strict=False@@ -451,6 +456,8 @@ def apinames_filepaths_to_funs_schemas()openapi_spec = parse_openapi_file(file_path)+ if openapi_spec is None:+ return [], []# Generate and merge function schemasopenapi_functions_schemas = openapi_spec_to_openai_schemas(diff --git a/camel/functions/slack_functions.py b/camel/functions/slack_functions.pyindex 114cc3057..bf2e58aba 100644--- a/camel/functions/slack_functions.py+++ b/camel/functions/slack_functions.py@@ -24,8 +24,6 @@ if TYPE_CHECKING:from slack_sdk import WebClient-from slack_sdk.errors import SlackApiError-from camel.functions import OpenAIFunctionlogger = logging.getLogger(__name__)@@ -89,6 +87,8 @@ def create_slack_channel(name: str, is_private: Optional[bool] = True) -> str:SlackApiError: If there is an error during get slack channelinformation."""+ from slack_sdk.errors import SlackApiError+try:slack_client = _login_slack()response = slack_client.conversations_create(@@ -115,6 +115,8 @@ def join_slack_channel(channel_id: str) -> str:SlackApiError: If there is an error during get slack channelinformation."""+ from slack_sdk.errors import SlackApiError+try:slack_client = _login_slack()response = slack_client.conversations_join(channel=channel_id)@@ -137,6 +139,8 @@ def leave_slack_channel(channel_id: str) -> str:SlackApiError: If there is an error during get slack channelinformation."""+ from slack_sdk.errors import SlackApiError+try:slack_client = _login_slack()response = slack_client.conversations_leave(channel=channel_id)@@ -155,6 +159,8 @@ def get_slack_channel_information() -> str:SlackApiError: If there is an error during get slack channelinformation."""+ from slack_sdk.errors import SlackApiError+try:slack_client = _login_slack()response = slack_client.conversations_list()@@ -189,6 +195,8 @@ def get_slack_channel_message(channel_id: str) -> str:Raises:SlackApiError: If there is an error during get slack channel message."""+ from slack_sdk.errors import SlackApiError+try:slack_client = _login_slack()result = slack_client.conversations_history(channel=channel_id)@@ -222,6 +230,8 @@ def send_slack_message(Raises:SlackApiError: If an error occurs while sending the message."""+ from slack_sdk.errors import SlackApiError+try:slack_client = _login_slack()if user:@@ -254,6 +264,8 @@ def delete_slack_message(Raises:SlackApiError: If an error occurs while sending the message."""+ from slack_sdk.errors import SlackApiError+try:slack_client = _login_slack()response = slack_client.chat_delete(channel=channel_id, ts=time_stamp)