Skip to content

Commit

Permalink
Merge pull request #95 from INCATools/remove-template-support
Browse files Browse the repository at this point in the history
Template detection deprecated.
  • Loading branch information
hrshdhgd authored Sep 5, 2024
2 parents 8f752ba + 2226204 commit 2100409
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 32 deletions.
20 changes: 10 additions & 10 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ python = ">=3.9,<4.0.0"
oaklib = ">=0.5.0"
PyGithub = "^2.3.0"
setuptools = ">=70.1.1"
llm-change-agent = {version = "^0.0.4", extras = ["llm"], optional = true}
llm-change-agent = {version = "^0.0.7", extras = ["llm"], optional = true}


[tool.poetry.group.dev.dependencies]
Expand Down
2 changes: 2 additions & 0 deletions src/ontobot_change_agent/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import kgcl_schema.grammar.parser as kgcl_parser
import requests
import yaml
from deprecated import deprecated
from github import Github
from github.Issue import Issue
from oaklib.cli import query_terms_iterator
Expand Down Expand Up @@ -192,6 +193,7 @@ def process_issue_via_oak(input: str, commands: list, output: str = None):
impl_obj.dump(output, output_format)


@deprecated(version="0.5.0", reason="Use process_issue_via_oak instead.")
def process_new_term_template(body, prefix):
"""Process an issue generated via new term request template.
Expand Down
55 changes: 36 additions & 19 deletions src/ontobot_change_agent/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,35 @@

import click

from ontobot_change_agent.constants import OWL_EXTENSION

try:
from llm_change_agent.cli import execute
from llm_change_agent.utils.llm_utils import (
extract_commands,
get_anthropic_models,
get_lbl_cborg_models,
get_ollama_models,
get_openai_models,
)

from ontobot_change_agent.constants import (
ANTHROPIC_PROVIDER,
CBORG_PROVIDER,
OLLAMA_PROVIDER,
OPENAI_PROVIDER,
)

llm_change_agent_available = True
ALL_AVAILABLE_PROVIDERS = [OPENAI_PROVIDER, OLLAMA_PROVIDER, ANTHROPIC_PROVIDER, CBORG_PROVIDER]
ALL_AVAILABLE_MODELS = (
get_openai_models() + get_ollama_models() + get_anthropic_models() + get_lbl_cborg_models()
)
except ImportError:
# Handle the case where the package is not installed
llm_change_agent_available = False
ALL_AVAILABLE_PROVIDERS = []
ALL_AVAILABLE_MODELS = []


from ontobot_change_agent import __version__
Expand All @@ -27,9 +49,7 @@
get_ontobot_implementers,
process_issue_via_jar,
process_issue_via_oak,
process_new_term_template,
)
from ontobot_change_agent.constants import NEW_TERM_LABEL, OWL_EXTENSION

__all__ = [
"main",
Expand Down Expand Up @@ -123,6 +143,12 @@ def main(verbose: int, quiet: bool):
default=False,
help="Use llm-change-agent for processing.",
)
llm_provider_option = click.option(
"--provider", type=click.Choice(ALL_AVAILABLE_PROVIDERS), help="Provider to use for generation."
)
llm_model_option = click.option(
"--model", type=click.Choice(ALL_AVAILABLE_MODELS), help="Model to use for generation."
)


@main.command()
Expand Down Expand Up @@ -188,6 +214,8 @@ def get_labels(repo: str, token: str):
@jar_path_option
@output_option
@use_llm_option
@llm_provider_option
@llm_model_option
def process_issue(
input: str,
repo: str,
Expand All @@ -200,6 +228,8 @@ def process_issue(
jar_path: str,
output: str,
use_llm: bool = False,
provider: str = None,
model: str = None,
):
"""Run processes based on issue label.
Expand Down Expand Up @@ -240,20 +270,7 @@ def process_issue(
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()):
if 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])
Expand All @@ -262,9 +279,9 @@ def process_issue(
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)
ctx.params["provider"] = provider
ctx.params["model"] = model
response = extract_commands(execute.invoke(ctx))
KGCL_COMMANDS = [
command.replace('"', "'") for command in ast.literal_eval(response)
]
Expand Down
17 changes: 15 additions & 2 deletions src/ontobot_change_agent/constants.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
"""Constants."""

NEW_TERM_LABEL = "New term request"
SYNONYM_LABEL = "synonym"
from os import getenv

# GitHUb Template Attributes.
SYNONYMS = "Synonyms"
SYNONYM_TYPE = "Synonym type"
DEFINITION = "Definition"
OWL_EXTENSION = ".owl"

OPENAI_KEY = str(getenv("OPENAI_API_KEY"))
ANTHROPIC_KEY = str(getenv("ANTHROPIC_API_KEY"))
CBORG_KEY = str(getenv("CBORG_API_KEY"))

OPEN_AI_MODEL = "gpt-4o-2024-08-06"
ANTHROPIC_MODEL = "claude-3-5-sonnet-20240620"
OLLAMA_MODEL = "llama3.1" # ! not all models support tools (tool calling)
CBORG_MODEL = "anthropic/claude-sonnet"

OPENAI_PROVIDER = "openai"
ANTHROPIC_PROVIDER = "anthropic"
OLLAMA_PROVIDER = "ollama"
CBORG_PROVIDER = "cborg"

0 comments on commit 2100409

Please sign in to comment.