Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ def __init__(
content_types: list[str] | None = None,
**kwargs: Any,
) -> None:
if content_types is not None:
kwargs["content_types"] = content_types
super().__init__(**kwargs)

if github_repo and content_types:
self.add(repo=github_repo, content_types=content_types)
if github_repo:
self.add(repo=github_repo, content_types=self.content_types)
self.description = f"A tool that can be used to semantic search a query the {github_repo} github repo's content. This is not the GitHub API, but instead a tool that can provide semantic search capabilities."
self.args_schema = FixedGithubSearchToolSchema
self._generate_description()
Expand Down
17 changes: 17 additions & 0 deletions lib/crewai-tools/tests/tools/test_search_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,20 @@ def test_github_search_tool(mock_adapter):
mock_adapter.query.assert_called_once_with(
"tell me about crewai repo", similarity_threshold=0.6, limit=5
)

# ensure content_types configured at construction is retained on dynamic tool
mock_adapter.query.reset_mock()
mock_adapter.add.reset_mock()

tool = GithubSearchTool(
gh_token="test_token",
content_types=["repo"],
adapter=mock_adapter,
)
assert tool.content_types == ["repo"]
tool.add(repo="crewai/crewai")
mock_adapter.add.assert_called_once_with(
"https://github.com/crewai/crewai",
data_type=DataType.GITHUB,
metadata={"content_types": ["repo"], "gh_token": "test_token"},
)
Loading