Skip to content

Commit

Permalink
Merge pull request #356 from gitautoai/wes
Browse files Browse the repository at this point in the history
Improve log readability by colorizing and do some minor refactorings
  • Loading branch information
hiroshinishio authored Oct 27, 2024
2 parents 29cf17e + a5a8a0b commit b206d4b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
4 changes: 3 additions & 1 deletion services/check_run_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions services/gitauto_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion services/github/actions_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion services/github/github_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
14 changes: 6 additions & 8 deletions services/openai/commit_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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]
Expand All @@ -86,15 +83,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)
Expand Down

0 comments on commit b206d4b

Please sign in to comment.