From 66f40bec120f770d26b75aa70d885698ce8306b4 Mon Sep 17 00:00:00 2001 From: Hiroshi Nishio Date: Sun, 27 Oct 2024 15:44:41 -0700 Subject: [PATCH 1/2] Improve log readability by colorizing --- services/check_run_handler.py | 4 +++- services/gitauto_handler.py | 5 ++--- services/github/actions_manager.py | 1 - services/github/github_manager.py | 2 +- services/openai/commit_changes.py | 9 +++++---- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/services/check_run_handler.py b/services/check_run_handler.py index 490e7f9c..31f60323 100644 --- a/services/check_run_handler.py +++ b/services/check_run_handler.py @@ -166,7 +166,9 @@ def handle_check_run(payload: CheckRunCompletedPayload) -> None: } user_input = json.dumps(obj=input_message) how_to_fix: str = chat_with_ai(system_input=IDENTIFY_CAUSE, user_input=user_input) - print(f"how_to_fix:\n{how_to_fix}") + print(colorize(text="How to fix:", color="green")) + print(how_to_fix) + content = { "pull_request_title": pull_title, "file_tree": file_tree, diff --git a/services/gitauto_handler.py b/services/gitauto_handler.py index f0150a2b..f2c2cf89 100644 --- a/services/gitauto_handler.py +++ b/services/gitauto_handler.py @@ -36,7 +36,6 @@ ) from services.openai.commit_changes import chat_with_agent from services.openai.instructions.write_pr_body import WRITE_PR_BODY -from services.openai.truncate import truncate_message from services.openai.chat import chat_with_ai from services.supabase import SupabaseManager from utils.extract_urls import extract_urls @@ -97,7 +96,7 @@ async def handle_gitauto(payload: GitHubLabeledPayload, trigger_type: str) -> No "base_branch": base_branch_name, "new_branch": new_branch_name, "token": token, - "reviewers": list({sender_name, issuer_name}) + "reviewers": list({sender_name, issuer_name}), } print(f"Issue Title: {issue_title}\n") @@ -168,7 +167,7 @@ async def handle_gitauto(payload: GitHubLabeledPayload, trigger_type: str) -> No "issue_comments": issue_comments, "root_files_and_dirs": root_files_and_dirs, } - ) + ), ) base_args["pr_body"] = pr_body diff --git a/services/github/actions_manager.py b/services/github/actions_manager.py index def303be..31ff931b 100644 --- a/services/github/actions_manager.py +++ b/services/github/actions_manager.py @@ -67,7 +67,6 @@ def get_workflow_run_logs(owner: str, repo: str, run_id: int, token: str): for line in content.splitlines() ) content = f"```GitHub Check Run Log: {log_fname}\n{content}\n```" - print(content) return content return None diff --git a/services/github/github_manager.py b/services/github/github_manager.py index a5c141da..956940c8 100644 --- a/services/github/github_manager.py +++ b/services/github/github_manager.py @@ -164,7 +164,7 @@ def commit_changes_to_remote_branch( new_branch = base_args["new_branch"] if not new_branch: raise ValueError("new_branch is not set.") - url: str = f"{GITHUB_API_URL}/repos/{owner}/{repo}/contents/{file_path}?ref={new_branch}" + url = f"{GITHUB_API_URL}/repos/{owner}/{repo}/contents/{file_path}?ref={new_branch}" headers = create_headers(token=token) get_response = requests.get(url=url, headers=headers, timeout=TIMEOUT) diff --git a/services/openai/commit_changes.py b/services/openai/commit_changes.py index de2041fe..d821b7cd 100644 --- a/services/openai/commit_changes.py +++ b/services/openai/commit_changes.py @@ -86,15 +86,16 @@ def chat_with_agent( tool_call_id: str = tool_calls[0].id tool_name: str = tool_calls[0].function.name tool_args: dict = json.loads(tool_calls[0].function.arguments) - print(f"tool_name: {tool_name}") - print(f"tool_args: {tool_args}\n") + print(colorize(f"tool_name: {tool_name}", "green")) + print(colorize(f"tool_args: {tool_args}\n", "green")) # Check if the same function with the same args has been called before current_call = {"function": tool_name, "args": tool_args} if current_call in previous_calls: - print(f"The function '{tool_name}' was called with the same arguments as before") + msg = f"The function '{tool_name}' was called with the same arguments as before" + print(msg) tool_result: str = ( - f"The function '{tool_name}' was called with the same arguments as before, which is non-sense. You must open the file path in your tool args and update your diff content accordingly." + f"{msg}, which is non-sense. You must open the file path in your tool args and update your diff content accordingly." ) else: tool_result = tools_to_call[tool_name](**tool_args, base_args=base_args) From a5a8a0bbd3c2bd7e181bd74c32248e429eac7d47 Mon Sep 17 00:00:00 2001 From: Hiroshi Nishio Date: Sun, 27 Oct 2024 15:46:34 -0700 Subject: [PATCH 2/2] Stop using 'required' and use 'auto' for tool_choice parameter --- services/openai/commit_changes.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/services/openai/commit_changes.py b/services/openai/commit_changes.py index d821b7cd..581c12b0 100644 --- a/services/openai/commit_changes.py +++ b/services/openai/commit_changes.py @@ -45,15 +45,12 @@ def chat_with_agent( if mode == "commit": content = SYSTEM_INSTRUCTION_TO_COMMIT_CHANGES tools = TOOLS_TO_COMMIT_CHANGES - tool_choice = "auto" # DO NOT USE "required" and allow GitAuto not to call any tools. elif mode == "explore": content = SYSTEM_INSTRUCTION_TO_EXPLORE_REPO tools = TOOLS_TO_EXPLORE_REPO - tool_choice = "auto" # DO NOT USE "required" and allow GitAuto not to call any tools. elif mode == "get": content = SYSTEM_INSTRUCTION_TO_EXPLORE_REPO tools = TOOLS_TO_GET_FILE - tool_choice = "auto" # DO NOT USE "required" and allow GitAuto not to call any tools. system_message: ChatCompletionMessageParam = {"role": "system", "content": content} all_messages = [system_message] + list(messages) @@ -66,7 +63,7 @@ def chat_with_agent( temperature=OPENAI_TEMPERATURE, timeout=TIMEOUT, tools=tools, - tool_choice=tool_choice, + tool_choice="auto", # DO NOT USE "required" and allow GitAuto not to call any tools. parallel_tool_calls=False, ) choice: Choice = completion.choices[0]