Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

chore: enhance toolkit function naming (#3038)

Wendong-Fan38b7cef85633
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index af8f016ea..ec38d359c 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -195,6 +195,25 @@ Examples:
By adhering to this principle, we ensure that CAMEL remains accessible and unambiguous for both developers and AI agents.
+#### Toolkit Function Naming Principle: Use Toolkit-Specific Prefixes
+
+All public functions in CAMEL toolkits MUST include a toolkit-specific prefix to prevent naming conflicts and improve code clarity.
+
+**Naming Pattern:**
+```
+<toolkit_prefix>_<action>_<resource>
+```
+
+**Examples:**
+- Good: `github_create_issue()`, `twitter_delete_tweet()`, `excel_create_workbook()`
+- Bad: `create_issue()`, `delete_tweet()`, `create_workbook()`
+
+**Key Requirements:**
+1. **Consistent Prefixes**: All public methods in a toolkit must use the same prefix
+2. **No Built-in Shadowing**: Never use names that shadow Python built-ins (e.g., avoid `round()`, use `math_round()`)
+3. **Clear Association**: The prefix should clearly identify which toolkit the function belongs to
+4. **Backward Compatibility**: When renaming functions, provide deprecated aliases with warnings for at least 2 minor versions
+
#### Logging Principle: Use `logger` Instead of `print`
Avoid using `print` for output. Use Python's `logging` module (`logger`) to ensure consistent, configurable, and professional logging.
diff --git a/camel/toolkits/github_toolkit.py b/camel/toolkits/github_toolkit.py
index f29cbccae..354bc603d 100644
--- a/camel/toolkits/github_toolkit.py
+++ b/camel/toolkits/github_toolkit.py
@@ -14,6 +14,7 @@
import logging
import os
+import warnings
from typing import Dict, List, Literal, Optional, Union
from camel.toolkits import FunctionTool
@@ -80,7 +81,7 @@ class GithubToolkit(BaseToolkit):
)
return GITHUB_ACCESS_TOKEN
- def create_pull_request(
+ def github_create_pull_request(
self,
repo_name: str,
file_path: str,
@@ -150,7 +151,7 @@ class GithubToolkit(BaseToolkit):
else:
raise ValueError("PRs with multiple files aren't supported yet.")
- def get_issue_list(
+ def github_get_issue_list(
self, repo_name: str, state: Literal["open", "closed", "all"] = "all"
) -> List[Dict[str, object]]:
r"""Retrieves all issues from the GitHub repository.
@@ -177,7 +178,9 @@ class GithubToolkit(BaseToolkit):
return issues_info
- def get_issue_content(self, repo_name: str, issue_number: int) -> str:
+ def github_get_issue_content(
+ self, repo_name: str, issue_number: int
+ ) -> str:
r"""Retrieves the content of a specific issue by its number.
Args:
@@ -194,7 +197,7 @@ class GithubToolkit(BaseToolkit):
except Exception as e:
return f"can't get Issue number {issue_number}: {e!s}"
- def get_pull_request_list(
+ def github_get_pull_request_list(
self, repo_name: str, state: Literal["open", "closed", "all"] = "all"
) -> List[Dict[str, object]]:
r"""Retrieves all pull requests from the GitHub repository.
@@ -221,7 +224,7 @@ class GithubToolkit(BaseToolkit):
return pull_requests_info
- def get_pull_request_code(
+ def github_get_pull_request_code(
self, repo_name: str, pr_number: int
) -> List[Dict[str, str]]:
r"""Retrieves the code changes of a specific pull request.
@@ -253,7 +256,7 @@ class GithubToolkit(BaseToolkit):
return files_changed
- def get_pull_request_comments(
+ def github_get_pull_request_comments(
self, repo_name: str, pr_number: int
) -> List[Dict[str, str]]:
r"""Retrieves the comments from a specific pull request.
@@ -278,7 +281,9 @@ class GithubToolkit(BaseToolkit):
return comments
- def get_all_file_paths(self, repo_name: str, path: str = "") -> List[str]:
+ def github_get_all_file_paths(
+ self, repo_name: str, path: str = ""
+ ) -> List[str]:
r"""Recursively retrieves all file paths in the GitHub repository.
Args:
@@ -308,13 +313,15 @@ class GithubToolkit(BaseToolkit):
for content in contents:
if content.type == "dir":
# If it's a directory, recursively retrieve its file paths
- files.extend(self.get_all_file_paths(content.path))
+ files.extend(self.github_get_all_file_paths(content.path))
else:
# If it's a file, add its path to the list
files.append(content.path)
return files
- def retrieve_file_content(self, repo_name: str, file_path: str) -> str:
+ def github_retrieve_file_content(
+ self, repo_name: str, file_path: str
+ ) -> str:
r"""Retrieves the content of a file from the GitHub repository.
Args:
@@ -343,12 +350,92 @@ class GithubToolkit(BaseToolkit):
the functions in the toolkit.
"""
return [
- FunctionTool(self.create_pull_request),
- FunctionTool(self.get_issue_list),
- FunctionTool(self.get_issue_content),
- FunctionTool(self.get_pull_request_list),
- FunctionTool(self.get_pull_request_code),
- FunctionTool(self.get_pull_request_comments),
- FunctionTool(self.get_all_file_paths),
- FunctionTool(self.retrieve_file_content),
+ FunctionTool(self.github_create_pull_request),
+ FunctionTool(self.github_get_issue_list),
+ FunctionTool(self.github_get_issue_content),
+ FunctionTool(self.github_get_pull_request_list),
+ FunctionTool(self.github_get_pull_request_code),
+ FunctionTool(self.github_get_pull_request_comments),
+ FunctionTool(self.github_get_all_file_paths),
+ FunctionTool(self.github_retrieve_file_content),
]
+
+ # Deprecated method aliases for backward compatibility
+ def create_pull_request(self, *args, **kwargs):
+ r"""Deprecated: Use github_create_pull_request instead."""
+ warnings.warn(
+ "create_pull_request is deprecated. Use "
+ "github_create_pull_request instead.",
+ DeprecationWarning,
+ stacklevel=2,
+ )
+ return self.github_create_pull_request(*args, **kwargs)
+
+ def get_issue_list(self, *args, **kwargs):
+ r"""Deprecated: Use github_get_issue_list instead."""
+ warnings.warn(
+ "get_issue_list is deprecated. Use github_get_issue_list instead.",
+ DeprecationWarning,
+ stacklevel=2,
+ )
+ return self.github_get_issue_list(*args, **kwargs)
+
+ def get_issue_content(self, *args, **kwargs):
+ r"""Deprecated: Use github_get_issue_content instead."""
+ warnings.warn(
+ "get_issue_content is deprecated. Use "
+ "github_get_issue_content instead.",
+ DeprecationWarning,
+ stacklevel=2,
+ )
+ return self.github_get_issue_content(*args, **kwargs)
+
+ def get_pull_request_list(self, *args, **kwargs):
+ r"""Deprecated: Use github_get_pull_request_list instead."""
+ warnings.warn(
+ "get_pull_request_list is deprecated. "
+ "Use github_get_pull_request_list instead.",
+ DeprecationWarning,
+ stacklevel=2,
+ )
+ return self.github_get_pull_request_list(*args, **kwargs)
+
+ def get_pull_request_code(self, *args, **kwargs):
+ r"""Deprecated: Use github_get_pull_request_code instead."""
+ warnings.warn(
+ "get_pull_request_code is deprecated. Use "
+ "github_get_pull_request_code instead.",
+ DeprecationWarning,
+ stacklevel=2,
+ )
+ return self.github_get_pull_request_code(*args, **kwargs)
+
+ def get_pull_request_comments(self, *args, **kwargs):
+ r"""Deprecated: Use github_get_pull_request_comments instead."""
+ warnings.warn(
+ "get_pull_request_comments is deprecated. "
+ "Use github_get_pull_request_comments instead.",
+ DeprecationWarning,
+ stacklevel=2,
+ )
+ return self.github_get_pull_request_comments(*args, **kwargs)
+
+ def get_all_file_paths(self, *args, **kwargs):
+ r"""Deprecated: Use github_get_all_file_paths instead."""
+ warnings.warn(
+ "get_all_file_paths is deprecated. Use "
+ "github_get_all_file_paths instead.",
+ DeprecationWarning,
+ stacklevel=2,
+ )
+ return self.github_get_all_file_paths(*args, **kwargs)
+
+ def retrieve_file_content(self, *args, **kwargs):
+ r"""Deprecated: Use github_retrieve_file_content instead."""
+ warnings.warn(
+ "retrieve_file_content is deprecated. "
+ "Use github_retrieve_file_content instead.",
+ DeprecationWarning,
+ stacklevel=2,
+ )
+ return self.github_retrieve_file_content(*args, **kwargs)
diff --git a/camel/toolkits/math_toolkit.py b/camel/toolkits/math_toolkit.py
index 24c5b70b1..14c60257d 100644
--- a/camel/toolkits/math_toolkit.py
+++ b/camel/toolkits/math_toolkit.py
@@ -12,6 +12,7 @@
# limitations under the License.
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
+import warnings
from typing import List
from camel.toolkits.base import BaseToolkit
@@ -27,7 +28,7 @@ class MathToolkit(BaseToolkit):
addition, subtraction, multiplication, division, and rounding.
"""
- def add(self, a: float, b: float) -> float:
+ def math_add(self, a: float, b: float) -> float:
r"""Adds two numbers.
Args:
@@ -39,7 +40,7 @@ class MathToolkit(BaseToolkit):
"""
return a + b
- def sub(self, a: float, b: float) -> float:
+ def math_subtract(self, a: float, b: float) -> float:
r"""Do subtraction between two numbers.
Args:
@@ -51,7 +52,9 @@ class MathToolkit(BaseToolkit):
"""
return a - b
- def multiply(self, a: float, b: float, decimal_places: int = 2) -> float:
+ def math_multiply(
+ self, a: float, b: float, decimal_places: int = 2
+ ) -> float:
r"""Multiplies two numbers.
Args:
@@ -65,7 +68,9 @@ class MathToolkit(BaseToolkit):
"""
return round(a * b, decimal_places)
- def divide(self, a: float, b: float, decimal_places: int = 2) -> float:
+ def math_divide(
+ self, a: float, b: float, decimal_places: int = 2
+ ) -> float:
r"""Divides two numbers.
Args:
@@ -79,7 +84,7 @@ class MathToolkit(BaseToolkit):
"""
return round(a / b, decimal_places)
- def round(self, a: float, decimal_places: int = 0) -> float:
+ def math_round(self, a: float, decimal_places: int = 0) -> float:
r"""Rounds a number to a specified number of decimal places.
Args:
@@ -101,9 +106,58 @@ class MathToolkit(BaseToolkit):
representing the functions in the toolkit.
"""
return [
- FunctionTool(self.add),
- FunctionTool(self.sub),
- FunctionTool(self.multiply),
- FunctionTool(self.divide),
- FunctionTool(self.round),
+ FunctionTool(self.math_add),
+ FunctionTool(self.math_subtract),
+ FunctionTool(self.math_multiply),
+ FunctionTool(self.math_divide),
+ FunctionTool(self.math_round),
]
+
+ # Deprecated method aliases for backward compatibility
+ def add(self, *args, **kwargs):
+ r"""Deprecated: Use math_add instead."""
+ warnings.warn(
+ "add is deprecated. Use math_add instead.",
+ DeprecationWarning,
+ stacklevel=2,
+ )
+ return self.math_add(*args, **kwargs)
+
+ def sub(self, *args, **kwargs):
+ r"""Deprecated: Use math_subtract instead."""
+ warnings.warn(
+ "sub is deprecated. Use math_subtract instead.",
+ DeprecationWarning,
+ stacklevel=2,
+ )
+ return self.math_subtract(*args, **kwargs)
+
+ def multiply(self, *args, **kwargs):
+ r"""Deprecated: Use math_multiply instead."""
+ warnings.warn(
+ "multiply is deprecated. Use math_multiply instead.",
+ DeprecationWarning,
+ stacklevel=2,
+ )
+ return self.math_multiply(*args, **kwargs)
+
+ def divide(self, *args, **kwargs):
+ r"""Deprecated: Use math_divide instead."""
+ warnings.warn(
+ "divide is deprecated. Use math_divide instead.",
+ DeprecationWarning,
+ stacklevel=2,
+ )
+ return self.math_divide(*args, **kwargs)
+
+ def round(self, *args, **kwargs):
+ r"""Deprecated: Use math_round instead. Note: This was shadowing
+ Python's built-in round().
+ """
+ warnings.warn(
+ "round is deprecated. Use math_round instead. This was "
+ "shadowing Python's built-in round().",
+ DeprecationWarning,
+ stacklevel=2,
+ )
+ return self.math_round(*args, **kwargs)
diff --git a/camel/toolkits/search_toolkit.py b/camel/toolkits/search_toolkit.py
index 59dd07805..f67c42427 100644
--- a/camel/toolkits/search_toolkit.py
+++ b/camel/toolkits/search_toolkit.py
@@ -12,6 +12,7 @@
# limitations under the License.
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
import os
+import warnings
from typing import Any, Dict, List, Literal, Optional, TypeAlias, Union, cast
import requests
@@ -683,7 +684,7 @@ class SearchToolkit(BaseToolkit):
responses.append({"error": f"google search failed: {e!s}"})
return responses
- def tavily_search(
+ def search_tavily(
self, query: str, number_of_result_pages: int = 10, **kwargs
) -> List[Dict[str, Any]]:
r"""Use Tavily Search API to search information for the given query.
@@ -1358,7 +1359,7 @@ class SearchToolkit(BaseToolkit):
FunctionTool(self.search_linkup),
FunctionTool(self.search_google),
FunctionTool(self.search_duckduckgo),
- FunctionTool(self.tavily_search),
+ FunctionTool(self.search_tavily),
FunctionTool(self.search_brave),
FunctionTool(self.search_bocha),
FunctionTool(self.search_baidu),
@@ -1367,3 +1368,13 @@ class SearchToolkit(BaseToolkit):
FunctionTool(self.search_alibaba_tongxiao),
FunctionTool(self.search_metaso),
]
+
+ # Deprecated method alias for backward compatibility
+ def tavily_search(self, *args, **kwargs):
+ r"""Deprecated: Use search_tavily instead for consistency with other search methods."""
+ warnings.warn(
+ "tavily_search is deprecated. Use search_tavily instead for consistency.",
+ DeprecationWarning,
+ stacklevel=2,
+ )
+ return self.search_tavily(*args, **kwargs)
diff --git a/docs/mintlify/reference/camel.toolkits.github_toolkit.mdx b/docs/mintlify/reference/camel.toolkits.github_toolkit.mdx
index 3dce0c210..d5e8a5412 100644
--- a/docs/mintlify/reference/camel.toolkits.github_toolkit.mdx
+++ b/docs/mintlify/reference/camel.toolkits.github_toolkit.mdx
@@ -49,12 +49,12 @@ def get_github_access_token(self):
str: A string containing the GitHub access token.
-<a id="camel.toolkits.github_toolkit.GithubToolkit.create_pull_request"></a>
+<a id="camel.toolkits.github_toolkit.GithubToolkit.github_create_pull_request"></a>
-### create_pull_request
+### github_create_pull_request
```python
-def create_pull_request(
+def github_create_pull_request(
self,
repo_name: str,
file_path: str,
@@ -85,12 +85,12 @@ description contains information about the issue title and number.
str: A formatted report of whether the pull request was created
successfully or not.
-<a id="camel.toolkits.github_toolkit.GithubToolkit.get_issue_list"></a>
+<a id="camel.toolkits.github_toolkit.GithubToolkit.github_get_issue_list"></a>
-### get_issue_list
+### github_get_issue_list
```python
-def get_issue_list(
+def github_get_issue_list(
self,
repo_name: str,
state: Literal['open', 'closed', 'all'] = 'all'
@@ -109,12 +109,12 @@ Retrieves all issues from the GitHub repository.
List[Dict[str, object]]: A list of dictionaries where each
dictionary contains the issue number and title.
-<a id="camel.toolkits.github_toolkit.GithubToolkit.get_issue_content"></a>
+<a id="camel.toolkits.github_toolkit.GithubToolkit.github_get_issue_content"></a>
-### get_issue_content
+### github_get_issue_content
```python
-def get_issue_content(self, repo_name: str, issue_number: int):
+def github_get_issue_content(self, repo_name: str, issue_number: int):
```
Retrieves the content of a specific issue by its number.
@@ -128,12 +128,12 @@ Retrieves the content of a specific issue by its number.
str: issues content details.
-<a id="camel.toolkits.github_toolkit.GithubToolkit.get_pull_request_list"></a>
+<a id="camel.toolkits.github_toolkit.GithubToolkit.github_get_pull_request_list"></a>
-### get_pull_request_list
+### github_get_pull_request_list
```python
-def get_pull_request_list(
+def github_get_pull_request_list(
self,
repo_name: str,
state: Literal['open', 'closed', 'all'] = 'all'
@@ -152,12 +152,12 @@ Retrieves all pull requests from the GitHub repository.
list: A list of dictionaries where each dictionary contains the
pull request number and title.
-<a id="camel.toolkits.github_toolkit.GithubToolkit.get_pull_request_code"></a>
+<a id="camel.toolkits.github_toolkit.GithubToolkit.github_get_pull_request_code"></a>
-### get_pull_request_code
+### github_get_pull_request_code
```python
-def get_pull_request_code(self, repo_name: str, pr_number: int):
+def github_get_pull_request_code(self, repo_name: str, pr_number: int):
```
Retrieves the code changes of a specific pull request.
@@ -173,12 +173,12 @@ Retrieves the code changes of a specific pull request.
contains the file name and the corresponding code changes
(patch).
-<a id="camel.toolkits.github_toolkit.GithubToolkit.get_pull_request_comments"></a>
+<a id="camel.toolkits.github_toolkit.GithubToolkit.github_get_pull_request_comments"></a>
-### get_pull_request_comments
+### github_get_pull_request_comments
```python
-def get_pull_request_comments(self, repo_name: str, pr_number: int):
+def github_get_pull_request_comments(self, repo_name: str, pr_number: int):
```
Retrieves the comments from a specific pull request.
@@ -193,12 +193,12 @@ Retrieves the comments from a specific pull request.
List[Dict[str, str]]: A list of dictionaries where each dictionary
contains the user ID and the comment body.
-<a id="camel.toolkits.github_toolkit.GithubToolkit.get_all_file_paths"></a>
+<a id="camel.toolkits.github_toolkit.GithubToolkit.github_get_all_file_paths"></a>
-### get_all_file_paths
+### github_get_all_file_paths
```python
-def get_all_file_paths(self, repo_name: str, path: str = ''):
+def github_get_all_file_paths(self, repo_name: str, path: str = ''):
```
Recursively retrieves all file paths in the GitHub repository.
@@ -213,12 +213,12 @@ Recursively retrieves all file paths in the GitHub repository.
List[str]: A list of file paths within the specified directory
structure.
-<a id="camel.toolkits.github_toolkit.GithubToolkit.retrieve_file_content"></a>
+<a id="camel.toolkits.github_toolkit.GithubToolkit.github_retrieve_file_content"></a>
-### retrieve_file_content
+### github_retrieve_file_content
```python
-def retrieve_file_content(self, repo_name: str, file_path: str):
+def github_retrieve_file_content(self, repo_name: str, file_path: str):
```
Retrieves the content of a file from the GitHub repository.
diff --git a/docs/mintlify/reference/camel.toolkits.search_toolkit.mdx b/docs/mintlify/reference/camel.toolkits.search_toolkit.mdx
index 92c3b0cf2..91e1a4c1e 100644
--- a/docs/mintlify/reference/camel.toolkits.search_toolkit.mdx
+++ b/docs/mintlify/reference/camel.toolkits.search_toolkit.mdx
@@ -236,12 +236,12 @@ Example image result:
'height': 600
\}`
-<a id="camel.toolkits.search_toolkit.SearchToolkit.tavily_search"></a>
+<a id="camel.toolkits.search_toolkit.SearchToolkit.search_tavily"></a>
-### tavily_search
+### search_tavily
```python
-def tavily_search(
+def search_tavily(
self,
query: str,
number_of_result_pages: int = 10,
diff --git a/docs/reference/camel.toolkits.github_toolkit.md b/docs/reference/camel.toolkits.github_toolkit.md
index 3dce0c210..d5e8a5412 100644
--- a/docs/reference/camel.toolkits.github_toolkit.md
+++ b/docs/reference/camel.toolkits.github_toolkit.md
@@ -49,12 +49,12 @@ def get_github_access_token(self):
str: A string containing the GitHub access token.
-<a id="camel.toolkits.github_toolkit.GithubToolkit.create_pull_request"></a>
+<a id="camel.toolkits.github_toolkit.GithubToolkit.github_create_pull_request"></a>
-### create_pull_request
+### github_create_pull_request
```python
-def create_pull_request(
+def github_create_pull_request(
self,
repo_name: str,
file_path: str,
@@ -85,12 +85,12 @@ description contains information about the issue title and number.
str: A formatted report of whether the pull request was created
successfully or not.
-<a id="camel.toolkits.github_toolkit.GithubToolkit.get_issue_list"></a>
+<a id="camel.toolkits.github_toolkit.GithubToolkit.github_get_issue_list"></a>
-### get_issue_list
+### github_get_issue_list
```python
-def get_issue_list(
+def github_get_issue_list(
self,
repo_name: str,
state: Literal['open', 'closed', 'all'] = 'all'
@@ -109,12 +109,12 @@ Retrieves all issues from the GitHub repository.
List[Dict[str, object]]: A list of dictionaries where each
dictionary contains the issue number and title.
-<a id="camel.toolkits.github_toolkit.GithubToolkit.get_issue_content"></a>
+<a id="camel.toolkits.github_toolkit.GithubToolkit.github_get_issue_content"></a>
-### get_issue_content
+### github_get_issue_content
```python
-def get_issue_content(self, repo_name: str, issue_number: int):
+def github_get_issue_content(self, repo_name: str, issue_number: int):
```
Retrieves the content of a specific issue by its number.
@@ -128,12 +128,12 @@ Retrieves the content of a specific issue by its number.
str: issues content details.
-<a id="camel.toolkits.github_toolkit.GithubToolkit.get_pull_request_list"></a>
+<a id="camel.toolkits.github_toolkit.GithubToolkit.github_get_pull_request_list"></a>
-### get_pull_request_list
+### github_get_pull_request_list
```python
-def get_pull_request_list(
+def github_get_pull_request_list(
self,
repo_name: str,
state: Literal['open', 'closed', 'all'] = 'all'
@@ -152,12 +152,12 @@ Retrieves all pull requests from the GitHub repository.
list: A list of dictionaries where each dictionary contains the
pull request number and title.
-<a id="camel.toolkits.github_toolkit.GithubToolkit.get_pull_request_code"></a>
+<a id="camel.toolkits.github_toolkit.GithubToolkit.github_get_pull_request_code"></a>
-### get_pull_request_code
+### github_get_pull_request_code
```python
-def get_pull_request_code(self, repo_name: str, pr_number: int):
+def github_get_pull_request_code(self, repo_name: str, pr_number: int):
```
Retrieves the code changes of a specific pull request.
@@ -173,12 +173,12 @@ Retrieves the code changes of a specific pull request.
contains the file name and the corresponding code changes
(patch).
-<a id="camel.toolkits.github_toolkit.GithubToolkit.get_pull_request_comments"></a>
+<a id="camel.toolkits.github_toolkit.GithubToolkit.github_get_pull_request_comments"></a>
-### get_pull_request_comments
+### github_get_pull_request_comments
```python
-def get_pull_request_comments(self, repo_name: str, pr_number: int):
+def github_get_pull_request_comments(self, repo_name: str, pr_number: int):
```
Retrieves the comments from a specific pull request.
@@ -193,12 +193,12 @@ Retrieves the comments from a specific pull request.
List[Dict[str, str]]: A list of dictionaries where each dictionary
contains the user ID and the comment body.
-<a id="camel.toolkits.github_toolkit.GithubToolkit.get_all_file_paths"></a>
+<a id="camel.toolkits.github_toolkit.GithubToolkit.github_get_all_file_paths"></a>
-### get_all_file_paths
+### github_get_all_file_paths
```python
-def get_all_file_paths(self, repo_name: str, path: str = ''):
+def github_get_all_file_paths(self, repo_name: str, path: str = ''):
```
Recursively retrieves all file paths in the GitHub repository.
@@ -213,12 +213,12 @@ Recursively retrieves all file paths in the GitHub repository.
List[str]: A list of file paths within the specified directory
structure.
-<a id="camel.toolkits.github_toolkit.GithubToolkit.retrieve_file_content"></a>
+<a id="camel.toolkits.github_toolkit.GithubToolkit.github_retrieve_file_content"></a>
-### retrieve_file_content
+### github_retrieve_file_content
```python
-def retrieve_file_content(self, repo_name: str, file_path: str):
+def github_retrieve_file_content(self, repo_name: str, file_path: str):
```
Retrieves the content of a file from the GitHub repository.
diff --git a/docs/reference/camel.toolkits.search_toolkit.md b/docs/reference/camel.toolkits.search_toolkit.md
index 4723dfdaf..c2f531b07 100644
--- a/docs/reference/camel.toolkits.search_toolkit.md
+++ b/docs/reference/camel.toolkits.search_toolkit.md
@@ -175,12 +175,12 @@ Each dictionary contains the following keys:
- 'long_description': More detail of the website.
- 'url': The URL of the website.
-<a id="camel.toolkits.search_toolkit.SearchToolkit.tavily_search"></a>
+<a id="camel.toolkits.search_toolkit.SearchToolkit.search_tavily"></a>
-### tavily_search
+### search_tavily
```python
-def tavily_search(
+def search_tavily(
self,
query: str,
num_results: int = 5,
diff --git a/examples/toolkits/github_toolkit.py b/examples/toolkits/github_toolkit.py
index f2fed95ae..a3a626400 100644
--- a/examples/toolkits/github_toolkit.py
+++ b/examples/toolkits/github_toolkit.py
@@ -17,7 +17,7 @@ from camel.toolkits import GithubToolkit
gt = GithubToolkit()
# Retrieve a list of all file paths within the camel GitHub repository
-paths = gt.get_all_file_paths(repo_name="camel-ai/camel")
+paths = gt.github_get_all_file_paths(repo_name="camel-ai/camel")
print(paths)
"""
===============================================================================
@@ -46,7 +46,7 @@ agents/base.py', 'camel/agents/chat_agent.py', 'camel/agents/critic_agent.py',
"""
# Retrieve the content of a specific file in the repository
-content = gt.retrieve_file_content(
+content = gt.github_retrieve_file_content(
repo_name="camel-ai/camel", file_path="camel/agents/chat_agent.py"
)
print(content[:1000])
diff --git a/test/agents/test_chat_agent.py b/test/agents/test_chat_agent.py
index e9db8ef9c..461dff829 100644
--- a/test/agents/test_chat_agent.py
+++ b/test/agents/test_chat_agent.py
@@ -317,7 +317,8 @@ def test_chat_agent_step_with_external_tools(step_call_count=3):
ChatCompletionMessageFunctionToolCall(
id='call_mock_123456',
function=Function(
- arguments='{"a":1776,"b":2007}', name='sub'
+ arguments='{"a":1776,"b":2007}',
+ name='math_subtract',
),
type='function',
)
@@ -364,7 +365,7 @@ def test_chat_agent_step_with_external_tools(step_call_count=3):
"external_tool_call_requests"
]
assert (
- external_tool_call_requests[0].tool_name == "sub"
+ external_tool_call_requests[0].tool_name == "math_subtract"
), f"Error in calling round {i+1}"
@@ -448,7 +449,8 @@ async def test_chat_agent_astep_with_external_tools(step_call_count=3):
ChatCompletionMessageFunctionToolCall(
id='call_mock_123456',
function=Function(
- arguments='{"a":1776,"b":2007}', name='sub'
+ arguments='{"a":1776,"b":2007}',
+ name='math_subtract',
),
type='function',
)
@@ -507,7 +509,7 @@ async def test_chat_agent_astep_with_external_tools(step_call_count=3):
"external_tool_call_requests"
]
assert (
- external_tool_call_requests[0].tool_name == "sub"
+ external_tool_call_requests[0].tool_name == "math_subtract"
), f"Error in calling round {i+1}"
@@ -863,14 +865,15 @@ def test_tool_calling_sync(step_call_count=3):
"b": 8, \
"decimal_places": 0 \
}',
- name='multiply',
+ name='math_multiply',
),
type='function',
),
ChatCompletionMessageFunctionToolCall(
id='call_mock_123457',
function=Function(
- arguments='{"a": 0, "b": 10}', name='sub'
+ arguments='{"a": 0, "b": 10}',
+ name='math_subtract',
),
type='function',
),
@@ -903,7 +906,8 @@ def test_tool_calling_sync(step_call_count=3):
ChatCompletionMessageFunctionToolCall(
id='call_kIJby7Y6As6gAbWoxDqxD6HG',
function=Function(
- arguments='{"a":16,"b":10}', name='sub'
+ arguments='{"a":16,"b":10}',
+ name='math_subtract',
),
type='function',
)
@@ -967,7 +971,7 @@ def test_tool_calling_sync(step_call_count=3):
"Tool Execution"
), f"Error in calling round {i+1}"
assert (
- tool_calls[0].tool_name == "multiply"
+ tool_calls[0].tool_name == "math_multiply"
), f"Error in calling round {i+1}"
assert tool_calls[0].args == {
"a": 2,
@@ -987,7 +991,9 @@ async def test_tool_calling_math_async(step_call_count=3):
content="You are a help assistant.",
)
model_config = ChatGPTConfig(temperature=0)
- math_funcs = sync_funcs_to_async([FunctionTool(MathToolkit().multiply)])
+ math_funcs = sync_funcs_to_async(
+ [FunctionTool(MathToolkit().math_multiply)]
+ )
model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type=ModelType.GPT_5_MINI,
@@ -1032,7 +1038,7 @@ async def test_tool_calling_math_async(step_call_count=3):
"b": 8, \
"decimal_places": 0 \
}',
- name='multiply',
+ name='math_multiply',
),
type='function',
)
@@ -1088,7 +1094,7 @@ async def test_tool_calling_math_async(step_call_count=3):
tool_calls = agent_response.info['tool_calls']
assert (
- tool_calls[0].tool_name == "multiply"
+ tool_calls[0].tool_name == "math_multiply"
), f"Error in calling round {i+1}"
assert tool_calls[0].args == {
"a": 2,
diff --git a/test/toolkits/test_github_toolkit.py b/test/toolkits/test_github_toolkit.py
index 27e7efb22..b34994841 100644
--- a/test/toolkits/test_github_toolkit.py
+++ b/test/toolkits/test_github_toolkit.py
@@ -105,8 +105,8 @@ def test_get_tools(mock_github):
@patch.dict('sys.modules', mock_modules)
@patch('github.Github')
-def test_create_pull_request(mock_github):
- """Test create_pull_request functionality."""
+def test_github_create_pull_request(mock_github):
+ """Test github_create_pull_request functionality."""
# Set up mock
mock_repo = MagicMock()
mock_github.return_value.get_repo.return_value = mock_repo
@@ -124,9 +124,9 @@ def test_create_pull_request(mock_github):
mock_pr_response.body = "Fixes #1"
mock_repo.create_pull.return_value = mock_pr_response
- # Create a simplified version of create_pull_request that
+ # Create a simplified version of github_create_pull_request that
# skips the isinstance check
- def simplified_create_pull_request(
+ def simplified_github_create_pull_request(
self, repo_name, file_path, new_content, pr_title, body, branch_name
):
# Get the repo using the repo_name parameter
@@ -139,9 +139,9 @@ def test_create_pull_request(mock_github):
return f"Title: {pr_title}\nBody: {body}\n"
# Replace the method temporarily
- original_method = github_toolkit.create_pull_request
- github_toolkit.create_pull_request = (
- simplified_create_pull_request.__get__(github_toolkit)
+ original_method = github_toolkit.github_create_pull_request
+ github_toolkit.github_create_pull_request = (
+ simplified_github_create_pull_request.__get__(github_toolkit)
)
try:
@@ -150,7 +150,7 @@ def test_create_pull_request(mock_github):
for product_of_array_except_self.py"""
body = "Fixes #1"
- pr = github_toolkit.create_pull_request(
+ pr = github_toolkit.github_create_pull_request(
repo_name="repo_name",
file_path="path/to/file",
branch_name="branch_name",
@@ -160,7 +160,7 @@ def test_create_pull_request(mock_github):
)
finally:
# Restore the original method
- github_toolkit.create_pull_request = original_method
+ github_toolkit.github_create_pull_request = original_method
expected_response = f"Title: {pr_title}\nBody: {body}\n"
assert pr == expected_response, f"Expected {expected_response}, got {pr}"
@@ -169,7 +169,7 @@ def test_create_pull_request(mock_github):
@patch.dict('sys.modules', mock_modules)
@patch('github.Github')
def test_get_all_issues(mock_github):
- r"""Test get_issue_list functionality."""
+ r"""Test github_get_issue_list functionality."""
# Set up mock
mock_repo = MagicMock()
mock_github.return_value.get_repo.return_value = mock_repo
@@ -180,13 +180,13 @@ def test_get_all_issues(mock_github):
mock_issue.number = 1
mock_issue.title = "Test Issue"
mock_repo.get_issues.return_value = [mock_issue]
- # Mock the get_issue_list method to return our expected result
+ # Mock the github_get_issue_list method to return our expected result
with patch.object(
github_toolkit,
- 'get_issue_list',
+ 'github_get_issue_list',
return_value=[{"number": 1, "title": "Test Issue"}],
):
- issues = github_toolkit.get_issue_list(repo_name="repo_name")
+ issues = github_toolkit.github_get_issue_list(repo_name="repo_name")
expected_issues = [{"number": 1, "title": "Test Issue"}]
assert (
issues == expected_issues
@@ -195,8 +195,8 @@ def test_get_all_issues(mock_github):
@patch.dict('sys.modules', mock_modules)
@patch('github.Github')
-def test_get_issue_content(mock_github):
- r"""Test get_issue_content functionality."""
+def test_github_get_issue_content(mock_github):
+ r"""Test github_get_issue_content functionality."""
# Set up mock
mock_repo = MagicMock()
mock_github.return_value.get_repo.return_value = mock_repo
@@ -206,11 +206,13 @@ def test_get_issue_content(mock_github):
mock_issue = MagicMock()
mock_issue.body = "Issue content"
mock_repo.get_issue.return_value = mock_issue
- # Mock the get_issue_content method to return our expected result
+ # Mock the github_get_issue_content method to return our expected result
with patch.object(
- github_toolkit, 'get_issue_content', return_value="Issue content"
+ github_toolkit,
+ 'github_get_issue_content',
+ return_value="Issue content",
):
- content = github_toolkit.get_issue_content(
+ content = github_toolkit.github_get_issue_content(
repo_name="repo_name", issue_number=1
)
expected_content = "Issue content"
@@ -222,7 +224,7 @@ def test_get_issue_content(mock_github):
@patch.dict('sys.modules', mock_modules)
@patch('github.Github')
def test_get_all_pull_requests(mock_github):
- r"""Test get_pull_request_list functionality."""
+ r"""Test github_get_pull_request_list functionality."""
# Set up mock
mock_repo = MagicMock()
mock_github.return_value.get_repo.return_value = mock_repo
@@ -233,21 +235,24 @@ def test_get_all_pull_requests(mock_github):
mock_pr.number = 1
mock_pr.title = "Test PR"
mock_repo.get_pulls.return_value = [mock_pr]
- # Mock the get_pull_request_list method to return our expected result
+ # Mock the github_get_pull_request_list method to return our expected
+ # result
with patch.object(
github_toolkit,
- 'get_pull_request_list',
+ 'github_get_pull_request_list',
return_value=[{"number": 1, "title": "Test PR"}],
):
- prs = github_toolkit.get_pull_request_list(repo_name="repo_name")
+ prs = github_toolkit.github_get_pull_request_list(
+ repo_name="repo_name"
+ )
expected_prs = [{"number": 1, "title": "Test PR"}]
assert prs == expected_prs, f"Expected {expected_prs}, got {prs}"
@patch.dict('sys.modules', mock_modules)
@patch('github.Github')
-def test_get_pull_request_code(mock_github):
- r"""Test get_pull_request_code functionality."""
+def test_github_get_pull_request_code(mock_github):
+ r"""Test github_get_pull_request_code functionality."""
# Set up mock
mock_repo = MagicMock()
mock_github.return_value.get_repo.return_value = mock_repo
@@ -260,13 +265,14 @@ def test_get_pull_request_code(mock_github):
mock_pr = MagicMock()
mock_pr.get_files.return_value = [mock_file]
mock_repo.get_pull.return_value = mock_pr
- # Mock the get_pull_request_code method to return our expected result
+ # Mock the github_get_pull_request_code method to return our expected
+ # result
with patch.object(
github_toolkit,
- 'get_pull_request_code',
+ 'github_get_pull_request_code',
return_value=[{"filename": "file1.py", "patch": "code changes"}],
):
- files_changed = github_toolkit.get_pull_request_code(
+ files_changed = github_toolkit.github_get_pull_request_code(
repo_name="repo_name", pr_number=1
)
expected_files = [{"filename": "file1.py", "patch": "code changes"}]
@@ -277,8 +283,8 @@ def test_get_pull_request_code(mock_github):
@patch.dict('sys.modules', mock_modules)
@patch('github.Github')
-def test_get_pull_request_comments(mock_github):
- r"""Test get_pull_request_comments functionality."""
+def test_github_get_pull_request_comments(mock_github):
+ r"""Test github_get_pull_request_comments functionality."""
# Set up mock
mock_repo = MagicMock()
mock_github.return_value.get_repo.return_value = mock_repo
@@ -293,13 +299,14 @@ def test_get_pull_request_comments(mock_github):
mock_pr = MagicMock()
mock_pr.get_comments.return_value = [mock_comment]
mock_repo.get_pull.return_value = mock_pr
- # Mock the get_pull_request_comments method to return our expected result
+ # Mock the github_get_pull_request_comments method to return our expected
+ # result
with patch.object(
github_toolkit,
- 'get_pull_request_comments',
+ 'github_get_pull_request_comments',
return_value=[{"user": "user1", "body": "Test comment"}],
):
- comments = github_toolkit.get_pull_request_comments(
+ comments = github_toolkit.github_get_pull_request_comments(
repo_name="repo_name", pr_number=1
)
expected_comments = [{"user": "user1", "body": "Test comment"}]
@@ -310,8 +317,8 @@ def test_get_pull_request_comments(mock_github):
@patch.dict('sys.modules', mock_modules)
@patch('github.Github')
-def test_get_all_file_paths(mock_github):
- r"""Test get_all_file_paths functionality."""
+def test_github_get_all_file_paths(mock_github):
+ r"""Test github_get_all_file_paths functionality."""
# Set up mock
mock_repo = MagicMock()
mock_github.return_value.get_repo.return_value = mock_repo
@@ -320,11 +327,13 @@ def test_get_all_file_paths(mock_github):
# Setup content
content_file = ContentFile(path="path/to/file.py", type="file")
mock_repo.get_contents.return_value = [content_file]
- # Mock the get_all_file_paths method to return our expected result
+ # Mock the github_get_all_file_paths method to return our expected result
with patch.object(
- github_toolkit, 'get_all_file_paths', return_value=["path/to/file.py"]
+ github_toolkit,
+ 'github_get_all_file_paths',
+ return_value=["path/to/file.py"],
):
- files = github_toolkit.get_all_file_paths(repo_name="repo_name")
+ files = github_toolkit.github_get_all_file_paths(repo_name="repo_name")
expected_files = ["path/to/file.py"]
assert (
files == expected_files