mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-03 19:57:51 +00:00
GitHubIssuesLoader Custom API URL Support (#11378)
- **Description:** Adds support for custom API URL in the GitHubIssuesLoader. This allows it to be used with Github enterprise instances.
This commit is contained in:
parent
16a80779b9
commit
939bceccb0
@ -17,6 +17,8 @@ class BaseGitHubLoader(BaseLoader, BaseModel, ABC):
|
|||||||
"""Name of repository"""
|
"""Name of repository"""
|
||||||
access_token: str
|
access_token: str
|
||||||
"""Personal access token - see https://github.com/settings/tokens?type=beta"""
|
"""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)
|
@root_validator(pre=True)
|
||||||
def validate_environment(cls, values: Dict) -> Dict:
|
def validate_environment(cls, values: Dict) -> Dict:
|
||||||
@ -183,4 +185,4 @@ class GitHubIssuesLoader(BaseGitHubLoader):
|
|||||||
@property
|
@property
|
||||||
def url(self) -> str:
|
def url(self) -> str:
|
||||||
"""Create URL for GitHub API."""
|
"""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}"
|
||||||
|
@ -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:
|
def test_invalid_initialization() -> None:
|
||||||
# Invalid parameter
|
# Invalid parameter
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
|
Loading…
Reference in New Issue
Block a user