🐫 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: Add Dappier toolkit (#1393)
Amaanbfd2a71851cd
diff --git a/.env b/.envindex 1a1136e34..ff2e979ea 100644--- a/.env+++ b/.env@@ -81,3 +81,6 @@# Meshy API (https://www.meshy.ai/api)# MESHY_API_KEY="Fill your API key here"++# Dappier API (https://api.dappier.com/)+# DAPPIER_API_KEY="Fill your API key here"diff --git a/.github/workflows/build_package.yml b/.github/workflows/build_package.ymlindex 60d164901..90513eb64 100644--- a/.github/workflows/build_package.yml+++ b/.github/workflows/build_package.yml@@ -76,6 +76,7 @@ jobs:QWEN_API_KEY: "${{ secrets.QWEN_API_KEY }}"GEMINI_API_KEY: "${{ secrets.GEMINI_API_KEY }}"DEEPSEEK_API_KEY: "${{ secrets.DEEPSEEK_API_KEY }}"+ DAPPIER_API_KEY: "${{ secrets.DAPPIER_API_KEY }}"run: |source venv/bin/activatepytest --fast-test-mode ./testdiff --git a/.github/workflows/pytest_package.yml b/.github/workflows/pytest_package.ymlindex b22e96046..e4c884902 100644--- a/.github/workflows/pytest_package.yml+++ b/.github/workflows/pytest_package.yml@@ -55,6 +55,7 @@ jobs:QWEN_API_KEY: "${{ secrets.QWEN_API_KEY }}"GEMINI_API_KEY: "${{ secrets.GEMINI_API_KEY }}"DEEPSEEK_API_KEY: "${{ secrets.DEEPSEEK_API_KEY }}"+ DAPPIER_API_KEY: "${{ secrets.DAPPIER_API_KEY }}"run: poetry run pytest --fast-test-mode test/pytest_package_llm_test:@@ -99,6 +100,7 @@ jobs:QWEN_API_KEY: "${{ secrets.QWEN_API_KEY }}"GEMINI_API_KEY: "${{ secrets.GEMINI_API_KEY }}"DEEPSEEK_API_KEY: "${{ secrets.DEEPSEEK_API_KEY }}"+ DAPPIER_API_KEY: "${{ secrets.DAPPIER_API_KEY }}"run: poetry run pytest --llm-test-only test/pytest_package_very_slow_test:@@ -143,4 +145,5 @@ jobs:QWEN_API_KEY: "${{ secrets.QWEN_API_KEY }}"GEMINI_API_KEY: "${{ secrets.GEMINI_API_KEY }}"DEEPSEEK_API_KEY: "${{ secrets.DEEPSEEK_API_KEY }}"+ DAPPIER_API_KEY: "${{ secrets.DAPPIER_API_KEY }}"run: poetry run pytest --very-slow-test-only test/diff --git a/camel/toolkits/__init__.py b/camel/toolkits/__init__.pyindex 29aaca3d2..30909f9f4 100644--- a/camel/toolkits/__init__.py+++ b/camel/toolkits/__init__.py@@ -44,6 +44,7 @@ from .notion_toolkit import NotionToolkitfrom .human_toolkit import HumanToolkitfrom .stripe_toolkit import StripeToolkitfrom .video_toolkit import VideoDownloaderToolkit+from .dappier_toolkit import DappierToolkit__all__ = ['BaseToolkit',@@ -75,4 +76,5 @@ __all__ = ['StripeToolkit','MeshyToolkit','OpenBBToolkit',+ 'DappierToolkit',]diff --git a/camel/toolkits/dappier_toolkit.py b/camel/toolkits/dappier_toolkit.pynew file mode 100644index 000000000..6eb0c814e--- /dev/null+++ b/camel/toolkits/dappier_toolkit.py@@ -0,0 +1,197 @@+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+import os+from typing import Dict, List, Literal, Optional, Union++from camel.toolkits.base import BaseToolkit+from camel.toolkits.function_tool import FunctionTool+from camel.utils import api_keys_required, dependencies_required+++class DappierToolkit(BaseToolkit):+ r"""A class representing a toolkit for interacting with the Dappier API.++ This class provides methods for searching real time data and fetching+ ai recommendations across key verticals like News, Finance, Stock Market,+ Sports, Weather and more.+ """++ @dependencies_required("dappier")+ @api_keys_required(+ [+ (None, "DAPPIER_API_KEY"),+ ]+ )+ def __init__(self):+ r"""Initialize the DappierTookit with API clients.The API keys and+ credentials are retrieved from environment variables.+ """+ from dappier import Dappier++ dappier_api_key = os.environ.get("DAPPIER_API_KEY")++ self.dappier_client = Dappier(dappier_api_key)++ def search_real_time_data(+ self, query: str, ai_model_id: str = "am_01j06ytn18ejftedz6dyhz2b15"+ ) -> str:+ r"""Search real-time data using an AI model.++ This function accesses real-time information using the specified+ AI model based on the given query. Depending on the AI model ID,+ the data retrieved can vary between general web search results or+ financial news and stock prices.++ Supported AI Models:+ - `am_01j06ytn18ejftedz6dyhz2b15`:+ Access real-time Google web search results, including the latest+ news, weather updates, travel details, deals, and more.+ - `am_01j749h8pbf7ns8r1bq9s2evrh`:+ Access real-time financial news, stock prices, and trades from+ polygon.io, with AI-powered insights and up-to-the-minute updates.++ Note:+ Multiple AI model IDs are available, which can be found at:+ https://marketplace.dappier.com/marketplace++ Args:+ query (str): The user-provided query. Examples include:+ - "How is the weather today in Austin, TX?"+ - "What is the latest news for Meta?"+ - "What is the stock price for AAPL?"+ ai_model_id (str, optional): The AI model ID to use for the query.+ Defaults to "am_01j06ytn18ejftedz6dyhz2b15". The AI model ID+ always starts with the prefix "am_".++ Returns:+ str: The search result corresponding to the provided query and+ AI model ID. This may include real time search data,+ depending on the selected AI model.+ """+ try:+ response = self.dappier_client.search_real_time_data(+ query=query, ai_model_id=ai_model_id+ )++ if response is None:+ return "An unknown error occurred"++ return response.message++ except Exception as e:+ return f"An unexpected error occurred: {e}"++ def get_ai_recommendations(+ self,+ query: str,+ data_model_id: str = "dm_01j0pb465keqmatq9k83dthx34",+ similarity_top_k: int = 9,+ ref: Optional[str] = None,+ num_articles_ref: int = 0,+ search_algorithm: Literal[+ "most_recent", "semantic", "most_recent_semantic", "trending"+ ] = "most_recent",+ ) -> Union[List[Dict[str, str]], Dict[str, str]]:+ r"""Retrieve AI-powered recommendations based on the provided query+ and data model.++ This function fetches real-time AI-generated recommendations using the+ specified data model and search algorithm. The results include+ personalized content based on the query and, optionally, relevance+ to a specific reference domain.++ Supported Data Models:+ - `dm_01j0pb465keqmatq9k83dthx34`:+ Real-time news, updates, and personalized content from top sports+ sources such as Sportsnaut, Forever Blueshirts, Minnesota Sports+ Fan, LAFB Network, Bounding Into Sports, and Ringside Intel.+ - `dm_01j0q82s4bfjmsqkhs3ywm3x6y`:+ Real-time updates, analysis, and personalized content from top+ sources like The Mix, Snipdaily, Nerdable, and Familyproof.++ Note:+ Multiple data model IDs are available and can be found at:+ https://marketplace.dappier.com/marketplace++ Args:+ query (str): The user query for retrieving recommendations.+ data_model_id (str, optional): The data model ID to use for+ recommendations.+ Defaults to "dm_01j0pb465keqmatq9k83dthx34". Data model IDs+ always start with the prefix "dm_".+ similarity_top_k (int, optional): The number of top documents to+ retrieve based on similarity. Defaults to 9.+ ref (Optional[str], optional): The site domain where AI+ recommendations should be displayed. Defaults to None.+ num_articles_ref (int, optional): The minimum number of articles+ to return from the specified reference domain (`ref`).+ The remaining articles will come from other sites in the RAG+ model. Defaults to 0.+ search_algorithm (Literal[+ "most_recent",+ "semantic",+ "most_recent_semantic",+ "trending"+ ], optional): The search algorithm to use for retrieving articles.+ Defaults to "most_recent".++ Returns:+ List[Dict[str, str]]: A list of recommended articles or content+ based on the specified parameters, query, and data model.+ """+ try:+ response = self.dappier_client.get_ai_recommendations(+ query=query,+ data_model_id=data_model_id,+ similarity_top_k=similarity_top_k,+ ref=ref,+ num_articles_ref=num_articles_ref,+ search_algorithm=search_algorithm,+ )++ if response is None or response.status != "success":+ return {"error": "An unknown error occurred."}++ # Collect only relevant information from the response.+ results = [+ {+ "author": result.author,+ "image_url": result.image_url,+ "pubdate": result.pubdate,+ "source_url": result.source_url,+ "summary": result.summary,+ "title": result.title,+ }+ for result in (+ getattr(response.response, "results", None) or []+ )+ ]++ return results++ except Exception as e:+ return {"error": f"An unexpected error occurred: {e!s}"}++ def get_tools(self) -> List[FunctionTool]:+ r"""Returns a list of FunctionTool objects representing the functions+ in the toolkit.++ Returns:+ List[FunctionTool]: A list of FunctionTool objects representing+ the functions in the toolkit.+ """+ return [+ FunctionTool(self.search_real_time_data),+ FunctionTool(self.get_ai_recommendations),+ ]diff --git a/examples/toolkits/dappier_toolkit.py b/examples/toolkits/dappier_toolkit.pynew file mode 100644index 000000000..735a7c5e2--- /dev/null+++ b/examples/toolkits/dappier_toolkit.py@@ -0,0 +1,136 @@+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========++from camel.agents import ChatAgent+from camel.toolkits import DappierToolkit, FunctionTool++real_time_data_response = DappierToolkit().search_real_time_data(+ query="camel-ai"+)++print(real_time_data_response)+"""+CAMEL-AI is pretty cool! It's the first LLM (Large Language Model) multi-agent+framework and an open-source community focused on exploring the scaling laws+of agents. 🌟++Here are some highlights:++- **Purpose**: It aims to create highly customizable intelligent agents and+ build multi-agent systems for real-world applications.+- **Features**: CAMEL provides a role-playing approach and inception prompting+ to help chat agents complete tasks aligned with human intentions.+- **Use Cases**: You can turn your database into an AI-powered data analyst,+ allowing you to ask questions in plain English and get instant insights.+ 📊🤖+- **Community**: It's an open-source initiative, so developers can contribute+ and collaborate on building and using LLM-based agents.++If you want to dive deeper, check out their website:+[CAMEL-AI.org](https://www.camel-ai.org) 🚀!+"""++# Use a different AI model which has access to real-time financial news.+real_time_data_response = DappierToolkit().search_real_time_data(+ query="Could you please provide the stock price for Google on 05/03/24?",+ ai_model_id="am_01j749h8pbf7ns8r1bq9s2evrh",+)+print(real_time_data_response)+"""+The stock price for Google (GOOGL) on May 3rd, 2024, was $167.10.+"""++# Example with ChatAgent using the Real Time Search.+agent = ChatAgent(+ system_message="""You are a helpful assistant that can use brave search+ engine to answer questions.""",+ tools=[FunctionTool(DappierToolkit().search_real_time_data)],+)++usr_msg = "What is the temperature in Tokyo?"++response = agent.step(input_message=usr_msg, response_format=None)++print(response.msgs[0].content)+"""+The current temperature in Tokyo is 50°F (about 10°C). It's a bit chilly,+so you might want to grab a jacket! 🧥🌬️+"""++ai_recommendations_response = DappierToolkit().get_ai_recommendations(+ query="latest sports news",+ data_model_id="dm_01j0pb465keqmatq9k83dthx34",+ similarity_top_k=3,+ ref="sportsnaut.com",+ num_articles_ref=2,+ search_algorithm="most_recent",+)+print(ai_recommendations_response)+"""+{'author': 'Andrew Buller-Russ',+'image_url': 'https://images.dappier.com/dm_01j0pb465keqmatq9k83dthx34/+Syndication-Detroit-Free-Press-25087075_.jpg?width=428&height=321',+'pubdate': 'Thu, 02 Jan 2025 03:12:06 +0000',+'source_url': 'https://sportsnaut.com/nick-bosa-detroit-lions-trade-rumors-49ers/',+'summary': 'In a thrilling Monday night game, the Detroit Lions triumphed+over the San Francisco 49ers 40-34, solidifying their status as a top NFL+team. Despite a strong performance from Nick Bosa, who recorded eight tackles+and two sacks, the 49ers\' playoff hopes were dashed. Bosa praised the Lions\'+competitive spirit and resilience under Coach Dan Campbell, sparking+about his interest in joining the team, although he remains under contract+with the 49ers for four more seasons. Bosa\'s admiration for the Lions+highlights the stark contrast between the two franchises\' fortunes,+with the Lions celebrating a significant victory while the 49ers struggle.+Having experienced playoff success with the 49ers, Bosa values strong+leadership from both Campbell and his own coach, Kyle Shanahan. His comments+reflect a broader sentiment in the NFL about the importance of winning and+the positive environment it fosters for players.',+'title': 'Nick Bosa gushes about Detroit Lions, sparking 49ers trade rumors'}++{'author': 'Andrew Buller-Russ',+'image_url': 'https://images.dappier.com/dm_01j0pb465keqmatq9k83dthx34/+Baseball-World-Baseball-Classic-Semifinal-Japan-vs-Mexico-20279015_.jpg?width=428&height=321',+'pubdate': 'Thu, 02 Jan 2025 02:43:38 +0000',+'source_url': 'https://www.lafbnetwork.com/los-angeles-dodgers/+los-angeles-dodgers-news/los-angeles-dodgers-meeting-roki-sasaki/',+'summary': 'Roki Sasaki, a talented 23-year-old Japanese pitcher, is+approaching a decision on his MLB free agency, with the Los Angeles Dodgers+among the frontrunners to sign him. They are competing against teams like+the Chicago Cubs, New York Mets, and others. The Dodgers are set to meet+with Sasaki, emphasizing his signing as a top priority despite facing+competition from around 20 other teams. Sasaki\'s status as a minor-league+posting player may allow him to be signed at a more affordable price,+increasing his appeal. As he gathers information and prepares for a second+round of meetings, the Dodgers are keen to secure him before the posting+window closes on January 24, with the international signing period beginning+on January 15.', 'title': 'Los Angeles Dodgers Take Another Step Toward+Signing Roki Sasaki'}++{'author': 'Andrew Buller-Russ',+'image_url': 'https://images.dappier.com/dm_01j0pb465keqmatq9k83dthx34/+NFL-Detroit-Lions-at-Kansas-City-Chiefs-24020812_.jpg?width=428&height=321',+'pubdate': 'Thu, 02 Jan 2025 02:08:34 +0000',+'source_url': 'https://sportsnaut.com/detroit-lions-cut-jamal-adams/',+'summary': 'The Detroit Lions, with a strong 14-2 record, have released+former All-Pro safety Jamal Adams from their practice squad ahead of a crucial+Week 18 game against the Minnesota Vikings. Adams, who joined the Lions on+December 1, 2024, played in two games but recorded only three tackles in+20 defensive snaps, representing a mere 17% of the team\'s defensive plays.+This marks Adams\' second release this season, having previously been cut+by the Tennessee Titans after three appearances. The Lions\' decision to part+ways with Adams comes as they focus on their playoff positioning for the+upcoming game.',+'title': 'Detroit Lions cut bait with All-Pro ahead of Week 18 matchup with+Vikings'}+"""diff --git a/poetry.lock b/poetry.lockindex 7a417e68b..677503f99 100644--- a/poetry.lock+++ b/poetry.lock@@ -530,6 +530,19 @@ files = [{file = "async_timeout-5.0.1.tar.gz", hash = "sha256:d9321a7a3d5a6a5e187e824d2fa0793ce379a202935782d555d6e9d2735677d3"},]+[[package]]+name = "asyncio"+version = "3.4.3"+description = "reference implementation of PEP 3156"+optional = true+python-versions = "*"+files = [+ {file = "asyncio-3.4.3-cp33-none-win32.whl", hash = "sha256:b62c9157d36187eca799c378e572c969f0da87cd5fc42ca372d92cdb06e7e1de"},+ {file = "asyncio-3.4.3-cp33-none-win_amd64.whl", hash = "sha256:c46a87b48213d7464f22d9a497b9eef8c1928b68320a2fa94240f969f6fec08c"},+ {file = "asyncio-3.4.3-py3-none-any.whl", hash = "sha256:c4d18b22701821de07bd6aea8b53d21449ec0ec5680645e5317062ea21817d2d"},+ {file = "asyncio-3.4.3.tar.gz", hash = "sha256:83360ff8bc97980e4ff25c964c7bd3923d333d177aa4f7fb736b019f26c7cb41"},+]+[[package]]name = "attrs"version = "24.3.0"@@ -1466,6 +1479,22 @@ files = [docs = ["ipython", "matplotlib", "numpydoc", "sphinx"]tests = ["pytest", "pytest-cov", "pytest-xdist"]+[[package]]+name = "dappier"+version = "0.3.3"+description = "The Dappier Python SDK provides an easy-to-use interface for interacting with the Dappier API."+optional = true+python-versions = "<4.0,>=3.9"+files = [+ {file = "dappier-0.3.3-py3-none-any.whl", hash = "sha256:05390cca61235d592aacc35b521cc5eb927a9954b786b390d1d7609a6ef79f20"},+ {file = "dappier-0.3.3.tar.gz", hash = "sha256:0e0e1e9ce91f550e20d9e2d86a6121c1497f1004ab72bc85222f49bb3ac5d6e0"},+]++[package.dependencies]+asyncio = ">=3.4.3,<4.0.0"+httpx = ">=0.23.0,<0.29.0"+pydantic = ">=1.9,<3.0.0"+[[package]]name = "dataclasses-json"version = "0.6.7"@@ -7371,6 +7400,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"},]@@ -7381,6 +7411,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"},]@@ -7738,6 +7769,7 @@ python-versions = ">=3.9"files = [{file = "pymupdf-1.25.1-cp39-abi3-macosx_10_9_x86_64.whl", hash = "sha256:793f9f6d51029e97851c711b3f6d9fe912313d95a306fbe8b1866f301d0e2bd3"},{file = "pymupdf-1.25.1-cp39-abi3-macosx_11_0_arm64.whl", hash = "sha256:15e6f4013ad0a029a2221920f9d2081f56dc43259dabfdf5cad7fbf1cee4b5a7"},+ {file = "pymupdf-1.25.1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:a39afbd80381f43e30d6eb2ec4613f465f507ac2b76070abdd2da8724f32ef36"},{file = "pymupdf-1.25.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:b63f8e9e65b0bda48f9217efd4d2a8c6d7a739dd28baf460c1ae78439b9af489"},{file = "pymupdf-1.25.1-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:a687bd387589e30abd810a78a23341f57f43fa16a4d8d8c0b870bb6d89607343"},{file = "pymupdf-1.25.1-cp39-abi3-win32.whl", hash = "sha256:fc7dbc1aa9e298a4c81084e389c9623c26fcaa232c71efaa073af150069e2221"},@@ -8924,6 +8956,7 @@ files = [{file = "ruamel.yaml.clib-0.2.12-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f66efbc1caa63c088dead1c4170d148eabc9b80d95fb75b6c92ac0aad2437d76"},{file = "ruamel.yaml.clib-0.2.12-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:22353049ba4181685023b25b5b51a574bce33e7f51c759371a7422dcae5402a6"},{file = "ruamel.yaml.clib-0.2.12-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:932205970b9f9991b34f55136be327501903f7c66830e9760a8ffb15b07f05cd"},+ {file = "ruamel.yaml.clib-0.2.12-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:a52d48f4e7bf9005e8f0a89209bf9a73f7190ddf0489eee5eb51377385f59f2a"},{file = "ruamel.yaml.clib-0.2.12-cp310-cp310-win32.whl", hash = "sha256:3eac5a91891ceb88138c113f9db04f3cebdae277f5d44eaa3651a4f573e6a5da"},{file = "ruamel.yaml.clib-0.2.12-cp310-cp310-win_amd64.whl", hash = "sha256:ab007f2f5a87bd08ab1499bdf96f3d5c6ad4dcfa364884cb4549aa0154b13a28"},{file = "ruamel.yaml.clib-0.2.12-cp311-cp311-macosx_13_0_arm64.whl", hash = "sha256:4a6679521a58256a90b0d89e03992c15144c5f3858f40d7c18886023d7943db6"},@@ -8932,6 +8965,7 @@ files = [{file = "ruamel.yaml.clib-0.2.12-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:811ea1594b8a0fb466172c384267a4e5e367298af6b228931f273b111f17ef52"},{file = "ruamel.yaml.clib-0.2.12-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:cf12567a7b565cbf65d438dec6cfbe2917d3c1bdddfce84a9930b7d35ea59642"},{file = "ruamel.yaml.clib-0.2.12-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:7dd5adc8b930b12c8fc5b99e2d535a09889941aa0d0bd06f4749e9a9397c71d2"},+ {file = "ruamel.yaml.clib-0.2.12-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:1492a6051dab8d912fc2adeef0e8c72216b24d57bd896ea607cb90bb0c4981d3"},{file = "ruamel.yaml.clib-0.2.12-cp311-cp311-win32.whl", hash = "sha256:bd0a08f0bab19093c54e18a14a10b4322e1eacc5217056f3c063bd2f59853ce4"},{file = "ruamel.yaml.clib-0.2.12-cp311-cp311-win_amd64.whl", hash = "sha256:a274fb2cb086c7a3dea4322ec27f4cb5cc4b6298adb583ab0e211a4682f241eb"},{file = "ruamel.yaml.clib-0.2.12-cp312-cp312-macosx_14_0_arm64.whl", hash = "sha256:20b0f8dc160ba83b6dcc0e256846e1a02d044e13f7ea74a3d1d56ede4e48c632"},@@ -8940,6 +8974,7 @@ files = [{file = "ruamel.yaml.clib-0.2.12-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:749c16fcc4a2b09f28843cda5a193e0283e47454b63ec4b81eaa2242f50e4ccd"},{file = "ruamel.yaml.clib-0.2.12-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:bf165fef1f223beae7333275156ab2022cffe255dcc51c27f066b4370da81e31"},{file = "ruamel.yaml.clib-0.2.12-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:32621c177bbf782ca5a18ba4d7af0f1082a3f6e517ac2a18b3974d4edf349680"},+ {file = "ruamel.yaml.clib-0.2.12-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:b82a7c94a498853aa0b272fd5bc67f29008da798d4f93a2f9f289feb8426a58d"},{file = "ruamel.yaml.clib-0.2.12-cp312-cp312-win32.whl", hash = "sha256:e8c4ebfcfd57177b572e2040777b8abc537cdef58a2120e830124946aa9b42c5"},{file = "ruamel.yaml.clib-0.2.12-cp312-cp312-win_amd64.whl", hash = "sha256:0467c5965282c62203273b838ae77c0d29d7638c8a4e3a1c8bdd3602c10904e4"},{file = "ruamel.yaml.clib-0.2.12-cp313-cp313-macosx_14_0_arm64.whl", hash = "sha256:4c8c5d82f50bb53986a5e02d1b3092b03622c02c2eb78e29bec33fd9593bae1a"},@@ -8948,6 +8983,7 @@ files = [{file = "ruamel.yaml.clib-0.2.12-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:96777d473c05ee3e5e3c3e999f5d23c6f4ec5b0c38c098b3a5229085f74236c6"},{file = "ruamel.yaml.clib-0.2.12-cp313-cp313-musllinux_1_1_i686.whl", hash = "sha256:3bc2a80e6420ca8b7d3590791e2dfc709c88ab9152c00eeb511c9875ce5778bf"},{file = "ruamel.yaml.clib-0.2.12-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:e188d2699864c11c36cdfdada94d781fd5d6b0071cd9c427bceb08ad3d7c70e1"},+ {file = "ruamel.yaml.clib-0.2.12-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:4f6f3eac23941b32afccc23081e1f50612bdbe4e982012ef4f5797986828cd01"},{file = "ruamel.yaml.clib-0.2.12-cp313-cp313-win32.whl", hash = "sha256:6442cb36270b3afb1b4951f060eccca1ce49f3d087ca1ca4563a6eb479cb3de6"},{file = "ruamel.yaml.clib-0.2.12-cp313-cp313-win_amd64.whl", hash = "sha256:e5b8daf27af0b90da7bb903a876477a9e6d7270be6146906b276605997c7e9a3"},{file = "ruamel.yaml.clib-0.2.12-cp39-cp39-macosx_12_0_arm64.whl", hash = "sha256:fc4b630cd3fa2cf7fce38afa91d7cfe844a9f75d7f0f36393fa98815e911d987"},@@ -8956,6 +8992,7 @@ files = [{file = "ruamel.yaml.clib-0.2.12-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e2f1c3765db32be59d18ab3953f43ab62a761327aafc1594a2a1fbe038b8b8a7"},{file = "ruamel.yaml.clib-0.2.12-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:d85252669dc32f98ebcd5d36768f5d4faeaeaa2d655ac0473be490ecdae3c285"},{file = "ruamel.yaml.clib-0.2.12-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:e143ada795c341b56de9418c58d028989093ee611aa27ffb9b7f609c00d813ed"},+ {file = "ruamel.yaml.clib-0.2.12-cp39-cp39-musllinux_1_2_aarch64.whl", hash = "sha256:2c59aa6170b990d8d2719323e628aaf36f3bfbc1c26279c0eeeb24d05d2d11c7"},{file = "ruamel.yaml.clib-0.2.12-cp39-cp39-win32.whl", hash = "sha256:beffaed67936fbbeffd10966a4eb53c402fafd3d6833770516bf7314bc6ffa12"},{file = "ruamel.yaml.clib-0.2.12-cp39-cp39-win_amd64.whl", hash = "sha256:040ae85536960525ea62868b642bdb0c2cc6021c9f9d507810c0c604e66f5a7b"},{file = "ruamel.yaml.clib-0.2.12.tar.gz", hash = "sha256:6c8fbb13ec503f99a91901ab46e0b07ae7941cd527393187039aec586fdfd36f"},@@ -11830,7 +11867,7 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools",type = ["pytest-mypy"][extras]-all = ["PyMuPDF", "accelerate", "agentops", "anthropic", "apify_client", "arxiv", "arxiv2text", "asknews", "azure-storage-blob", "beautifulsoup4", "botocore", "cohere", "cohere", "datacommons", "datacommons_pandas", "datasets", "diffusers", "discord.py", "docker", "docx2txt", "duckduckgo-search", "e2b-code-interpreter", "ffmpeg-python", "firecrawl-py", "fish-audio-sdk", "google-cloud-storage", "google-generativeai", "googlemaps", "imageio", "ipykernel", "jupyter_client", "linkup-sdk", "litellm", "mistralai", "nebula3-python", "neo4j", "newspaper3k", "notion-client", "openapi-spec-validator", "openbb", "opencv-python", "outlines", "pandas", "pdfplumber", "pillow", "prance", "praw", "pyTelegramBotAPI", "pydub", "pygithub", "pymilvus", "pyowm", "pyyaml", "qdrant-client", "rank-bm25", "redis", "reka-api", "requests_oauthlib", "rouge", "scholarly", "sentence-transformers", "sentencepiece", "sglang", "slack-bolt", "slack-sdk", "soundfile", "stripe", "tavily-python", "textblob", "torch", "torch", "transformers", "tree-sitter", "tree-sitter-python", "unstructured", "wikipedia", "wolframalpha", "yt-dlp"]+all = ["PyMuPDF", "accelerate", "agentops", "anthropic", "apify_client", "arxiv", "arxiv2text", "asknews", "azure-storage-blob", "beautifulsoup4", "botocore", "cohere", "cohere", "dappier", "datacommons", "datacommons_pandas", "datasets", "diffusers", "discord.py", "docker", "docx2txt", "duckduckgo-search", "e2b-code-interpreter", "ffmpeg-python", "firecrawl-py", "fish-audio-sdk", "google-cloud-storage", "google-generativeai", "googlemaps", "imageio", "ipykernel", "jupyter_client", "linkup-sdk", "litellm", "mistralai", "nebula3-python", "neo4j", "newspaper3k", "notion-client", "openapi-spec-validator", "openbb", "opencv-python", "outlines", "pandas", "pdfplumber", "pillow", "prance", "praw", "pyTelegramBotAPI", "pydub", "pygithub", "pymilvus", "pyowm", "pyyaml", "qdrant-client", "rank-bm25", "redis", "reka-api", "requests_oauthlib", "rouge", "scholarly", "sentence-transformers", "sentencepiece", "sglang", "slack-bolt", "slack-sdk", "soundfile", "stripe", "tavily-python", "textblob", "torch", "torch", "transformers", "tree-sitter", "tree-sitter-python", "unstructured", "wikipedia", "wolframalpha", "yt-dlp"]encoders = ["sentence-transformers"]graph-storages = ["nebula3-python", "neo4j"]huggingface-agent = ["accelerate", "datasets", "diffusers", "opencv-python", "sentencepiece", "soundfile", "torch", "torch", "transformers"]@@ -11842,10 +11879,10 @@ retrievers = ["cohere", "rank-bm25"]runtime = ["docker"]search-tools = ["duckduckgo-search", "linkup-sdk", "tavily-python", "wikipedia", "wolframalpha"]test = ["mock", "pytest", "pytest-asyncio"]-tools = ["PyMuPDF", "agentops", "apify_client", "arxiv", "arxiv2text", "asknews", "beautifulsoup4", "datacommons", "datacommons_pandas", "discord.py", "docker", "docx2txt", "duckduckgo-search", "e2b-code-interpreter", "ffmpeg-python", "firecrawl-py", "googlemaps", "imageio", "ipykernel", "jupyter_client", "linkup-sdk", "newspaper3k", "notion-client", "openapi-spec-validator", "openbb", "outlines", "pandas", "pdfplumber", "pillow", "prance", "praw", "pyTelegramBotAPI", "pydub", "pygithub", "pyowm", "pyyaml", "requests_oauthlib", "rouge", "scholarly", "slack-bolt", "slack-sdk", "stripe", "textblob", "tree-sitter", "tree-sitter-python", "unstructured", "wikipedia", "wolframalpha", "yt-dlp"]+tools = ["PyMuPDF", "agentops", "apify_client", "arxiv", "arxiv2text", "asknews", "beautifulsoup4", "dappier", "datacommons", "datacommons_pandas", "discord.py", "docker", "docx2txt", "duckduckgo-search", "e2b-code-interpreter", "ffmpeg-python", "firecrawl-py", "googlemaps", "imageio", "ipykernel", "jupyter_client", "linkup-sdk", "newspaper3k", "notion-client", "openapi-spec-validator", "openbb", "outlines", "pandas", "pdfplumber", "pillow", "prance", "praw", "pyTelegramBotAPI", "pydub", "pygithub", "pyowm", "pyyaml", "requests_oauthlib", "rouge", "scholarly", "slack-bolt", "slack-sdk", "stripe", "textblob", "tree-sitter", "tree-sitter-python", "unstructured", "wikipedia", "wolframalpha", "yt-dlp"]vector-databases = ["pymilvus", "qdrant-client"][metadata]lock-version = "2.0"python-versions = ">=3.10,<3.13"-content-hash = "e92f9809dc76a8d3caae0850a9ea62614f1398ab681e54ccca3da97ba71c1f0b"+content-hash = "9ba5d2649fb404e582277f30008318b9879556503662b1b931cb08a3dedd9ece"diff --git a/pyproject.toml b/pyproject.tomlindex 24063e2ec..9de508c05 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -91,6 +91,7 @@ pygithub = { version = "^2.3.0", optional = true }imageio = { extras = ["pyav"], version = "^2.34.2", optional = true }e2b-code-interpreter = { version = "^1.0.3", optional = true }pyTelegramBotAPI = { version = "^4.18.0", optional = true }+dappier = { version = "^0.3.3", optional = true }"discord.py" = { version = "^2.3.2", optional = true }docker = { version = "^7.1.0", optional = true }agentops = { version = "^0.3.21", optional = true }@@ -220,6 +221,7 @@ tools = ["pydub","pygithub","pyTelegramBotAPI",+ "dappier","discord.py","docker","jupyter_client",@@ -290,6 +292,7 @@ all = ["docx2txt","pygithub","pyTelegramBotAPI",+ "dappier","discord.py","PyMuPDF","wikipedia",@@ -498,6 +501,7 @@ module = ["pygithub","litellm","pyTelegramBotAPI",+ "dappier","discord.py","docker.*","google.*",diff --git a/test/toolkits/test_dappier_function.py b/test/toolkits/test_dappier_function.pynew file mode 100644index 000000000..8a987f716--- /dev/null+++ b/test/toolkits/test_dappier_function.py@@ -0,0 +1,145 @@+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+import os+import unittest+from unittest.mock import MagicMock, patch++from camel.toolkits.dappier_toolkit import DappierToolkit+++class TestDappierToolkit(unittest.TestCase):+ @patch.dict(+ os.environ,+ {"DAPPIER_API_KEY": "fake_api_key"},+ )+ @patch("dappier.Dappier")+ def setUp(self, MockDappierSDK):+ # Setup for tests+ self.mock_sdk = MockDappierSDK.return_value+ self.toolkit = DappierToolkit()++ def test_search_real_time_data_success(self):+ # Mock the API response for a successful search_real_time_data call+ mock_response = MagicMock()+ mock_response.message = "latest tech news"+ self.mock_sdk.search_real_time_data.return_value = mock_response++ result = self.toolkit.search_real_time_data(query="test query")++ self.assertEqual(result, "latest tech news")+ self.mock_sdk.search_real_time_data.assert_called_once_with(+ query="test query", ai_model_id="am_01j06ytn18ejftedz6dyhz2b15"+ )++ def test_search_real_time_data_failure(self):+ # Test handling of an exception in search_real_time_data+ self.mock_sdk.search_real_time_data.side_effect = Exception("Error")+ result = self.toolkit.search_real_time_data(query="test query")+ self.assertEqual(result, "An unexpected error occurred: Error")++ def test_get_ai_recommendations_success(self):+ # Mock the API response for a successful get_ai_recommendations call+ mock_result = MagicMock()+ mock_result.return_value = [+ MagicMock(+ author="John Doe",+ image_url="https://example.com/image1.jpg",+ pubdate="Mon, 01 Jan 2025 10:00:00 +0000",+ source_url="https://example1.com/article1",+ summary="Summary of article 1.",+ title="Article Title 1",+ ),+ MagicMock(+ author="Jane Smith",+ image_url="https://example.com/image2.jpg",+ pubdate="Tue, 02 Jan 2025 12:00:00 +0000",+ source_url="https://example2.com/article2",+ summary="Summary of article 2.",+ title="Article Title 2",+ ),+ MagicMock(+ author="Alice Johnson",+ image_url="https://example.com/image3.jpg",+ pubdate="Wed, 03 Jan 2025 14:00:00 +0000",+ source_url="https://example3.com/article3",+ summary="Summary of article 3.",+ title="Article Title 3",+ ),+ ]+ mock_response = MagicMock()+ mock_response.status = "success"+ mock_response.response.query = "test query"+ mock_response.response.results = mock_result()++ self.mock_sdk.get_ai_recommendations.return_value = mock_response++ result = self.toolkit.get_ai_recommendations(+ query="test query", similarity_top_k=3+ )++ expected_result = [+ {+ "author": "John Doe",+ "image_url": "https://example.com/image1.jpg",+ "pubdate": "Mon, 01 Jan 2025 10:00:00 +0000",+ "source_url": "https://example1.com/article1",+ "summary": "Summary of article 1.",+ "title": "Article Title 1",+ },+ {+ "author": "Jane Smith",+ "image_url": "https://example.com/image2.jpg",+ "pubdate": "Tue, 02 Jan 2025 12:00:00 +0000",+ "source_url": "https://example2.com/article2",+ "summary": "Summary of article 2.",+ "title": "Article Title 2",+ },+ {+ "author": "Alice Johnson",+ "image_url": "https://example.com/image3.jpg",+ "pubdate": "Wed, 03 Jan 2025 14:00:00 +0000",+ "source_url": "https://example3.com/article3",+ "summary": "Summary of article 3.",+ "title": "Article Title 3",+ },+ ]++ self.assertEqual(result, expected_result)+ self.mock_sdk.get_ai_recommendations.assert_called_once_with(+ query="test query",+ data_model_id="dm_01j0pb465keqmatq9k83dthx34",+ similarity_top_k=3,+ ref=None,+ num_articles_ref=0,+ search_algorithm="most_recent",+ )++ def test_get_ai_recommendations_failure(self):+ # Test handling of an exception in get_ai_recommendations+ self.mock_sdk.get_ai_recommendations.side_effect = Exception(+ "API Error"+ )+ result = self.toolkit.get_ai_recommendations(query="test query")+ self.assertEqual(+ result, {"error": "An unexpected error occurred: API Error"}+ )++ def test_get_ai_recommendations_failure_when_status_failure(self):+ # Test handling of an exception in get_ai_recommendations+ mock_response = MagicMock()+ mock_response.status = "failure"+ mock_response.response.query = "test query"+ mock_response.response.results = None+ result = self.toolkit.get_ai_recommendations(query="test query")+ self.assertEqual(result, {"error": "An unknown error occurred."})