diff --git a/libs/langchain/langchain/document_loaders/github.py b/libs/langchain/langchain/document_loaders/github.py index e3dc44b579..63cda0f844 100644 --- a/libs/langchain/langchain/document_loaders/github.py +++ b/libs/langchain/langchain/document_loaders/github.py @@ -17,6 +17,8 @@ class BaseGitHubLoader(BaseLoader, BaseModel, ABC): """Name of repository""" access_token: str """Personal access token - see https://github.com/settings/tokens?type=beta""" + github_api_url: str = "https://api.github.com" + """URL of GitHub API""" @root_validator(pre=True) def validate_environment(cls, values: Dict) -> Dict: @@ -183,4 +185,4 @@ class GitHubIssuesLoader(BaseGitHubLoader): @property def url(self) -> str: """Create URL for GitHub API.""" - return f"https://api.github.com/repos/{self.repo}/issues?{self.query_params}" + return f"{self.github_api_url}/repos/{self.repo}/issues?{self.query_params}" diff --git a/libs/langchain/tests/unit_tests/document_loaders/test_github.py b/libs/langchain/tests/unit_tests/document_loaders/test_github.py index ef88026548..097589329a 100644 --- a/libs/langchain/tests/unit_tests/document_loaders/test_github.py +++ b/libs/langchain/tests/unit_tests/document_loaders/test_github.py @@ -15,6 +15,21 @@ def test_initialization() -> None: } +def test_initialization_ghe() -> None: + loader = GitHubIssuesLoader( + repo="repo", + access_token="access_token", + github_api_url="https://github.example.com/api/v3", + ) + assert loader.repo == "repo" + assert loader.access_token == "access_token" + assert loader.github_api_url == "https://github.example.com/api/v3" + assert loader.headers == { + "Accept": "application/vnd.github+json", + "Authorization": "Bearer access_token", + } + + def test_invalid_initialization() -> None: # Invalid parameter with pytest.raises(ValueError):