Skip to content

Commit

Permalink
clean up and drop temp
Browse files Browse the repository at this point in the history
  • Loading branch information
sivang committed Oct 5, 2023
1 parent 497e5c9 commit 2472ece
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
5 changes: 2 additions & 3 deletions agit/openai_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ async def translate_to_git_command(natural_language, explain):
"role": "system",
"content": "You are an expert git revision control system mentor, you translate natural language to a "
"coherent git command. You will only return commands that are for the git RCS tool and refuse "
"commands to other software. You will not use ANY OTHER commands like grep or sort or anything similar -- "
"Just plain git revision control commands."
"commands to other software."
f"You will also return short description of the command to the user.",
},
{
Expand Down Expand Up @@ -100,7 +99,7 @@ async def review_patch(diff_content, instruct_review):
openai.ChatCompletion.acreate(
model="gpt-3.5-turbo-16k",
messages=prompt_template,
temperature=0.2,
temperature=0.1,
)
)
with tqdm.tqdm(
Expand Down
19 changes: 19 additions & 0 deletions agit/os_iface.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@
from agit.util import is_interactive_command


def split_piped_command_string(command_string):
commands = command_string.split()
commands = [cmd.strip() for cmd in commands]
print (f"commands: {commands}")

match commands:
case ['|', *after]:
print(f"There's a pipe with commands before and after it. {after}")
case [*before, '|']:
print (f"{before}")
case _:
print("There's no pipe.")


def normalize(command_string: str):
quoted = quotedString.searchString(command_string)
quotes = None
Expand All @@ -36,6 +50,7 @@ def normalize(command_string: str):
else:
normalized_command_list = command_string.split()

print (f"After quotes removal: {normalized_command_list}")
eq_parts = []
result_list = []
for part in normalized_command_list:
Expand All @@ -47,6 +62,8 @@ def normalize(command_string: str):
if part.endswith("=") or part.endswith(":"):
eq_parts.append(part)

print(f"After parts parsing: {result_list}")

normalized_command_list = result_list
return normalized_command_list

Expand All @@ -56,6 +73,7 @@ def execute_git_command(command_string: str):
return "Command list is empty."

interactive = is_interactive_command(command_string)
split_piped_command_string(command_string)
normalized_command_list = normalize(command_string=command_string)

# Check if the git command is in the list of allowed commands
Expand All @@ -65,6 +83,7 @@ def execute_git_command(command_string: str):
return f"Command '{normalized_command_list[0]}' is not allowed."

# Execute the command
print(normalized_command_list)
try:
result = subprocess.run(
["git", "-c", "color.ui=always", "-c", "log.decorate=true"]
Expand Down

0 comments on commit 2472ece

Please sign in to comment.