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
2 changes: 2 additions & 0 deletions .github/workflows/langchain_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ concurrency:
env:
POETRY_VERSION: "1.5.1"
WORKDIR: "libs/langchain"
EXTENDED_TESTING: "extended_testing"

jobs:
lint:
Expand Down Expand Up @@ -70,6 +71,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
poetry-version: ${{ env.POETRY_VERSION }}
extra-args: -E extended_testing
working-directory: libs/langchain
cache-key: extended

Expand Down
39 changes: 39 additions & 0 deletions libs/langchain/langchain/tools/github/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,33 @@
from langchain.utilities.github import GitHubAPIWrapper


class GitHubAction(BaseTool):
"""Tool for interacting with the GitHub API."""

api_wrapper: GitHubAPIWrapper = Field(default_factory=GitHubAPIWrapper)
mode: str
name: str = ""
description: str = ""

def _run(
self,
instructions: str,
run_manager: Optional[CallbackManagerForToolRun] = None,
) -> str:
"""Use the GitHub API to run an operation."""
try:
return self.api_wrapper.run(self.mode, instructions)
except Exception as e:
# Handle the exception and log the error
print(f"Error occurred: {e}")
return ""

from langchain.callbacks.manager import CallbackManagerForToolRun
from langchain.pydantic_v1 import Field
from langchain.tools.base import BaseTool
from langchain.utilities.github import GitHubAPIWrapper


class GitHubAction(BaseTool):
"""Tool for interacting with the GitHub API."""

Expand All @@ -30,3 +57,15 @@ def _run(
) -> str:
"""Use the GitHub API to run an operation."""
return self.api_wrapper.run(self.mode, instructions)
def _run(
self,
instructions: str,
run_manager: Optional[CallbackManagerForToolRun] = None,
) -> str:
"""Use the GitHub API to run an operation."""
try:
return self.api_wrapper.run(self.mode, instructions)
except Exception as e:
# Handle the exception and log the error
print(f"Error occurred: {e}")
return ""
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@


@pytest.fixture
def api_client() -> GitHubAPIWrapper:
def api_client(mocker) -> GitHubAPIWrapper:
return GitHubAPIWrapper()


def test_get_open_issues(api_client: GitHubAPIWrapper) -> None:
def test_get_open_issues(api_client: GitHubAPIWrapper, mocker):
"""Basic test to fetch issues"""
issues = api_client.get_issues()
assert len(issues) != 0