🐫 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: Google scholar toolkit (#997)
Wendong-Fan817ed3dffa8a
diff --git a/camel/toolkits/__init__.py b/camel/toolkits/__init__.pyindex 8c715a3e6..f703d5a7c 100644--- a/camel/toolkits/__init__.py+++ b/camel/toolkits/__init__.py@@ -30,6 +30,7 @@ from .base import BaseToolkitfrom .google_maps_toolkit import GoogleMapsToolkitfrom .code_execution import CodeExecutionToolkitfrom .github_toolkit import GithubToolkit+from .google_scholar_toolkit import GoogleScholarToolkitfrom .arxiv_toolkit import ArxivToolkitfrom .linkedin_toolkit import LinkedInToolkitfrom .reddit_toolkit import RedditToolkit@@ -58,6 +59,7 @@ __all__ = ['LinkedInToolkit','RedditToolkit','CodeExecutionToolkit',+ 'GoogleScholarToolkit','ArxivToolkit','MATH_FUNCS','SEARCH_FUNCS',diff --git a/camel/toolkits/arxiv_toolkit.py b/camel/toolkits/arxiv_toolkit.pyindex edbb9da5b..c3719edec 100644--- a/camel/toolkits/arxiv_toolkit.py+++ b/camel/toolkits/arxiv_toolkit.py@@ -142,6 +142,13 @@ class ArxivToolkit(BaseToolkit):return f"An error occurred: {e}"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_papers),FunctionTool(self.download_papers),diff --git a/camel/toolkits/google_scholar_toolkit.py b/camel/toolkits/google_scholar_toolkit.pynew file mode 100644index 000000000..8c3b03e64--- /dev/null+++ b/camel/toolkits/google_scholar_toolkit.py@@ -0,0 +1,146 @@+# =========== Copyright 2023 @ 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 @ CAMEL-AI.org. All Rights Reserved. ===========+import re+from typing import List, Optional++from camel.toolkits import FunctionTool+from camel.toolkits.base import BaseToolkit+++class GoogleScholarToolkit(BaseToolkit):+ r"""A toolkit for retrieving information about authors and their+ publications from Google Scholar.++ Attributes:+ author_identifier (Union[str, None]): The author's Google Scholar URL+ or name of the author to search for.+ is_author_name (bool): Flag to indicate if the identifier is a name.+ (default: :obj:`False`)+ scholarly (module): The scholarly module for querying Google Scholar.+ """++ def __init__(+ self, author_identifier: str, is_author_name: bool = False+ ) -> None:+ r"""Initializes the GoogleScholarToolkit with the author's identifier.++ Args:+ author_identifier (str): The author's Google Scholar URL or name+ of the author to search for.+ is_author_name (bool): Flag to indicate if the identifier is a+ name. (default: :obj:`False`)+ """+ from scholarly import scholarly++ self.scholarly = scholarly+ self.author_identifier = author_identifier+ self.is_author_name = is_author_name++ def _extract_author_id(self) -> Optional[str]:+ r"""Extracts the author ID from a Google Scholar URL if provided.++ Returns:+ Optional[str]: The extracted author ID, or None if not found.+ """+ match = re.search(r'user=([A-Za-z0-9-]+)', self.author_identifier)+ return match.group(1) if match else None++ def get_author_detailed_info(+ self,+ ) -> dict:+ r"""Retrieves detailed information about the author.++ Returns:+ dict: A dictionary containing detailed information about the+ author.+ """+ if self.is_author_name:+ search_query = self.scholarly.search_author(self.author_identifier)+ # Retrieve the first result from the iterator+ first_author_result = next(search_query)+ else:+ author_id = self._extract_author_id()+ first_author_result = self.scholarly.search_author_id(id=author_id)++ author = self.scholarly.fill(first_author_result)+ return author++ def get_author_publications(+ self,+ ) -> List[str]:+ r"""Retrieves the titles of the author's publications.++ Returns:+ List[str]: A list of publication titles authored by the author.+ """+ author = self.get_author_detailed_info()+ publication_titles = [+ pub['bib']['title'] for pub in author['publications']+ ]+ return publication_titles++ def get_publication_by_title(+ self, publication_title: str+ ) -> Optional[dict]:+ r"""Retrieves detailed information about a specific publication by its+ title. Note that this method cannot retrieve the full content of the+ paper.++ Args:+ publication_title (str): The title of the publication to search+ for.++ Returns:+ Optional[dict]: A dictionary containing detailed information about+ the publication if found; otherwise, `None`.+ """+ author = self.get_author_detailed_info()+ publications = author['publications']+ for publication in publications:+ if publication['bib']['title'] == publication_title:+ return self.scholarly.fill(publication)+ return None # Return None if not found++ def get_full_paper_content_by_link(self, pdf_url: str) -> Optional[str]:+ r"""Retrieves the full paper content from a given PDF URL using the+ arxiv2text tool.++ Args:+ pdf_url (str): The URL of the PDF file.++ Returns:+ Optional[str]: The full text extracted from the PDF, or `None` if+ an error occurs.+ """+ from arxiv2text import arxiv_to_text++ try:+ return arxiv_to_text(pdf_url)+ except Exception:+ return None # Return None in case of any error++ 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.get_author_detailed_info),+ FunctionTool(self.get_author_publications),+ FunctionTool(self.get_publication_by_title),+ FunctionTool(self.get_full_paper_content_by_link),+ ]diff --git a/examples/test/test_ai_society_example.py b/examples/test/test_ai_society_example.pyindex 8b926525a..46427083d 100644--- a/examples/test/test_ai_society_example.py+++ b/examples/test/test_ai_society_example.py@@ -14,8 +14,8 @@from mock import patchimport examples.ai_society.role_playing-import examples.function_call.role_playing_with_functionsimport examples.models.role_playing_with_open_source_model+import examples.tool_call.role_playing_with_functionsfrom camel.models import ModelFactoryfrom camel.types import ModelPlatformType, ModelType@@ -35,9 +35,7 @@ def test_ai_society_role_playing_example():def test_role_playing_with_function_example():with patch('time.sleep', return_value=None):- examples.function_call.role_playing_with_functions.main(- chat_turn_limit=2- )+ examples.tool_call.role_playing_with_functions.main(chat_turn_limit=2)def test_role_playing_with_open_source_model():diff --git a/examples/function_call/code_execution.py b/examples/tool_call/code_execution_toolkit.pysimilarity index 100%rename from examples/function_call/code_execution.pyrename to examples/tool_call/code_execution_toolkit.pydiff --git a/examples/function_call/github_examples.py b/examples/tool_call/github_toolkit.pysimilarity index 100%rename from examples/function_call/github_examples.pyrename to examples/tool_call/github_toolkit.pydiff --git a/examples/tool_call/google_scholar_toolkit.py b/examples/tool_call/google_scholar_toolkit.pynew file mode 100644index 000000000..6692b641a--- /dev/null+++ b/examples/tool_call/google_scholar_toolkit.py@@ -0,0 +1,194 @@+# =========== Copyright 2023 @ 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 @ CAMEL-AI.org. All Rights Reserved. ===========++from camel.agents import ChatAgent+from camel.configs.openai_config import ChatGPTConfig+from camel.messages import BaseMessage+from camel.models import ModelFactory+from camel.toolkits import GoogleScholarToolkit+from camel.types import ModelPlatformType, ModelType++# Define system message+sys_msg = BaseMessage.make_assistant_message(+ role_name="Tools calling opertor", content="You are a helpful assistant"+)++# Set model config+tools = GoogleScholarToolkit(+ author_identifier="https://scholar.google.com/citations?user=JicYPdAAAAAJ&hl=en&oi=ao"+).get_tools()+model_config_dict = ChatGPTConfig(+ temperature=0.0,+).as_dict()++model = ModelFactory.create(+ model_platform=ModelPlatformType.OPENAI,+ model_type=ModelType.GPT_4O_MINI,+ model_config_dict=model_config_dict,+)++# Set agent+camel_agent = ChatAgent(+ system_message=sys_msg,+ model=model,+ tools=tools,+)+camel_agent.reset()++# Define a user message+usr_msg = BaseMessage.make_user_message(+ role_name="CAMEL User",+ content="get the detailed information of this author",+)++# Get response information+response = camel_agent.step(usr_msg)+print(str(response.info['tool_calls'])[:1000])+"""+===============================================================================+[FunctionCallingRecord(func_name='get_author_detailed_info', args={}, result=+{'container_type': 'Author', 'filled': ['basics', 'indices', 'counts',+'coauthors', 'publications', 'public_access'], 'scholar_id': 'JicYPdAAAAAJ',+'source': <AuthorSource.AUTHOR_PROFILE_PAGE: 'AUTHOR_PROFILE_PAGE'>, 'name':+'Geoffrey Hinton', 'url_picture': 'https://scholar.googleusercontent.com/+citations?view_op=view_photo&user=JicYPdAAAAAJ&citpid=2', 'affiliation':+'Emeritus Prof. Computer Science, University of Toronto', 'organization':+8515235176732148308, 'interests': ['machine learning', 'psychology',+'artificial intelligence', 'cognitive science', 'computer science'],+'email_domain': '@cs.toronto.edu', 'homepage': 'http://www.cs.toronto.edu/+~hinton', 'citedby': 853541, 'citedby5y': 560063, 'hindex': 186, 'hindex5y':+137, 'i10index': 483, 'i10index5y': 368, 'cites_per_year': {1989: 2627, 1990:+3589, 1991: 3766, 1992: 4091, 1993: 4573, 1994: 4499, 1995: 4090, 1996: 3935,+1997: 3740, 1998: 3744, 1999: 3559, 2000: 3292, 2001: 3398, 2002: 3713, 2003:+3670, 2004: 3393, 2005: 3813, 2006: 4168, 2007: 4558, 2008: 4349, 2009: 4784,+2010: 5238, 2011: 5722, 2012: 6746, 2013: 9900, 2014: 12751, 2015: 18999,+2016: 29932, 2017: 43675, 2018: 63544, 2019: 80800, 2020: 90523, 2021: 101735,+2022: 104036, 2023: 106452, 2024: 76413}, 'coauthors': [{'container_type':+'Author', 'filled': [], 'scholar_id': 'm1qAiOUAAAAJ', 'source': <AuthorSource.+CO_AUTHORS_LIST: 'CO_AUTHORS_LIST'>, 'name': 'Terrence Sejnowski',+'affiliation': 'Francis Crick Professor, Salk Institute, Distingished+Professor, UC San Diego'}, {'container_type': 'Author', 'filled': [],+'scholar_id': 'RnoIxUwAAAAJ', 'source': <AuthorSource.CO_AUTHORS_LIST:+'CO_AUTHORS_LIST'>, 'name': 'Vinod Nair', 'affiliation': 'Research Scientist,+DeepMind'}, {'container_type': 'Author', 'filled': [], 'scholar_id':+'ghbWy-0AAAAJ', 'source': <AuthorSource.CO_AUTHORS_LIST: 'CO_AUTHORS_LIST'>,+'name': 'George E. Dahl', 'affiliation': 'Google Inc.'}, {'container_+===============================================================================+"""++# Define a user message+usr_msg = BaseMessage.make_user_message(+ role_name="CAMEL User", content="get the publications of this author"+)++# Get response information+response = camel_agent.step(usr_msg)+print(str(response.info['tool_calls'])[:1000])+"""+===============================================================================+[FunctionCallingRecord(func_name='get_author_publications', args={}, result=+['Imagenet classification with deep convolutional neural networks', 'Deep+learning', 'Learning internal representations by error-propagation', 'Dropout:+a simple way to prevent neural networks from overfitting', 'Visualizing data+using t-SNE', 'Learning representations by back-propagating errors', 'Learning+multiple layers of features from tiny images', 'Rectified linear units improve+restricted boltzmann machines', 'Reducing the dimensionality of data with+neural networks', 'A fast learning algorithm for deep belief nets',+'Distilling the Knowledge in a Neural Network', 'A simple framework for+contrastive learning of visual representations', 'Deep neural networks for+acoustic modeling in speech recognition: The shared views of four research+groups', 'Layer normalization', 'Speech recognition with deep recurrent neural+networks', 'Improving neural networks by preventing co-adaptation of feature+detectors', 'Lec+===============================================================================+"""++# ruff: noqa: E501+# Define a user message+usr_msg = BaseMessage.make_user_message(+ role_name="CAMEL User",+ content="""get the detailed information for publication with title: `Camel: Communicative agents for" mind" exploration of large language model society`""",+)++# Get response information+response = camel_agent.step(usr_msg)+print(response.info['tool_calls'])+"""+===============================================================================+[FunctionCallingRecord(func_name='get_publication_by_title', args=+{'publication_title': 'Camel: Communicative agents for" mind" exploration of+large language model society'}, result={'container_type': 'Publication',+'source': <PublicationSource.AUTHOR_PUBLICATION_ENTRY:+'AUTHOR_PUBLICATION_ENTRY'>, 'bib': {'title': 'Camel: Communicative agents+for" mind" exploration of large language model society', 'pub_year': 2023,+'citation': 'Advances in Neural Information Processing Systems 36, 2023',+'author': 'Guohao Li and Hasan Hammoud and Hani Itani and Dmitrii Khizbullin+and Bernard Ghanem', 'journal': 'Advances in Neural Information Processing+Systems', 'volume': '36', 'abstract': 'The rapid advancement of chat-based+language models has led to remarkable progress in complex task-solving.+However, their success heavily relies on human input to guide the+conversation, which can be challenging and time-consuming. This paper explores+the potential of building scalable techniques to facilitate autonomous+cooperation among communicative agents, and provides insight into their+“cognitive” processes. To address the challenges of achieving autonomous+cooperation, we propose a novel communicative agent framework named+role-playing. Our approach involves using inception prompting to guide chat+agents toward task completion while maintaining consistency with human+intentions. We showcase how role-playing can be used to generate+conversational data for studying the behaviors and capabilities of a society+of agents, providing a valuable resource for investigating conversational+language models. In particular, we conduct comprehensive studies on+instruction-following cooperation in multi-agent settings. Our contributions+include introducing a novel communicative agent framework, offering a scalable+approach for studying the cooperative behaviors and capabilities of+multi-agent systems, and open-sourcing our library to support research on+communicative agents and beyond: https://github. com/camel-ai/camel.'},+'filled': True, 'author_pub_id': 'J9K-D0sAAAAJ:_Qo2XoVZTnwC', 'num_citations':+364, 'citedby_url': '/scholar?hl=en&cites=3976259482297250805', 'cites_id':+['3976259482297250805'], 'pub_url': 'https://proceedings.neurips.cc/+paper_files/paper/2023/hash/+a3621ee907def47c1b952ade25c67698-Abstract-Conference.html',+'url_related_articles': '/scholar?oi=bibs&hl=en&q=related:9TMbme6CLjcJ:scholar.+google.com/', 'cites_per_year': {2023: 95, 2024: 269}})]+===============================================================================+"""++usr_msg = BaseMessage.make_user_message(+ role_name="CAMEL User",+ content="""get the full information for paper from link: `https://hal.science/hal-04206682/document`""",+)++# Get response information+response = camel_agent.step(usr_msg)+print((response.info['tool_calls'])[:1000])+"""+===============================================================================+[FunctionCallingRecord(func_name='get_full_paper_content_by_link', args=+{'pdf_url': 'https://hal.science/hal-04206682/document'}, result='Deep+learning\nYann Lecun, Yoshua Bengio, Geoffrey Hinton\n\nTo cite this+version:\n\nYann Lecun, Yoshua Bengio, Geoffrey Hinton. Deep learning. Nature,+2015, 521 (7553), pp.436-444.\n\uffff10.1038/nature14539\uffff.+\uffffhal-04206682\uffff\n\nHAL Id: hal-04206682\n\nhttps://hal.science/+hal-04206682v1\n\nSubmitted on 14 Sep 2023\n\nHAL is a multi-disciplinary open+access\narchive for the deposit and dissemination of sci-\nentific research+documents, whether they are pub-\nlished or not. The documents may come+from\nteaching and research institutions in France or\nabroad, or from public+or private research centers.\n\nL'archive ouverte pluridisciplinaire HAL,+est\ndestinée au dépôt et à la diffusion de documents\nscientifiques de niveau+recherche, publiés ou non,\némanant des établissements d'enseignement et+de\nrecherche français ou étrangers, des laboratoires\npublics ou privés.+\n\n\x0cDeep learning\n\nYann LeCun1,2, Yoshua Bengio3 & Geoffrey Hinton4,+5\n\n1Facebook AI Research, 770 Broadway, New York, New York 10003 USA\n\n2N..+===============================================================================+"""diff --git a/examples/function_call/openapi_function.py b/examples/tool_call/openapi_toolkit.pysimilarity index 100%rename from examples/function_call/openapi_function.pyrename to examples/tool_call/openapi_toolkit.pydiff --git a/examples/function_call/reddit_examples.py b/examples/tool_call/reddit_examples.pysimilarity index 100%rename from examples/function_call/reddit_examples.pyrename to examples/tool_call/reddit_examples.pydiff --git a/examples/function_call/role_playing_with_functions.py b/examples/tool_call/role_playing_with_functions.pysimilarity index 100%rename from examples/function_call/role_playing_with_functions.pyrename to examples/tool_call/role_playing_with_functions.pydiff --git a/poetry.lock b/poetry.lockindex 373ee111b..7f067dcd1 100644--- a/poetry.lock+++ b/poetry.lock@@ -332,6 +332,25 @@ files = [{file = "appnope-0.1.4.tar.gz", hash = "sha256:1de3860566df9caf38f01f86f65e0e13e379af54f9e4bee1e66b48f2efffd1ee"},]+[[package]]+name = "arrow"+version = "1.3.0"+description = "Better dates & times for Python"+optional = true+python-versions = ">=3.8"+files = [+ {file = "arrow-1.3.0-py3-none-any.whl", hash = "sha256:c728b120ebc00eb84e01882a6f5e7927a53960aa990ce7dd2b10f39005a67f80"},+ {file = "arrow-1.3.0.tar.gz", hash = "sha256:d4540617648cb5f895730f1ad8c82a65f2dad0166f57b75f3ca54759c4d67a85"},+]++[package.dependencies]+python-dateutil = ">=2.7.0"+types-python-dateutil = ">=2.8.10"++[package.extras]+doc = ["doc8", "sphinx (>=7.0.0)", "sphinx-autobuild", "sphinx-autodoc-typehints", "sphinx_rtd_theme (>=1.3.0)"]+test = ["dateparser (==1.*)", "pre-commit", "pytest", "pytest-cov", "pytest-mock", "pytz (==2021.1)", "simplejson (==3.*)"]+[[package]]name = "arxiv"version = "2.1.3"@@ -564,6 +583,19 @@ charset-normalizer = ["charset-normalizer"]html5lib = ["html5lib"]lxml = ["lxml"]+[[package]]+name = "bibtexparser"+version = "1.4.2"+description = "Bibtex parser for python 3"+optional = true+python-versions = "*"+files = [+ {file = "bibtexparser-1.4.2.tar.gz", hash = "sha256:dd5d54a1ec6d27b6485ce2f6b9aa514b183fb2b8d4bf5f19333a906eedaf8eaa"},+]++[package.dependencies]+pyparsing = ">=2.0.3"+[[package]]name = "bleach"version = "6.1.0"@@ -1573,6 +1605,17 @@ files = [[package.extras]tests = ["asttokens (>=2.1.0)", "coverage", "coverage-enable-subprocess", "ipython", "littleutils", "pytest", "rich"]+[[package]]+name = "fake-useragent"+version = "1.5.1"+description = "Up-to-date simple useragent faker with real world database"+optional = true+python-versions = "*"+files = [+ {file = "fake-useragent-1.5.1.tar.gz", hash = "sha256:6387269f5a2196b5ba7ed8935852f75486845a1c95c50e72460e6a8e762f5c49"},+ {file = "fake_useragent-1.5.1-py3-none-any.whl", hash = "sha256:57415096557c8a4e23b62a375c21c55af5fd4ba30549227f562d2c4f5b60e3b3"},+]+[[package]]name = "fastapi"version = "0.115.2"@@ -1819,6 +1862,20 @@ ufo = ["fs (>=2.2.0,<3)"]unicode = ["unicodedata2 (>=15.1.0)"]woff = ["brotli (>=1.0.1)", "brotlicffi (>=0.8.0)", "zopfli (>=0.1.4)"]+[[package]]+name = "free-proxy"+version = "1.1.2"+description = "Proxy scraper for further use"+optional = true+python-versions = ">=3.6"+files = [+ {file = "free_proxy-1.1.2.tar.gz", hash = "sha256:f7c361d3b6c82918ab845163c46ea574e6bd4ce54b1342e89804aaf07e53b848"},+]++[package.dependencies]+lxml = "*"+requests = "*"+[[package]]name = "frozenlist"version = "1.4.1"@@ -3343,13 +3400,13 @@ files = [[[package]]name = "litellm"-version = "1.49.4"+version = "1.49.5"description = "Library to easily interface with LLM API providers"optional = truepython-versions = "!=2.7.*,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,!=3.7.*,>=3.8"files = [- {file = "litellm-1.49.4-py3-none-any.whl", hash = "sha256:3094a9f74979da993f4b3298372ec4416f7a3f82d11a0831c9c616098b3fb50a"},- {file = "litellm-1.49.4.tar.gz", hash = "sha256:5f16d40bfa7747fcc21f45f340454c57cbc705178244fe7326abac7c0759e05e"},+ {file = "litellm-1.49.5-py3-none-any.whl", hash = "sha256:9cd246221c1d922edb7614f29b5b5618b9da588f0ac04612965dbd8afeaa130f"},+ {file = "litellm-1.49.5.tar.gz", hash = "sha256:f45667d723d77d235dc3cc3b056338012eb2ffbfd46d7beb7abea927f49358e0"},][package.dependencies]@@ -4812,6 +4869,20 @@ files = [{file = "orjson-3.10.7.tar.gz", hash = "sha256:75ef0640403f945f3a1f9f6400686560dbfb0fb5b16589ad62cd477043c4eee3"},]+[[package]]+name = "outcome"+version = "1.3.0.post0"+description = "Capture the outcome of Python function calls."+optional = true+python-versions = ">=3.7"+files = [+ {file = "outcome-1.3.0.post0-py2.py3-none-any.whl", hash = "sha256:e771c5ce06d1415e356078d3bdd68523f284b4ce5419828922b6871e65eda82b"},+ {file = "outcome-1.3.0.post0.tar.gz", hash = "sha256:9dcf02e65f2971b80047b377468e72a268e15c0af3cf1238e6ff14f7f91143b8"},+]++[package.dependencies]+attrs = ">=19.2.0"+[[package]]name = "packaging"version = "23.2"@@ -7185,6 +7256,35 @@ tensorflow = ["safetensors[numpy]", "tensorflow (>=2.11.0)"]testing = ["h5py (>=3.7.0)", "huggingface-hub (>=0.12.1)", "hypothesis (>=6.70.2)", "pytest (>=7.2.0)", "pytest-benchmark (>=4.0.0)", "safetensors[numpy]", "setuptools-rust (>=1.5.2)"]torch = ["safetensors[numpy]", "torch (>=1.10)"]+[[package]]+name = "scholarly"+version = "1.7.11"+description = "Simple access to Google Scholar authors and citations"+optional = true+python-versions = "*"+files = [+ {file = "scholarly-1.7.11-py3-none-any.whl", hash = "sha256:be404853e0d020254de32d2050c54dc201f1f36efa4a9d3f8e740d3be4361b20"},+ {file = "scholarly-1.7.11.tar.gz", hash = "sha256:2c983dd44d9d9398a6f2605102ae6e5586023b41ebbaec1461917ee48eb153f0"},+]++[package.dependencies]+arrow = "*"+beautifulsoup4 = "*"+bibtexparser = "*"+deprecated = "*"+fake-useragent = "*"+free-proxy = "*"+httpx = "*"+python-dotenv = "*"+requests = {version = "*", extras = ["socks"]}+selenium = "*"+sphinx-rtd-theme = "*"+stem = {version = "*", optional = true, markers = "extra == \"tor\""}+typing-extensions = "*"++[package.extras]+tor = ["stem"]+[[package]]name = "scikit-learn"version = "1.5.2"@@ -7280,6 +7380,25 @@ dev = ["cython-lint (>=0.12.2)", "doit (>=0.36.0)", "mypy (==1.10.0)", "pycodestdoc = ["jupyterlite-pyodide-kernel", "jupyterlite-sphinx (>=0.13.1)", "jupytext", "matplotlib (>=3.5)", "myst-nb", "numpydoc", "pooch", "pydata-sphinx-theme (>=0.15.2)", "sphinx (>=5.0.0,<=7.3.7)", "sphinx-design (>=0.4.0)"]test = ["Cython", "array-api-strict (>=2.0)", "asv", "gmpy2", "hypothesis (>=6.30)", "meson", "mpmath", "ninja", "pooch", "pytest", "pytest-cov", "pytest-timeout", "pytest-xdist", "scikit-umfpack", "threadpoolctl"]+[[package]]+name = "selenium"+version = "4.25.0"+description = "Official Python bindings for Selenium WebDriver"+optional = true+python-versions = ">=3.8"+files = [+ {file = "selenium-4.25.0-py3-none-any.whl", hash = "sha256:3798d2d12b4a570bc5790163ba57fef10b2afee958bf1d80f2a3cf07c4141f33"},+ {file = "selenium-4.25.0.tar.gz", hash = "sha256:95d08d3b82fb353f3c474895154516604c7f0e6a9a565ae6498ef36c9bac6921"},+]++[package.dependencies]+certifi = ">=2021.10.8"+trio = ">=0.17,<1.0"+trio-websocket = ">=0.9,<1.0"+typing_extensions = ">=4.9,<5.0"+urllib3 = {version = ">=1.26,<3", extras = ["socks"]}+websocket-client = ">=1.8,<2.0"+[[package]]name = "semantic-version"version = "2.10.0"@@ -7461,6 +7580,17 @@ files = [{file = "snowballstemmer-2.2.0.tar.gz", hash = "sha256:09b16deb8547d3412ad7b590689584cd0fe25ec8db3be37788be3810cbf19cb1"},]+[[package]]+name = "sortedcontainers"+version = "2.4.0"+description = "Sorted Containers -- Sorted List, Sorted Dict, Sorted Set"+optional = true+python-versions = "*"+files = [+ {file = "sortedcontainers-2.4.0-py2.py3-none-any.whl", hash = "sha256:a163dcaede0f1c021485e957a39245190e74249897e2ae4b2aa38595db237ee0"},+ {file = "sortedcontainers-2.4.0.tar.gz", hash = "sha256:25caa5a06cc30b6b83d11423433f65d1f9d76c4c6a0c90e3379eaa43b9bfdb88"},+]+[[package]]name = "soundfile"version = "0.12.1"@@ -7550,6 +7680,25 @@ code-style = ["pre-commit"]doc = ["ablog", "folium", "ipywidgets", "matplotlib", "myst-nb", "nbclient", "numpy", "numpydoc", "pandas", "plotly", "sphinx-copybutton", "sphinx-design", "sphinx-examples", "sphinx-tabs", "sphinx-thebe", "sphinx-togglebutton", "sphinxcontrib-bibtex", "sphinxcontrib-youtube", "sphinxext-opengraph"]test = ["beautifulsoup4", "coverage", "defusedxml", "myst-nb", "pytest", "pytest-cov", "pytest-regressions", "sphinx_thebe"]+[[package]]+name = "sphinx-rtd-theme"+version = "3.0.1"+description = "Read the Docs theme for Sphinx"+optional = true+python-versions = ">=3.8"+files = [+ {file = "sphinx_rtd_theme-3.0.1-py2.py3-none-any.whl", hash = "sha256:921c0ece75e90633ee876bd7b148cfaad136b481907ad154ac3669b6fc957916"},+ {file = "sphinx_rtd_theme-3.0.1.tar.gz", hash = "sha256:a4c5745d1b06dfcb80b7704fe532eb765b44065a8fad9851e4258c8804140703"},+]++[package.dependencies]+docutils = ">0.18,<0.22"+sphinx = ">=6,<9"+sphinxcontrib-jquery = ">=4,<5"++[package.extras]+dev = ["bump2version", "transifex-client", "twine", "wheel"]+[[package]]name = "sphinxcontrib-applehelp"version = "2.0.0"@@ -7598,6 +7747,20 @@ lint = ["mypy", "ruff (==0.5.5)", "types-docutils"]standalone = ["Sphinx (>=5)"]test = ["html5lib", "pytest"]+[[package]]+name = "sphinxcontrib-jquery"+version = "4.1"+description = "Extension to include jQuery on newer Sphinx releases"+optional = true+python-versions = ">=2.7"+files = [+ {file = "sphinxcontrib-jquery-4.1.tar.gz", hash = "sha256:1620739f04e36a2c779f1a131a2dfd49b2fd07351bf1968ced074365933abc7a"},+ {file = "sphinxcontrib_jquery-4.1-py2.py3-none-any.whl", hash = "sha256:f936030d7d0147dd026a4f2b5a57343d233f1fc7b363f68b3d4f1cb0993878ae"},+]++[package.dependencies]+Sphinx = ">=1.8"+[[package]]name = "sphinxcontrib-jsmath"version = "1.0.1"@@ -7680,6 +7843,16 @@ anyio = ">=3.4.0,<5"[package.extras]full = ["httpx (>=0.22.0)", "itsdangerous", "jinja2", "python-multipart (>=0.0.7)", "pyyaml"]+[[package]]+name = "stem"+version = "1.8.2"+description = "Stem is a Python controller library that allows applications to interact with Tor (https://www.torproject.org/)."+optional = true+python-versions = "*"+files = [+ {file = "stem-1.8.2.tar.gz", hash = "sha256:83fb19ffd4c9f82207c006051480389f80af221a7e4783000aedec4e384eb582"},+]+[[package]]name = "sympy"version = "1.13.3"@@ -8229,6 +8402,42 @@ torchhub = ["filelock", "huggingface-hub (>=0.23.2,<1.0)", "importlib-metadata",video = ["av (==9.2.0)", "decord (==0.6.0)"]vision = ["Pillow (>=10.0.1,<=15.0)"]+[[package]]+name = "trio"+version = "0.26.2"+description = "A friendly Python library for async concurrency and I/O"+optional = true+python-versions = ">=3.8"+files = [+ {file = "trio-0.26.2-py3-none-any.whl", hash = "sha256:c5237e8133eb0a1d72f09a971a55c28ebe69e351c783fc64bc37db8db8bbe1d0"},+ {file = "trio-0.26.2.tar.gz", hash = "sha256:0346c3852c15e5c7d40ea15972c4805689ef2cb8b5206f794c9c19450119f3a4"},+]++[package.dependencies]+attrs = ">=23.2.0"+cffi = {version = ">=1.14", markers = "os_name == \"nt\" and implementation_name != \"pypy\""}+exceptiongroup = {version = "*", markers = "python_version < \"3.11\""}+idna = "*"+outcome = "*"+sniffio = ">=1.3.0"+sortedcontainers = "*"++[[package]]+name = "trio-websocket"+version = "0.11.1"+description = "WebSocket library for Trio"+optional = true+python-versions = ">=3.7"+files = [+ {file = "trio-websocket-0.11.1.tar.gz", hash = "sha256:18c11793647703c158b1f6e62de638acada927344d534e3c7628eedcb746839f"},+ {file = "trio_websocket-0.11.1-py3-none-any.whl", hash = "sha256:520d046b0d030cf970b8b2b2e00c4c2245b3807853ecd44214acd33d74581638"},+]++[package.dependencies]+exceptiongroup = {version = "*", markers = "python_version < \"3.11\""}+trio = ">=0.11"+wsproto = ">=0.14"+[[package]]name = "triton"version = "3.0.0"@@ -8315,6 +8524,17 @@ files = [types-docutils = "*"types-setuptools = "*"+[[package]]+name = "types-python-dateutil"+version = "2.9.0.20241003"+description = "Typing stubs for python-dateutil"+optional = true+python-versions = ">=3.8"+files = [+ {file = "types-python-dateutil-2.9.0.20241003.tar.gz", hash = "sha256:58cb85449b2a56d6684e41aeefb4c4280631246a0da1a719bdbe6f3fb0317446"},+ {file = "types_python_dateutil-2.9.0.20241003-py3-none-any.whl", hash = "sha256:250e1d8e80e7bbc3a6c99b907762711d1a1cdd00e978ad39cb5940f6f0a87f3d"},+]+[[package]]name = "types-regex"version = "2024.9.11.20240912"@@ -8668,6 +8888,9 @@ files = [{file = "urllib3-2.2.3.tar.gz", hash = "sha256:e7d814a81dad81e6caf2ec9fdedb284ecc9c73076b62654547cc64ccdcae26e9"},]+[package.dependencies]+pysocks = {version = ">=1.5.6,<1.5.7 || >1.5.7,<2.0", optional = true, markers = "extra == \"socks\""}+[package.extras]brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)"]h2 = ["h2 (>=4,<5)"]@@ -8960,6 +9183,20 @@ files = [{file = "wrapt-1.16.0.tar.gz", hash = "sha256:5f370f952971e7d17c7d1ead40e49f32345a7f7a5373571ef44d800d06b1899d"},]+[[package]]+name = "wsproto"+version = "1.2.0"+description = "WebSockets state-machine based protocol implementation"+optional = true+python-versions = ">=3.7.0"+files = [+ {file = "wsproto-1.2.0-py3-none-any.whl", hash = "sha256:b9acddd652b585d75b20477888c56642fdade28bdfd3579aa24a4d2c037dd736"},+ {file = "wsproto-1.2.0.tar.gz", hash = "sha256:ad565f26ecb92588a3e43bc3d96164de84cd9902482b130d0ddbaa9664a85065"},+]++[package.dependencies]+h11 = ">=0.9.0,<1"+[[package]]name = "xlrd"version = "2.0.1"@@ -9246,7 +9483,7 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools",type = ["pytest-mypy"][extras]-all = ["PyMuPDF", "accelerate", "agentops", "arxiv", "arxiv2text", "azure-storage-blob", "beautifulsoup4", "botocore", "cohere", "datasets", "diffusers", "discord.py", "docker", "docx2txt", "duckduckgo-search", "firecrawl-py", "google-cloud-storage", "google-generativeai", "googlemaps", "imageio", "jupyter_client", "litellm", "mistralai", "nebula3-python", "neo4j", "newspaper3k", "nltk", "openapi-spec-validator", "opencv-python", "pillow", "prance", "praw", "pyTelegramBotAPI", "pydub", "pygithub", "pymilvus", "pyowm", "qdrant-client", "rank-bm25", "redis", "reka-api", "requests_oauthlib", "sentence-transformers", "sentencepiece", "slack-sdk", "soundfile", "textblob", "torch", "transformers", "unstructured", "wikipedia", "wolframalpha"]+all = ["PyMuPDF", "accelerate", "agentops", "arxiv", "arxiv2text", "azure-storage-blob", "beautifulsoup4", "botocore", "cohere", "datasets", "diffusers", "discord.py", "docker", "docx2txt", "duckduckgo-search", "firecrawl-py", "google-cloud-storage", "google-generativeai", "googlemaps", "imageio", "jupyter_client", "litellm", "mistralai", "nebula3-python", "neo4j", "newspaper3k", "nltk", "openapi-spec-validator", "opencv-python", "pillow", "prance", "praw", "pyTelegramBotAPI", "pydub", "pygithub", "pymilvus", "pyowm", "qdrant-client", "rank-bm25", "redis", "reka-api", "requests_oauthlib", "scholarly", "sentence-transformers", "sentencepiece", "slack-sdk", "soundfile", "textblob", "torch", "transformers", "unstructured", "wikipedia", "wolframalpha"]encoders = ["sentence-transformers"]graph-storages = ["nebula3-python", "neo4j"]huggingface-agent = ["accelerate", "datasets", "diffusers", "opencv-python", "sentencepiece", "soundfile", "torch", "transformers"]@@ -9257,10 +9494,10 @@ rag = ["cohere", "nebula3-python", "neo4j", "pymilvus", "qdrant-client", "rank-bretrievers = ["cohere", "rank-bm25"]search-tools = ["duckduckgo-search", "wikipedia", "wolframalpha"]test = ["mock", "pytest", "pytest-asyncio"]-tools = ["PyMuPDF", "agentops", "arxiv", "arxiv2text", "beautifulsoup4", "discord.py", "docker", "docx2txt", "duckduckgo-search", "firecrawl-py", "googlemaps", "imageio", "jupyter_client", "newspaper3k", "nltk", "openapi-spec-validator", "pillow", "prance", "praw", "pyTelegramBotAPI", "pydub", "pygithub", "pyowm", "requests_oauthlib", "slack-sdk", "textblob", "unstructured", "wikipedia", "wolframalpha"]+tools = ["PyMuPDF", "agentops", "arxiv", "arxiv2text", "beautifulsoup4", "discord.py", "docker", "docx2txt", "duckduckgo-search", "firecrawl-py", "googlemaps", "imageio", "jupyter_client", "newspaper3k", "nltk", "openapi-spec-validator", "pillow", "prance", "praw", "pyTelegramBotAPI", "pydub", "pygithub", "pyowm", "requests_oauthlib", "scholarly", "slack-sdk", "textblob", "unstructured", "wikipedia", "wolframalpha"]vector-databases = ["pymilvus", "qdrant-client"][metadata]lock-version = "2.0"python-versions = ">=3.10.0,<=3.13"-content-hash = "262190989db7ae1e524b1f3442412c285cff302aa9d2b9a1b45b18478679115b"+content-hash = "dd92185c6f132df5561577938bce32b57b798166241971f02b5a6aa418459efe"diff --git a/pyproject.toml b/pyproject.tomlindex 6a7434ff4..ae3636ed0 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -91,6 +91,7 @@ botocore = { version = "^1.35.3", optional = true }nltk = { version = "3.8.1", optional = true }praw = { version = "^7.7.1", optional = true }textblob = { version = "^0.18.0.post0", optional = true }+scholarly = { extras = ["tor"], version = "1.7.11", optional = true }arxiv = { version = "^2.1.3", optional = true }arxiv2text = { version = "^0.1.14", optional = true }@@ -189,6 +190,7 @@ tools = ["agentops","praw","textblob",+ "scholarly",]vector-databases = [@@ -256,6 +258,7 @@ all = ["agentops","praw","textblob",+ "scholarly",# vector-database"qdrant-client","pymilvus",@@ -419,5 +422,6 @@ module = ["arxiv2text","praw","textblob",+ "scholarly",]ignore_missing_imports = truediff --git a/test/toolkits/test_google_scholar_toolkit.py b/test/toolkits/test_google_scholar_toolkit.pynew file mode 100644index 000000000..435023467--- /dev/null+++ b/test/toolkits/test_google_scholar_toolkit.py@@ -0,0 +1,94 @@+# =========== Copyright 2023 @ 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 @ CAMEL-AI.org. All Rights Reserved. ===========+from unittest.mock import patch++from camel.toolkits import FunctionTool, GoogleScholarToolkit+++def test_get_author_detailed_info_by_name():+ with patch('scholarly.scholarly') as mock_scholarly:+ mock_scholarly.fill.return_value = {+ 'name': 'Author Name',+ 'publications': [],+ }+ toolkit = GoogleScholarToolkit('Author Name')++ author_info = toolkit.get_author_detailed_info()+ assert author_info['name'] == 'Author Name'+ assert author_info['publications'] == []+++def test_get_author_detailed_info_by_url():+ with patch('scholarly.scholarly') as mock_scholarly:+ mock_scholarly.fill.return_value = {+ 'name': 'Author Name',+ 'publications': [],+ }+ toolkit = GoogleScholarToolkit(+ 'https://scholar.google.com/citations?user=J9K-D0sAAAAJ'+ )++ author_info = toolkit.get_author_detailed_info()+ assert author_info['name'] == 'Author Name'+ assert author_info['publications'] == []+++def test_get_author_publications():+ with patch('scholarly.scholarly') as mock_scholarly:+ mock_scholarly.fill.return_value = {+ 'publications': [+ {'bib': {'title': 'Publication 1'}},+ {'bib': {'title': 'Publication 2'}},+ ]+ }+ toolkit = GoogleScholarToolkit('Author Name')++ publications = toolkit.get_author_publications()+ assert publications == ['Publication 1', 'Publication 2']+++def test_get_publication_by_title_found():+ with patch('scholarly.scholarly') as mock_scholarly:+ mock_scholarly.fill.side_effect = [+ {+ 'publications': [+ {'bib': {'title': 'Publication 1'}},+ {'bib': {'title': 'Publication 2'}},+ ]+ },+ {'bib': {'title': 'Publication 1', 'abstract': 'An abstract'}},+ ]+ toolkit = GoogleScholarToolkit('Author Name')++ publication_info = toolkit.get_publication_by_title('Publication 1')+ assert publication_info is not None+ assert publication_info['bib']['title'] == 'Publication 1'+++def test_get_publication_by_title_not_found():+ with patch('scholarly.scholarly') as mock_scholarly:+ mock_scholarly.fill.return_value = {'publications': []}+ toolkit = GoogleScholarToolkit('Author Name')++ publication_info = toolkit.get_publication_by_title(+ 'Nonexistent Publication'+ )+ assert publication_info is None+++def test_get_tools():+ toolkit = GoogleScholarToolkit('Author Name')+ tools = toolkit.get_tools()+ assert len(tools) == 4+ assert all(isinstance(tool, FunctionTool) for tool in tools)