From 0c6159bbb866b3863b558ce976b71dc17c526351 Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Thu, 5 Sep 2024 13:07:56 -0500 Subject: [PATCH 1/9] Template detection deprecated. --- src/ontobot_change_agent/cli.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/ontobot_change_agent/cli.py b/src/ontobot_change_agent/cli.py index b97ab74..40774bf 100644 --- a/src/ontobot_change_agent/cli.py +++ b/src/ontobot_change_agent/cli.py @@ -240,20 +240,20 @@ 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:
" - 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 += "
The following commands were executed:
" - else: - click.echo(f"{issue[TITLE]} does not need ontobot's attention since {reason}") - break - elif ontobot_pattern.match(issue[BODY].lower()): + # if NEW_TERM_LABEL in issue["labels"]: + # click.echo("New term label found. Processing new term template...") + # formatted_body = "The following input was provided:
" + # 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 += "
The following commands were executed:
" + # else: + # click.echo(f"{issue[TITLE]} does not need ontobot's attention since {reason}") + # break + if ontobot_pattern.match(issue[BODY].lower()): click.echo("Ontobot apply command found. Extracting KGCL commands...") formatted_body = "The following commands were executed:
" KGCL_COMMANDS = _get_kgcl_commands(issue[BODY]) From 4b10e26c65753d1e80595f11ac67810ee6639340 Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Thu, 5 Sep 2024 13:09:54 -0500 Subject: [PATCH 2/9] label detection removed --- src/ontobot_change_agent/cli.py | 15 +-------------- src/ontobot_change_agent/constants.py | 3 --- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/src/ontobot_change_agent/cli.py b/src/ontobot_change_agent/cli.py index 40774bf..760effb 100644 --- a/src/ontobot_change_agent/cli.py +++ b/src/ontobot_change_agent/cli.py @@ -29,7 +29,7 @@ process_issue_via_oak, process_new_term_template, ) -from ontobot_change_agent.constants import NEW_TERM_LABEL, OWL_EXTENSION +from ontobot_change_agent.constants import OWL_EXTENSION __all__ = [ "main", @@ -240,19 +240,6 @@ 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:
" - # 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 += "
The following commands were executed:
" - # else: - # click.echo(f"{issue[TITLE]} does not need ontobot's attention since {reason}") - # break if ontobot_pattern.match(issue[BODY].lower()): click.echo("Ontobot apply command found. Extracting KGCL commands...") formatted_body = "The following commands were executed:
" diff --git a/src/ontobot_change_agent/constants.py b/src/ontobot_change_agent/constants.py index ed32436..e3e603b 100644 --- a/src/ontobot_change_agent/constants.py +++ b/src/ontobot_change_agent/constants.py @@ -1,8 +1,5 @@ """Constants.""" -NEW_TERM_LABEL = "New term request" -SYNONYM_LABEL = "synonym" - # GitHUb Template Attributes. SYNONYMS = "Synonyms" SYNONYM_TYPE = "Synonym type" From 7e9193b31e991920d42a9968b6788e3acd39e157 Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Thu, 5 Sep 2024 13:13:30 -0500 Subject: [PATCH 3/9] deprecate function --- src/ontobot_change_agent/api.py | 2 ++ src/ontobot_change_agent/cli.py | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ontobot_change_agent/api.py b/src/ontobot_change_agent/api.py index 081951b..d16f6c2 100644 --- a/src/ontobot_change_agent/api.py +++ b/src/ontobot_change_agent/api.py @@ -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 @@ -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. diff --git a/src/ontobot_change_agent/cli.py b/src/ontobot_change_agent/cli.py index 760effb..6d1fd21 100644 --- a/src/ontobot_change_agent/cli.py +++ b/src/ontobot_change_agent/cli.py @@ -27,7 +27,6 @@ get_ontobot_implementers, process_issue_via_jar, process_issue_via_oak, - process_new_term_template, ) from ontobot_change_agent.constants import OWL_EXTENSION From eef1306b6c99c3087e8b031ec071e109ed648651 Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Thu, 5 Sep 2024 15:09:45 -0500 Subject: [PATCH 4/9] Updated model provider for LLM --- src/ontobot_change_agent/cli.py | 6 +++--- src/ontobot_change_agent/constants.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/ontobot_change_agent/cli.py b/src/ontobot_change_agent/cli.py index 6d1fd21..7d7facb 100644 --- a/src/ontobot_change_agent/cli.py +++ b/src/ontobot_change_agent/cli.py @@ -28,7 +28,7 @@ process_issue_via_jar, process_issue_via_oak, ) -from ontobot_change_agent.constants import OWL_EXTENSION +from ontobot_change_agent.constants import OPEN_AI_MODEL, OPENAI_PROVIDER, OWL_EXTENSION __all__ = [ "main", @@ -248,8 +248,8 @@ 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" + ctx.params["provider"] = OPENAI_PROVIDER + ctx.params["model"] = OPEN_AI_MODEL response = execute.invoke(ctx) KGCL_COMMANDS = [ command.replace('"', "'") for command in ast.literal_eval(response) diff --git a/src/ontobot_change_agent/constants.py b/src/ontobot_change_agent/constants.py index e3e603b..69e4d1d 100644 --- a/src/ontobot_change_agent/constants.py +++ b/src/ontobot_change_agent/constants.py @@ -1,7 +1,22 @@ """Constants.""" +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" \ No newline at end of file From 1cb47759b233bfe8a9e9a050f1d3b65b0687b825 Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Thu, 5 Sep 2024 15:15:17 -0500 Subject: [PATCH 5/9] formatted --- poetry.lock | 20 ++++++++++---------- pyproject.toml | 2 +- src/ontobot_change_agent/constants.py | 5 +++-- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/poetry.lock b/poetry.lock index ab3fa98..7a531ac 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2146,13 +2146,13 @@ langchain-core = ">=0.2.38,<0.3.0" [[package]] name = "langsmith" -version = "0.1.114" +version = "0.1.115" description = "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform." optional = true python-versions = "<4.0,>=3.8.1" files = [ - {file = "langsmith-0.1.114-py3-none-any.whl", hash = "sha256:2b6b6b49ddb1cea75f465da107ddc21e60d3c7242813dcc0de90f914e4957249"}, - {file = "langsmith-0.1.114.tar.gz", hash = "sha256:1683e1505d034d1bf7c960067c1357fd0d294172dd20540f913093e4b86857a2"}, + {file = "langsmith-0.1.115-py3-none-any.whl", hash = "sha256:04e35cfd4c2d4ff1ea10bb577ff43957b05ebb3d9eb4e06e200701f4a2b4ac9f"}, + {file = "langsmith-0.1.115.tar.gz", hash = "sha256:3b775377d858d32354f3ee0dd1ed637068cfe9a1f13e7b3bfa82db1615cdffc9"}, ] [package.dependencies] @@ -2226,13 +2226,13 @@ requests = "*" [[package]] name = "llm-change-agent" -version = "0.0.4" +version = "0.0.7" description = "llm-change-agent" optional = true python-versions = "<4.0,>=3.9" files = [ - {file = "llm_change_agent-0.0.4-py3-none-any.whl", hash = "sha256:0dc915ad5d350c64053dfc88fbf1f96944c928fd5b2916d8dfd83ae84491c0d0"}, - {file = "llm_change_agent-0.0.4.tar.gz", hash = "sha256:1dae218ca533dda54d9396801c5f4c431e93765c09960c4ff431663b227f2961"}, + {file = "llm_change_agent-0.0.7-py3-none-any.whl", hash = "sha256:e917ad7140c9bdc6e1aca693a2f86102989cbede5867a10506a66b1761ba21ba"}, + {file = "llm_change_agent-0.0.7.tar.gz", hash = "sha256:c4c032e3f5bffda0bd99a35961efbdc0274368fe7f79e32e91d641f5614e9ff3"}, ] [package.dependencies] @@ -3018,13 +3018,13 @@ tests = ["coverage", "pytest", "unittest-templates"] [[package]] name = "openai" -version = "1.43.0" +version = "1.43.1" description = "The official Python library for the openai API" optional = true python-versions = ">=3.7.1" files = [ - {file = "openai-1.43.0-py3-none-any.whl", hash = "sha256:1a748c2728edd3a738a72a0212ba866f4fdbe39c9ae03813508b267d45104abe"}, - {file = "openai-1.43.0.tar.gz", hash = "sha256:e607aff9fc3e28eade107e5edd8ca95a910a4b12589336d3cbb6bfe2ac306b3c"}, + {file = "openai-1.43.1-py3-none-any.whl", hash = "sha256:23ed3aa71e89cf644c911f7ab80087d08c0bf46ce6b75d9a811fc7942cff85c2"}, + {file = "openai-1.43.1.tar.gz", hash = "sha256:b64843711b7c92ded36795062ea1f8cad84ec6c2848646f2a786ac4617a6b9f5"}, ] [package.dependencies] @@ -5735,4 +5735,4 @@ llm = ["llm-change-agent"] [metadata] lock-version = "2.0" python-versions = ">=3.9,<4.0.0" -content-hash = "18ec4f7e69308915f9a436ad9bb3f771e3680a06106365cd6ccf34ffeb10eefa" +content-hash = "4c3f4d8532dc5477b008f2e1143a0c0ae89087ea86d6d54d6cd2d5cab632a16e" diff --git a/pyproject.toml b/pyproject.toml index ac4b9e0..d08bf39 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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] diff --git a/src/ontobot_change_agent/constants.py b/src/ontobot_change_agent/constants.py index 69e4d1d..c145b4b 100644 --- a/src/ontobot_change_agent/constants.py +++ b/src/ontobot_change_agent/constants.py @@ -1,4 +1,5 @@ """Constants.""" + from os import getenv # GitHUb Template Attributes. @@ -13,10 +14,10 @@ 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) +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" \ No newline at end of file +CBORG_PROVIDER = "cborg" From 8ffb3852e99e5a7c0192a96631980179fbe1caf6 Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Thu, 5 Sep 2024 16:13:29 -0500 Subject: [PATCH 6/9] cleaning llm response --- src/ontobot_change_agent/cli.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ontobot_change_agent/cli.py b/src/ontobot_change_agent/cli.py index 7d7facb..c64538e 100644 --- a/src/ontobot_change_agent/cli.py +++ b/src/ontobot_change_agent/cli.py @@ -12,6 +12,7 @@ try: from llm_change_agent.cli import execute + from llm_change_agent.utils.llm_utils import extract_commands llm_change_agent_available = True except ImportError: @@ -250,7 +251,7 @@ def process_issue( ctx.params["prompt"] = issue[BODY] ctx.params["provider"] = OPENAI_PROVIDER ctx.params["model"] = OPEN_AI_MODEL - response = execute.invoke(ctx) + response = extract_commands(execute.invoke(ctx)) KGCL_COMMANDS = [ command.replace('"', "'") for command in ast.literal_eval(response) ] From 47f203b006f39e472a364f74118441ef3a90bd42 Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Thu, 5 Sep 2024 17:17:12 -0500 Subject: [PATCH 7/9] pass model and/or provider for llm --- src/ontobot_change_agent/cli.py | 35 +++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/ontobot_change_agent/cli.py b/src/ontobot_change_agent/cli.py index c64538e..dbe3be0 100644 --- a/src/ontobot_change_agent/cli.py +++ b/src/ontobot_change_agent/cli.py @@ -12,9 +12,27 @@ try: from llm_change_agent.cli import execute - from llm_change_agent.utils.llm_utils import extract_commands + 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, + OWL_EXTENSION, + ) 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 @@ -29,7 +47,6 @@ process_issue_via_jar, process_issue_via_oak, ) -from ontobot_change_agent.constants import OPEN_AI_MODEL, OPENAI_PROVIDER, OWL_EXTENSION __all__ = [ "main", @@ -123,6 +140,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() @@ -188,6 +211,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, @@ -200,6 +225,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. @@ -249,8 +276,8 @@ 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"] = OPENAI_PROVIDER - ctx.params["model"] = OPEN_AI_MODEL + 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) From 1ca2fe9eaf4e84b4312764d2654ab36ec5dcb994 Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Thu, 5 Sep 2024 17:21:22 -0500 Subject: [PATCH 8/9] declared variables in case of llm absent --- src/ontobot_change_agent/cli.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ontobot_change_agent/cli.py b/src/ontobot_change_agent/cli.py index dbe3be0..862d5ac 100644 --- a/src/ontobot_change_agent/cli.py +++ b/src/ontobot_change_agent/cli.py @@ -36,6 +36,8 @@ 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__ From 222620450829bb5a4328302d60d5a3790d66a8b3 Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Thu, 5 Sep 2024 17:27:32 -0500 Subject: [PATCH 9/9] imported OWL EXT outside try statement --- src/ontobot_change_agent/cli.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ontobot_change_agent/cli.py b/src/ontobot_change_agent/cli.py index 862d5ac..acc333a 100644 --- a/src/ontobot_change_agent/cli.py +++ b/src/ontobot_change_agent/cli.py @@ -10,6 +10,8 @@ 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 ( @@ -25,7 +27,6 @@ CBORG_PROVIDER, OLLAMA_PROVIDER, OPENAI_PROVIDER, - OWL_EXTENSION, ) llm_change_agent_available = True