mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-23 23:29:21 +00:00
community: correct return type of get_files_from_directory in github tool (#27885)
### About: - **Description:** the _get_files_from_directory_ method return a string, but it's used in other methods that expect a List[str] - **Issue:** None - **Dependencies:** None This pull request import a new method _list_files_ with the old logic of _get_files_from_directory_, but it return a List[str] at the end. The behavior of _ get_files_from_directory_ is not changed.
This commit is contained in:
parent
580a8d53f9
commit
b79a1156ed
@ -213,7 +213,7 @@ class GitHubAPIWrapper(BaseModel):
|
|||||||
)
|
)
|
||||||
for content in contents:
|
for content in contents:
|
||||||
if content.type == "dir":
|
if content.type == "dir":
|
||||||
files.extend(self.get_files_from_directory(content.path))
|
files.extend(self._list_files(content.path))
|
||||||
else:
|
else:
|
||||||
files.append(content.path)
|
files.append(content.path)
|
||||||
|
|
||||||
@ -324,7 +324,7 @@ class GitHubAPIWrapper(BaseModel):
|
|||||||
)
|
)
|
||||||
for content in contents:
|
for content in contents:
|
||||||
if content.type == "dir":
|
if content.type == "dir":
|
||||||
files.extend(self.get_files_from_directory(content.path))
|
files.extend(self._list_files(content.path))
|
||||||
else:
|
else:
|
||||||
files.append(content.path)
|
files.append(content.path)
|
||||||
|
|
||||||
@ -351,20 +351,24 @@ class GitHubAPIWrapper(BaseModel):
|
|||||||
"""
|
"""
|
||||||
from github import GithubException
|
from github import GithubException
|
||||||
|
|
||||||
files: List[str] = []
|
|
||||||
try:
|
try:
|
||||||
contents = self.github_repo_instance.get_contents(
|
return str(self._list_files(directory_path))
|
||||||
directory_path, ref=self.active_branch
|
|
||||||
)
|
|
||||||
except GithubException as e:
|
except GithubException as e:
|
||||||
return f"Error: status code {e.status}, {e.message}"
|
return f"Error: status code {e.status}, {e.message}"
|
||||||
|
|
||||||
|
def _list_files(self, directory_path: str) -> List[str]:
|
||||||
|
files: List[str] = []
|
||||||
|
|
||||||
|
contents = self.github_repo_instance.get_contents(
|
||||||
|
directory_path, ref=self.active_branch
|
||||||
|
)
|
||||||
|
|
||||||
for content in contents:
|
for content in contents:
|
||||||
if content.type == "dir":
|
if content.type == "dir":
|
||||||
files.extend(self.get_files_from_directory(content.path))
|
files.extend(self._list_files(content.path))
|
||||||
else:
|
else:
|
||||||
files.append(content.path)
|
files.append(content.path)
|
||||||
return str(files)
|
return files
|
||||||
|
|
||||||
def get_issue(self, issue_number: int) -> Dict[str, Any]:
|
def get_issue(self, issue_number: int) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user