diff --git a/camel/agents/chat_agent.py b/camel/agents/chat_agent.py index 805df53cb4..e54937ab53 100644 --- a/camel/agents/chat_agent.py +++ b/camel/agents/chat_agent.py @@ -643,7 +643,7 @@ def step_tool_call( 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 function try: @@ -702,7 +702,7 @@ async def step_tool_call_async( 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 function try: diff --git a/camel/functions/open_api_function.py b/camel/functions/open_api_function.py index b4211553b2..bf77829e24 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 json import os -from typing import Any, Callable, Dict, List, Tuple +from typing import Any, Callable, Dict, List, Optional, Tuple -import prance import requests from camel.functions import OpenAIFunction, openapi_security_config from 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 spec parser = 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 schemas openapi_functions_schemas = openapi_spec_to_openai_schemas( diff --git a/camel/functions/slack_functions.py b/camel/functions/slack_functions.py index 114cc30572..bf2e58abae 100644 --- a/camel/functions/slack_functions.py +++ b/camel/functions/slack_functions.py @@ -24,8 +24,6 @@ from slack_sdk import WebClient -from slack_sdk.errors import SlackApiError - from camel.functions import OpenAIFunction logger = 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 channel information. """ + 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 channel information. """ + 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 channel information. """ + 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 channel information. """ + 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)