diff --git a/openai_compatible_inference_bot.py b/openai_compatible_inference_bot.py index fc346bb..6688d03 100644 --- a/openai_compatible_inference_bot.py +++ b/openai_compatible_inference_bot.py @@ -144,7 +144,7 @@ class OpenAICompatibleInferenceBot(BaseTelegramInferenceBot): tool_calls_from_response = list(assistant_message.tool_calls) if assistant_message.tool_calls else [] tool_use_count = 0 - MAX_TOOL_ITERATIONS = 5 # OpenAI compatible typically uses fewer iterations than Anthropic + MAX_TOOL_ITERATIONS = 200 while tool_calls_from_response and tool_use_count < MAX_TOOL_ITERATIONS: tool_results_for_model = [] diff --git a/tools/github_ci_tool.py b/tools/github_ci_tool.py index b4a1422..715a321 100644 --- a/tools/github_ci_tool.py +++ b/tools/github_ci_tool.py @@ -16,9 +16,6 @@ class GitHubCIHelper(BaseTool): # Inherits from BaseTool specifically for fetching and analyzing test logs. """ def __init__(self, repo_owner: str = None, repo_name: str = None, github_token: str = None, session=None, logger_instance=None): - # Call BaseTool's init. BaseTool's __init__ expects 'logger' as the arg name. - super().__init__(logger=logger_instance) - # Logger setup: Prefer logger_instance, then BaseTool's logger, then a default. if logger_instance: self.logger = logger_instance @@ -121,7 +118,6 @@ class GitHubCIHelper(BaseTool): # Inherits from BaseTool } ] - @metrics.measure def execute(self, function_name, **kwargs): self.logger.info(f"Executing GitHub CI Helper function: {function_name} with args: {kwargs}") # Dispatch to the appropriate public method @@ -141,8 +137,6 @@ class GitHubCIHelper(BaseTool): # Inherits from BaseTool """Clears any sensitive state if necessary. For this tool, it's a no-op but present for interface consistency.""" self.logger.info("GitHubCIHelper state cleared (no specific state to clear).") - - @metrics.measure def _make_request(self, method: str, url: str, **kwargs): # Added @metrics.measure """Helper function for making HTTP requests.""" try: @@ -155,13 +149,12 @@ class GitHubCIHelper(BaseTool): # Inherits from BaseTool return response return None except requests.exceptions.HTTPError as e: - self.logger.error(f"HTTP error occurred: {e} - {e.response.text if e.response else "No response text"}") # Use self.logger + self.logger.error(f"HTTP error occurred: {e} - {e.response.text if e.response else 'No response text'}") # Use self.logger raise except requests.exceptions.RequestException as e: self.logger.error(f"Request failed: {e}") # Use self.logger raise - @metrics.measure def get_pr_workflow_runs(self, pull_request_number: int): # Added @metrics.measure """ Gets all workflow runs associated with a specific pull request. @@ -187,7 +180,6 @@ class GitHubCIHelper(BaseTool): # Inherits from BaseTool return None - @metrics.measure def get_latest_failed_run_for_pr(self, pull_request_number: int, workflow_name: str = "Python CI"): # Added @metrics.measure """ Gets the latest failed workflow run for a specific pull request and workflow name. @@ -205,7 +197,6 @@ class GitHubCIHelper(BaseTool): # Inherits from BaseTool self.logger.info(f"No failed run for workflow '{workflow_name}' found for PR #{pull_request_number}") # Use self.logger return None - @metrics.measure def get_job_logs_for_run(self, run_id: int, job_name: str = "test"): # Added @metrics.measure """ Downloads and returns the logs for a specific job within a workflow run. @@ -281,8 +272,6 @@ class GitHubCIHelper(BaseTool): # Inherits from BaseTool self.logger.error(f"An unexpected error occurred while processing logs for job {target_job.get('id', 'unknown') if target_job else 'unknown'}: {e}", exc_info=True) return f"Unexpected error processing logs: {e}" - - @metrics.measure def parse_unittest_failures_from_log(self, log_content: str): # Added @metrics.measure """ Parses unittest failure details from log content. @@ -360,52 +349,4 @@ class GitHubCIHelper(BaseTool): # Inherits from BaseTool if not failures: self.logger.info("No specific unittest failure blocks parsed with available patterns.") - return failures - - -# --- Example Usage (Illustrative) --- -if __name__ == "__main__": - # This example assumes you have GITHUB_TOKEN environment variable set - # And that 'requests' is installed. - # Replace with your actual repo owner, name, and PR number. - pr_number = 206 # Example PR - repo_owner = "bucolucas" # Example owner - repo_name = "cyclop" # Example repo - - # Setup basic logging for the example - # In a real app, logger would be configured externally - logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') - example_logger = logging.getLogger("GitHubCIHelperExample") - - - # Pass the logger to the helper - helper = GitHubCIHelper(repo_owner, repo_name, logger_instance=example_logger) - - example_logger.info(f"Looking for failed runs for PR #{pr_number} in {repo_owner}/{repo_name}") - failed_run = helper.get_latest_failed_run_for_pr(pull_request_number=pr_number, workflow_name="Python CI") - - if failed_run: - example_logger.info(f"Found failed run: ID {failed_run['id']}, Status {failed_run['conclusion']}") - example_logger.info(f"Attempting to download logs for job 'test' in run {failed_run['id']}...") - - log_content = helper.get_job_logs_for_run(run_id=failed_run['id'], job_name="test") - - if isinstance(log_content, str) and not log_content.startswith("Error") and not log_content.startswith("Job") and not log_content.startswith("Failed"): - example_logger.info(f"Successfully downloaded logs (length: {len(log_content)} characters).") - - example_logger.info("\n--- Parsing unittest failures ---") - failures = helper.parse_unittest_failures_from_log(log_content) - if failures: - for i, failure_details in enumerate(failures): - print(f"\nFailure {i+1}:\n{failure_details}") - else: - print("No specific unittest failures parsed by the tool.") - # Consider logging the beginning of the log if parsing fails, for debugging the regexes - # print(f"Log start:\n{log_content[:2000]}") - elif log_content is None: - example_logger.error("Could not retrieve log content (returned None).") - else: # If it's an error message string from the function itself - example_logger.error(f"Failed to get/process logs: {log_content}") - - else: - example_logger.info(f"No failed 'Python CI' workflow run found for PR #{pr_number} or the PR doesn't exist/no runs yet.") + return failures \ No newline at end of file