From 5a6d05acd30a417b9cace76ec4709fd0cc5fb602 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Mon, 22 Jan 2024 13:26:09 +0000 Subject: [PATCH] feat: Updated libs/langchain/langchain/tools/githu --- libs/langchain/langchain/tools/github/tool.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/libs/langchain/langchain/tools/github/tool.py b/libs/langchain/langchain/tools/github/tool.py index ec67fd2b3357b..ffeb879869627 100644 --- a/libs/langchain/langchain/tools/github/tool.py +++ b/libs/langchain/langchain/tools/github/tool.py @@ -7,6 +7,9 @@ GITHUB_REPOSITORY -> format: {owner}/{repo} """ +import logging +import os + from typing import Optional from langchain.callbacks.manager import CallbackManagerForToolRun @@ -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