Skip to content

Commit

Permalink
formatted and added --use-llm flag
Browse files Browse the repository at this point in the history
  • Loading branch information
hrshdhgd committed Aug 22, 2024
1 parent 2b4d71b commit 7c9973a
Showing 1 changed file with 57 additions and 40 deletions.
97 changes: 57 additions & 40 deletions src/ontobot_change_agent/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ def main(verbose: int, quiet: bool):
type=click.Path(exists=True),
help="Path to jar file.",
)
use_llm_option = click.option(
"--use-llm", is_flag=True, default=False, help="Use llm-change-agent for processing."
)


@main.command()
Expand Down Expand Up @@ -173,6 +176,7 @@ def get_labels(repo: str, token: str):
@state_option
@jar_path_option
@output_option
@use_llm_option
def process_issue(
input: str,
repo: str,
Expand All @@ -184,6 +188,7 @@ def process_issue(
state: str,
jar_path: str,
output: str,
use_llm: bool = False,
):
"""Run processes based on issue label.
Expand All @@ -205,52 +210,64 @@ def process_issue(
)

else:
for issue in get_issues(
issues = get_issues(
repository_name=repo, token=token, label=label, number=number, state=state
):
# Make sure ontobot_change_agent needs to be triggered or no.
if issue and issue[BODY]:

KGCL_COMMANDS = []
if NEW_TERM_LABEL in issue["labels"]:
formatted_body = "The following input was provided: </br> "
KGCL_COMMANDS, body_as_dict, reason = process_new_term_template(
issue["body"], prefix
)
if reason is None:
formatted_body += _convert_to_markdown(body_as_dict)
formatted_body += "</br> The following commands were executed: </br> "
else:
click.echo(
f"""{issue[TITLE]} does not need ontobot's attention since {reason}""", # noqa
)
break

elif re.match(r"(.*)ontobot(.*)apply(.*):(.*)", issue[BODY].lower(), re.DOTALL):
)
ontobot_pattern = re.compile(r"(.*)ontobot(.*)apply(.*):(.*)", re.DOTALL)

click.echo("Starting to process issues...")

for issue in issues:
if not issue or not issue[BODY]:
click.echo(
f"Issue number:{number} is either closed, does not exist or has no body."
)
break

click.echo(f"Processing issue: {issue[TITLE]}")

KGCL_COMMANDS = []
formatted_body = ""

if NEW_TERM_LABEL in issue["labels"]:
click.echo("New term label found. Processing new term template...")
formatted_body = "The following input was provided: </br> "
KGCL_COMMANDS, body_as_dict, reason = process_new_term_template(
issue["body"], prefix
)
if reason is None:
click.echo("No reason found to skip. Converting body to markdown...")
formatted_body += _convert_to_markdown(body_as_dict)
formatted_body += "</br> The following commands were executed: </br> "
else:
click.echo(f"{issue[TITLE]} does not need ontobot's attention since {reason}")
break
elif ontobot_pattern.match(issue[BODY].lower()):
click.echo("Ontobot apply command found. Extracting KGCL commands...")
formatted_body = "The following commands were executed: </br> "
KGCL_COMMANDS = _get_kgcl_commands(issue[BODY])

elif use_llm:
click.echo(f"Summoning llm-change-agent for {issue[TITLE]}")
with click.Context(execute) as ctx:
ctx.params["prompt"] = issue[BODY]
ctx.params["provider"] = "cborg"
ctx.params["model"] = "google/gemini:latest"
response = execute.invoke(ctx)
KGCL_COMMANDS = [
command.replace('"', "'") for command in ast.literal_eval(response)
]
if KGCL_COMMANDS:
click.echo(f"llm-change-agent result: {response}")
formatted_body = "The following commands were executed: </br> "
KGCL_COMMANDS = _get_kgcl_commands(issue[BODY])
click.echo(formatted_body + "\n".join(KGCL_COMMANDS))
else:
# ! llm-change-agent activate!
click.echo(f"Summoning llm-change-agent for {issue[TITLE]}")
with click.Context(execute) as ctx:
ctx.params["prompt"] = issue[BODY]
ctx.params["provider"] = "cborg"
ctx.params["model"] = "google/gemini:latest"
response = execute.invoke(ctx)
KGCL_COMMANDS = [
command.replace('"', "'") for command in ast.literal_eval(response)
]

if len(KGCL_COMMANDS) > 0:
click.echo(f"llm-change-agent result: {response}")
formatted_body = "The following commands were executed: </br> "
else:
click.echo(f"""{issue[TITLE]} does not need ontobot's attention.""")
click.echo(f"{issue[TITLE]} does not need ontobot's attention.")
else:
click.echo(
f"""Issue number:{number} is either closed, does not exist or has no body."""
f"""{issue[TITLE]} does not need ontobot's
attention unless `--use-llm` flag is True."""
)
break

new_output = output if output else input

Expand Down

0 comments on commit 7c9973a

Please sign in to comment.