Skip to content
Open
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
19 changes: 17 additions & 2 deletions libs/langchain/langchain/tools/github/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
GITHUB_REPOSITORY -> format: {owner}/{repo}

"""
import logging
import os

from typing import Optional

from langchain.callbacks.manager import CallbackManagerForToolRun
Expand All @@ -23,10 +26,22 @@ class GitHubAction(BaseTool):
name: str = ""
description: str = ""

def _run(
def _run_with_error_handling(
self,
instructions: str,
run_manager: Optional[CallbackManagerForToolRun] = None,
) -> str:
"""Use the GitHub API to run an operation."""
return self.api_wrapper.run(self.mode, instructions)
import logging
import os

try:
# Ensure necessary environment variables are set
if "GITHUB_API_TOKEN" not in os.environ or "GITHUB_REPOSITORY" not in os.environ:
raise Exception("Environment variables GITHUB_API_TOKEN and GITHUB_REPOSITORY are missing")
# Use the GitHub API to run an operation
return self.api_wrapper.run(self.mode, instructions)
except Exception as e:
# Log any errors or exceptions
logging.error(f"An error occurred during the GitHub API call: {e}")
raise