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/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 b97ab74..acc333a 100644 --- a/src/ontobot_change_agent/cli.py +++ b/src/ontobot_change_agent/cli.py @@ -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__ @@ -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", @@ -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() @@ -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, @@ -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. @@ -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:
" - 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 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]) @@ -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) ] diff --git a/src/ontobot_change_agent/constants.py b/src/ontobot_change_agent/constants.py index ed32436..c145b4b 100644 --- a/src/ontobot_change_agent/constants.py +++ b/src/ontobot_change_agent/constants.py @@ -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"