janus-llm 3.1.1__tar.gz → 3.2.0__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. {janus_llm-3.1.1 → janus_llm-3.2.0}/PKG-INFO +1 -1
  2. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/__init__.py +1 -1
  3. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/cli.py +64 -7
  4. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/converter/_tests/test_translate.py +7 -7
  5. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/converter/converter.py +6 -3
  6. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/converter/translate.py +1 -1
  7. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/alc/_tests/test_alc.py +3 -3
  8. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/binary/_tests/test_binary.py +2 -2
  9. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/mumps/_tests/test_mumps.py +2 -2
  10. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/treesitter/_tests/test_treesitter.py +2 -2
  11. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/llm/models_info.py +42 -20
  12. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/metrics/_tests/test_llm.py +3 -3
  13. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/metrics/metric.py +4 -4
  14. {janus_llm-3.1.1 → janus_llm-3.2.0}/pyproject.toml +1 -1
  15. {janus_llm-3.1.1 → janus_llm-3.2.0}/LICENSE +0 -0
  16. {janus_llm-3.1.1 → janus_llm-3.2.0}/README.md +0 -0
  17. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/__main__.py +0 -0
  18. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/_tests/__init__.py +0 -0
  19. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/_tests/conftest.py +0 -0
  20. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/_tests/test_cli.py +0 -0
  21. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/converter/__init__.py +0 -0
  22. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/converter/_tests/__init__.py +0 -0
  23. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/converter/diagram.py +0 -0
  24. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/converter/document.py +0 -0
  25. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/converter/evaluate.py +0 -0
  26. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/converter/requirements.py +0 -0
  27. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/embedding/__init__.py +0 -0
  28. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/embedding/_tests/__init__.py +0 -0
  29. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/embedding/_tests/test_collections.py +0 -0
  30. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/embedding/_tests/test_database.py +0 -0
  31. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/embedding/_tests/test_vectorize.py +0 -0
  32. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/embedding/collections.py +0 -0
  33. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/embedding/database.py +0 -0
  34. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/embedding/embedding_models_info.py +0 -0
  35. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/embedding/vectorize.py +0 -0
  36. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/__init__.py +0 -0
  37. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/_tests/__init__.py +0 -0
  38. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/_tests/test_combine.py +0 -0
  39. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/_tests/test_splitter.py +0 -0
  40. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/alc/__init__.py +0 -0
  41. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/alc/_tests/__init__.py +0 -0
  42. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/alc/alc.py +0 -0
  43. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/binary/__init__.py +0 -0
  44. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/binary/_tests/__init__.py +0 -0
  45. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/binary/binary.py +0 -0
  46. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/binary/reveng/decompile_script.py +0 -0
  47. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/block.py +0 -0
  48. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/combine.py +0 -0
  49. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/file.py +0 -0
  50. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/mumps/__init__.py +0 -0
  51. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/mumps/_tests/__init__.py +0 -0
  52. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/mumps/mumps.py +0 -0
  53. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/mumps/patterns.py +0 -0
  54. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/naive/__init__.py +0 -0
  55. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/naive/basic_splitter.py +0 -0
  56. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/naive/chunk_splitter.py +0 -0
  57. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/naive/registry.py +0 -0
  58. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/naive/simple_ast.py +0 -0
  59. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/naive/tag_splitter.py +0 -0
  60. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/node.py +0 -0
  61. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/splitter.py +0 -0
  62. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/treesitter/__init__.py +0 -0
  63. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/treesitter/_tests/__init__.py +0 -0
  64. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/language/treesitter/treesitter.py +0 -0
  65. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/llm/__init__.py +0 -0
  66. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/llm/model_callbacks.py +0 -0
  67. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/metrics/__init__.py +0 -0
  68. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/metrics/_tests/__init__.py +0 -0
  69. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/metrics/_tests/reference.py +0 -0
  70. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/metrics/_tests/target.py +0 -0
  71. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/metrics/_tests/test_bleu.py +0 -0
  72. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/metrics/_tests/test_chrf.py +0 -0
  73. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/metrics/_tests/test_file_pairing.py +0 -0
  74. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/metrics/_tests/test_reading.py +0 -0
  75. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/metrics/_tests/test_rouge_score.py +0 -0
  76. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/metrics/_tests/test_similarity_score.py +0 -0
  77. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/metrics/_tests/test_treesitter_metrics.py +0 -0
  78. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/metrics/bleu.py +0 -0
  79. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/metrics/chrf.py +0 -0
  80. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/metrics/cli.py +0 -0
  81. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/metrics/complexity_metrics.py +0 -0
  82. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/metrics/file_pairing.py +0 -0
  83. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/metrics/llm_metrics.py +0 -0
  84. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/metrics/reading.py +0 -0
  85. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/metrics/rouge_score.py +0 -0
  86. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/metrics/similarity.py +0 -0
  87. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/metrics/splitting.py +0 -0
  88. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/parsers/__init__.py +0 -0
  89. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/parsers/_tests/__init__.py +0 -0
  90. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/parsers/_tests/test_code_parser.py +0 -0
  91. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/parsers/code_parser.py +0 -0
  92. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/parsers/doc_parser.py +0 -0
  93. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/parsers/eval_parser.py +0 -0
  94. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/parsers/reqs_parser.py +0 -0
  95. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/parsers/uml.py +0 -0
  96. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/prompts/__init__.py +0 -0
  97. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/prompts/prompt.py +0 -0
  98. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/utils/__init__.py +0 -0
  99. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/utils/_tests/__init__.py +0 -0
  100. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/utils/_tests/test_logger.py +0 -0
  101. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/utils/_tests/test_progress.py +0 -0
  102. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/utils/enums.py +0 -0
  103. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/utils/logger.py +0 -0
  104. {janus_llm-3.1.1 → janus_llm-3.2.0}/janus/utils/progress.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: janus-llm
3
- Version: 3.1.1
3
+ Version: 3.2.0
4
4
  Summary: A transcoding library using LLMs.
5
5
  Home-page: https://github.com/janus-llm/janus-llm
6
6
  License: Apache 2.0
@@ -5,7 +5,7 @@ from langchain_core._api.deprecation import LangChainDeprecationWarning
5
5
  from .converter.translate import Translator
6
6
  from .metrics import * # noqa: F403
7
7
 
8
- __version__ = "3.1.1"
8
+ __version__ = "3.2.0"
9
9
 
10
10
  # Ignoring a deprecation warning from langchain_core that I can't seem to hunt down
11
11
  warnings.filterwarnings("ignore", category=LangChainDeprecationWarning)
@@ -32,8 +32,12 @@ from janus.language.treesitter import TreeSitterSplitter
32
32
  from janus.llm.model_callbacks import COST_PER_1K_TOKENS
33
33
  from janus.llm.models_info import (
34
34
  MODEL_CONFIG_DIR,
35
+ MODEL_ID_TO_LONG_ID,
35
36
  MODEL_TYPE_CONSTRUCTORS,
37
+ MODEL_TYPES,
36
38
  TOKEN_LIMITS,
39
+ bedrock_models,
40
+ openai_models,
37
41
  )
38
42
  from janus.metrics.cli import evaluate
39
43
  from janus.utils.enums import LANGUAGES
@@ -179,7 +183,7 @@ def translate(
179
183
  "-L",
180
184
  help="The custom name of the model set with 'janus llm add'.",
181
185
  ),
182
- ] = "gpt-3.5-turbo-0125",
186
+ ] = "gpt-4o",
183
187
  max_prompts: Annotated[
184
188
  int,
185
189
  typer.Option(
@@ -301,7 +305,7 @@ def document(
301
305
  "-L",
302
306
  help="The custom name of the model set with 'janus llm add'.",
303
307
  ),
304
- ] = "gpt-3.5-turbo-0125",
308
+ ] = "gpt-4o",
305
309
  max_prompts: Annotated[
306
310
  int,
307
311
  typer.Option(
@@ -437,7 +441,7 @@ def diagram(
437
441
  "-L",
438
442
  help="The custom name of the model set with 'janus llm add'.",
439
443
  ),
440
- ] = "gpt-3.5-turbo-0125",
444
+ ] = "gpt-4o",
441
445
  max_prompts: Annotated[
442
446
  int,
443
447
  typer.Option(
@@ -800,16 +804,44 @@ def llm_add(
800
804
  "model_cost": {"input": in_cost, "output": out_cost},
801
805
  }
802
806
  elif model_type == "OpenAI":
803
- model_name = typer.prompt("Enter the model name", default="gpt-3.5-turbo-0125")
807
+ model_id = typer.prompt(
808
+ "Enter the model ID (list model IDs with `janus llm ls -a`)",
809
+ default="gpt-4o",
810
+ type=click.Choice(openai_models),
811
+ show_choices=False,
812
+ )
804
813
  params = dict(
805
- model_name=model_name,
814
+ # OpenAI uses the "model_name" key for what we're calling "long_model_id"
815
+ model_name=MODEL_ID_TO_LONG_ID[model_id],
806
816
  temperature=0.7,
807
817
  n=1,
808
818
  )
809
- max_tokens = TOKEN_LIMITS[model_name]
810
- model_cost = COST_PER_1K_TOKENS[model_name]
819
+ max_tokens = TOKEN_LIMITS[MODEL_ID_TO_LONG_ID[model_id]]
820
+ model_cost = COST_PER_1K_TOKENS[MODEL_ID_TO_LONG_ID[model_id]]
821
+ cfg = {
822
+ "model_type": model_type,
823
+ "model_id": model_id,
824
+ "model_args": params,
825
+ "token_limit": max_tokens,
826
+ "model_cost": model_cost,
827
+ }
828
+ elif model_type == "BedrockChat" or model_type == "Bedrock":
829
+ model_id = typer.prompt(
830
+ "Enter the model ID (list model IDs with `janus llm ls -a`)",
831
+ default="bedrock-claude-sonnet",
832
+ type=click.Choice(bedrock_models),
833
+ show_choices=False,
834
+ )
835
+ params = dict(
836
+ # Bedrock uses the "model_id" key for what we're calling "long_model_id"
837
+ model_id=MODEL_ID_TO_LONG_ID[model_id],
838
+ model_kwargs={"temperature": 0.7},
839
+ )
840
+ max_tokens = TOKEN_LIMITS[MODEL_ID_TO_LONG_ID[model_id]]
841
+ model_cost = COST_PER_1K_TOKENS[MODEL_ID_TO_LONG_ID[model_id]]
811
842
  cfg = {
812
843
  "model_type": model_type,
844
+ "model_id": model_id,
813
845
  "model_args": params,
814
846
  "token_limit": max_tokens,
815
847
  "model_cost": model_cost,
@@ -821,6 +853,31 @@ def llm_add(
821
853
  print(f"Model config written to {model_cfg}")
822
854
 
823
855
 
856
+ @llm.command("ls", help="List all of the user-configured models")
857
+ def llm_ls(
858
+ all: Annotated[
859
+ bool,
860
+ typer.Option(
861
+ "--all",
862
+ "-a",
863
+ is_flag=True,
864
+ help="List all models, including the default model IDs.",
865
+ click_type=click.Choice(sorted(list(MODEL_TYPE_CONSTRUCTORS.keys()))),
866
+ ),
867
+ ] = False,
868
+ ):
869
+ print("\n[green]User-configured models[/green]:")
870
+ for model_cfg in MODEL_CONFIG_DIR.glob("*.json"):
871
+ with open(model_cfg, "r") as f:
872
+ cfg = json.load(f)
873
+ print(f"\t[blue]{model_cfg.stem}[/blue]: [purple]{cfg['model_type']}[/purple]")
874
+
875
+ if all:
876
+ print("\n[green]Available model IDs[/green]:")
877
+ for model_id, model_type in MODEL_TYPES.items():
878
+ print(f"\t[blue]{model_id}[/blue]: [purple]{model_type}[/purple]")
879
+
880
+
824
881
  @embedding.command("add", help="Add an embedding model config to janus")
825
882
  def embedding_add(
826
883
  model_name: Annotated[
@@ -79,7 +79,7 @@ class TestTranslator(unittest.TestCase):
79
79
  def setUp(self):
80
80
  """Set up the tests."""
81
81
  self.translator = Translator(
82
- model="gpt-3.5-turbo-0125",
82
+ model="gpt-4o",
83
83
  source_language="fortran",
84
84
  target_language="python",
85
85
  target_version="3.10",
@@ -88,7 +88,7 @@ class TestTranslator(unittest.TestCase):
88
88
  self.TEST_FILE_EMBEDDING_COUNT = 14
89
89
 
90
90
  self.req_translator = RequirementsDocumenter(
91
- model="gpt-3.5-turbo-0125",
91
+ model="gpt-4o",
92
92
  source_language="fortran",
93
93
  prompt_template="requirements",
94
94
  )
@@ -317,14 +317,14 @@ class TestDiagramGenerator(unittest.TestCase):
317
317
  def setUp(self):
318
318
  """Set up the tests."""
319
319
  self.diagram_generator = DiagramGenerator(
320
- model="gpt-3.5-turbo-0125",
320
+ model="gpt-4o",
321
321
  source_language="fortran",
322
322
  diagram_type="Activity",
323
323
  )
324
324
 
325
325
  def test_init(self):
326
326
  """Test __init__ method."""
327
- self.assertEqual(self.diagram_generator._model_name, "gpt-3.5-turbo-0125")
327
+ self.assertEqual(self.diagram_generator._model_name, "gpt-4o")
328
328
  self.assertEqual(self.diagram_generator._source_language, "fortran")
329
329
  self.assertEqual(self.diagram_generator._diagram_type, "Activity")
330
330
 
@@ -370,8 +370,8 @@ def test_language_combinations(
370
370
  """Tests that translator target language settings are consistent
371
371
  with prompt template expectations.
372
372
  """
373
- translator = Translator(model="gpt-3.5-turbo-0125")
374
- translator.set_model("gpt-3.5-turbo-0125")
373
+ translator = Translator(model="gpt-4o")
374
+ translator.set_model("gpt-4o")
375
375
  translator.set_source_language(source_language)
376
376
  translator.set_target_language(expected_target_language, expected_target_version)
377
377
  translator.set_prompt(prompt_template)
@@ -379,5 +379,5 @@ def test_language_combinations(
379
379
  assert translator._target_language == expected_target_language # nosec
380
380
  assert translator._target_version == expected_target_version # nosec
381
381
  assert translator._splitter.language == source_language # nosec
382
- assert translator._splitter.model.model_name == "gpt-3.5-turbo-0125" # nosec
382
+ assert translator._splitter.model.model_name == "gpt-4o" # nosec
383
383
  assert translator._prompt_template_name == prompt_template # nosec
@@ -64,7 +64,7 @@ class Converter:
64
64
 
65
65
  def __init__(
66
66
  self,
67
- model: str = "gpt-3.5-turbo-0125",
67
+ model: str = "gpt-4o",
68
68
  model_arguments: dict[str, Any] = {},
69
69
  source_language: str = "fortran",
70
70
  max_prompts: int = 10,
@@ -92,6 +92,7 @@ class Converter:
92
92
  self.override_token_limit: bool = max_tokens is not None
93
93
 
94
94
  self._model_name: str
95
+ self._model_id: str
95
96
  self._custom_model_arguments: dict[str, Any]
96
97
 
97
98
  self._source_language: str
@@ -265,7 +266,9 @@ class Converter:
265
266
  # model_arguments.update(self._custom_model_arguments)
266
267
 
267
268
  # Load the model
268
- self._llm, token_limit, self.model_cost = load_model(self._model_name)
269
+ self._llm, self._model_id, token_limit, self.model_cost = load_model(
270
+ self._model_name
271
+ )
269
272
  # Set the max_tokens to less than half the model's limit to allow for enough
270
273
  # tokens at output
271
274
  # Only modify max_tokens if it is not specified by user
@@ -283,7 +286,7 @@ class Converter:
283
286
  If the relevant fields have not been changed since the last time this
284
287
  method was called, nothing happens.
285
288
  """
286
- prompt_engine = MODEL_PROMPT_ENGINES[self._model_name](
289
+ prompt_engine = MODEL_PROMPT_ENGINES[self._model_id](
287
290
  source_language=self._source_language,
288
291
  prompt_template=self._prompt_template_name,
289
292
  )
@@ -90,7 +90,7 @@ class Translator(Converter):
90
90
  f"({self._source_language} != {self._target_language})"
91
91
  )
92
92
 
93
- prompt_engine = MODEL_PROMPT_ENGINES[self._model_name](
93
+ prompt_engine = MODEL_PROMPT_ENGINES[self._model_id](
94
94
  source_language=self._source_language,
95
95
  target_language=self._target_language,
96
96
  target_version=self._target_version,
@@ -11,8 +11,8 @@ class TestAlcSplitter(unittest.TestCase):
11
11
 
12
12
  def setUp(self):
13
13
  """Set up the tests."""
14
- model_name = "gpt-3.5-turbo-0125"
15
- llm, _, _ = load_model(model_name)
14
+ model_name = "gpt-4o"
15
+ llm, _, _, _ = load_model(model_name)
16
16
  self.splitter = AlcSplitter(model=llm)
17
17
  self.combiner = Combiner(language="ibmhlasm")
18
18
  self.test_file = Path("janus/language/alc/_tests/alc.asm")
@@ -20,7 +20,7 @@ class TestAlcSplitter(unittest.TestCase):
20
20
  def test_split(self):
21
21
  """Test the split method."""
22
22
  tree_root = self.splitter.split(self.test_file)
23
- self.assertEqual(tree_root.n_descendents, 34)
23
+ self.assertAlmostEqual(tree_root.n_descendents, 32, delta=5)
24
24
  self.assertLessEqual(tree_root.max_tokens, self.splitter.max_tokens)
25
25
  self.assertFalse(tree_root.complete)
26
26
  self.combiner.combine_children(tree_root)
@@ -13,9 +13,9 @@ class TestBinarySplitter(unittest.TestCase):
13
13
  """Tests for the BinarySplitter class."""
14
14
 
15
15
  def setUp(self):
16
- model_name = "gpt-3.5-turbo-0125"
16
+ model_name = "gpt-4o"
17
17
  self.binary_file = Path("janus/language/binary/_tests/hello")
18
- self.llm, _, _ = load_model(model_name)
18
+ self.llm, _, _, _ = load_model(model_name)
19
19
  self.splitter = BinarySplitter(model=self.llm)
20
20
  os.environ["GHIDRA_INSTALL_PATH"] = "~/programs/ghidra_10.4_PUBLIC"
21
21
 
@@ -11,8 +11,8 @@ class TestMumpsSplitter(unittest.TestCase):
11
11
 
12
12
  def setUp(self):
13
13
  """Set up the tests."""
14
- model_name = "gpt-3.5-turbo-0125"
15
- llm, _, _ = load_model(model_name)
14
+ model_name = "gpt-4o"
15
+ llm, _, _, _ = load_model(model_name)
16
16
  self.splitter = MumpsSplitter(model=llm)
17
17
  self.combiner = Combiner(language="mumps")
18
18
  self.test_file = Path("janus/language/mumps/_tests/mumps.m")
@@ -11,9 +11,9 @@ class TestTreeSitterSplitter(unittest.TestCase):
11
11
 
12
12
  def setUp(self):
13
13
  """Set up the tests."""
14
- model_name = "gpt-3.5-turbo-0125"
14
+ model_name = "gpt-4o"
15
15
  self.maxDiff = None
16
- self.llm, _, _ = load_model(model_name)
16
+ self.llm, _, _, _ = load_model(model_name)
17
17
 
18
18
  def _split(self):
19
19
  """Split the test file."""
@@ -55,11 +55,12 @@ openai_model_reroutes = {
55
55
  }
56
56
 
57
57
  openai_models = [
58
- "gpt-4-0613",
59
- "gpt-4-1106-preview",
60
- "gpt-4-0125-preview",
61
- "gpt-4o-2024-05-13",
62
- "gpt-3.5-turbo-0125",
58
+ "gpt-4o",
59
+ "gpt-4",
60
+ "gpt-4-turbo",
61
+ "gpt-4-turbo-preview",
62
+ "gpt-3.5-turbo",
63
+ "gpt-3.5-turbo-16k",
63
64
  ]
64
65
  claude_models = [
65
66
  "bedrock-claude-v2",
@@ -133,8 +134,8 @@ _open_ai_defaults: dict[str, str] = {
133
134
  "openai_organization": os.getenv("OPENAI_ORG_ID"),
134
135
  }
135
136
 
136
- model_identifiers = {
137
- **{m: m for m in openai_models},
137
+ MODEL_ID_TO_LONG_ID = {
138
+ **{m: mr for m, mr in openai_model_reroutes.items()},
138
139
  "bedrock-claude-v2": "anthropic.claude-v2",
139
140
  "bedrock-claude-instant-v1": "anthropic.claude-instant-v1",
140
141
  "bedrock-claude-haiku": "anthropic.claude-3-haiku-20240307-v1:0",
@@ -157,7 +158,7 @@ model_identifiers = {
157
158
 
158
159
  MODEL_DEFAULT_ARGUMENTS: dict[str, dict[str, str]] = {
159
160
  k: (dict(model_name=k) if k in openai_models else dict(model_id=v))
160
- for k, v in model_identifiers.items()
161
+ for k, v in MODEL_ID_TO_LONG_ID.items()
161
162
  }
162
163
 
163
164
  DEFAULT_MODELS = list(MODEL_DEFAULT_ARGUMENTS.keys())
@@ -199,22 +200,38 @@ TOKEN_LIMITS: dict[str, int] = {
199
200
  }
200
201
 
201
202
 
202
- def load_model(model_name: str) -> tuple[BaseLanguageModel, int, dict[str, float]]:
203
+ def get_available_model_names() -> list[str]:
204
+ avaialable_models = []
205
+ for file in MODEL_CONFIG_DIR.iterdir():
206
+ if file.is_file():
207
+ avaialable_models.append(MODEL_CONFIG_DIR.stem)
208
+ return avaialable_models
209
+
210
+
211
+ def load_model(user_model_name: str) -> tuple[BaseLanguageModel, int, dict[str, float]]:
203
212
  if not MODEL_CONFIG_DIR.exists():
204
213
  MODEL_CONFIG_DIR.mkdir(parents=True)
205
- model_config_file = MODEL_CONFIG_DIR / f"{model_name}.json"
214
+ model_config_file = MODEL_CONFIG_DIR / f"{user_model_name}.json"
206
215
  if not model_config_file.exists():
207
- if model_name not in DEFAULT_MODELS:
208
- if model_name in openai_model_reroutes:
209
- model_name = openai_model_reroutes[model_name]
210
- else:
211
- raise ValueError(f"Error: could not find model {model_name}")
216
+ log.warning(
217
+ f"Model {user_model_name} not found in user-defined models, searching "
218
+ f"default models for {user_model_name}."
219
+ )
220
+ model_id = user_model_name
221
+ if user_model_name not in DEFAULT_MODELS:
222
+ message = (
223
+ f"Model {user_model_name} not found in default models. Make sure to run "
224
+ "`janus llm add` first."
225
+ )
226
+ log.error(message)
227
+ raise ValueError(message)
212
228
  model_config = {
213
- "model_type": MODEL_TYPES[model_name],
214
- "model_args": MODEL_DEFAULT_ARGUMENTS[model_name],
215
- "token_limit": TOKEN_LIMITS.get(model_identifiers[model_name], 4096),
229
+ "model_type": MODEL_TYPES[model_id],
230
+ "model_id": model_id,
231
+ "model_args": MODEL_DEFAULT_ARGUMENTS[model_id],
232
+ "token_limit": TOKEN_LIMITS.get(MODEL_ID_TO_LONG_ID[model_id], 4096),
216
233
  "model_cost": COST_PER_1K_TOKENS.get(
217
- model_identifiers[model_name], {"input": 0, "output": 0}
234
+ MODEL_ID_TO_LONG_ID[model_id], {"input": 0, "output": 0}
218
235
  ),
219
236
  }
220
237
  with open(model_config_file, "w") as f:
@@ -227,4 +244,9 @@ def load_model(model_name: str) -> tuple[BaseLanguageModel, int, dict[str, float
227
244
  if model_config["model_type"] == "OpenAI":
228
245
  model_args.update(_open_ai_defaults)
229
246
  model = model_constructor(**model_args)
230
- return model, model_config["token_limit"], model_config["model_cost"]
247
+ return (
248
+ model,
249
+ model_config["model_id"],
250
+ model_config["token_limit"],
251
+ model_config["model_cost"],
252
+ )
@@ -53,7 +53,7 @@ class TestLLMMetrics(unittest.TestCase):
53
53
  self.bad_code,
54
54
  metric="quality",
55
55
  language="python",
56
- llm=load_model("gpt-3.5-turbo-0125")[0],
56
+ llm=load_model("gpt-4o")[0],
57
57
  )
58
58
  self.assertLess(bad_code_quality, 5)
59
59
 
@@ -63,7 +63,7 @@ class TestLLMMetrics(unittest.TestCase):
63
63
  self.impressive_code,
64
64
  metric="quality",
65
65
  language="python",
66
- llm=load_model("gpt-3.5-turbo-0125")[0],
66
+ llm=load_model("gpt-4o")[0],
67
67
  )
68
68
  self.assertGreater(impressive_code_quality, 5)
69
69
 
@@ -81,7 +81,7 @@ class TestLLMMetrics(unittest.TestCase):
81
81
  self.impressive_code_reference,
82
82
  metric="faithfulness",
83
83
  language="python",
84
- llm=load_model("gpt-3.5-turbo-0125")[0],
84
+ llm=load_model("gpt-4o")[0],
85
85
  )
86
86
  self.assertGreater(faithfulness, 8)
87
87
 
@@ -112,7 +112,7 @@ def metric(
112
112
  "-L",
113
113
  help="The custom name of the model set with 'janus llm add'.",
114
114
  ),
115
- ] = "gpt-3.5-turbo-0125",
115
+ ] = "gpt-4o",
116
116
  progress: Annotated[
117
117
  bool,
118
118
  typer.Option(
@@ -135,7 +135,7 @@ def metric(
135
135
  **kwargs,
136
136
  ):
137
137
  out = []
138
- llm, token_limit, model_cost = load_model(llm_name)
138
+ llm, _, token_limit, model_cost = load_model(llm_name)
139
139
  if json_file_name is not None:
140
140
  with open(json_file_name, "r") as f:
141
141
  json_obj = json.load(f)
@@ -274,7 +274,7 @@ def metric(
274
274
  "-L",
275
275
  help="The custom name of the model set with 'janus llm add'.",
276
276
  ),
277
- ] = "gpt-3.5-turbo-0125",
277
+ ] = "gpt-4o",
278
278
  progress: Annotated[
279
279
  bool,
280
280
  typer.Option(
@@ -296,7 +296,7 @@ def metric(
296
296
  *args,
297
297
  **kwargs,
298
298
  ):
299
- llm, token_limit, model_cost = load_model(llm_name)
299
+ llm, _, token_limit, model_cost = load_model(llm_name)
300
300
  if json_file_name is not None:
301
301
  with open(json_file_name, "r") as f:
302
302
  json_obj = json.load(f)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "janus-llm"
3
- version = "3.1.1"
3
+ version = "3.2.0"
4
4
  description = "A transcoding library using LLMs."
5
5
  authors = ["Michael Doyle <mdoyle@mitre.org>", "Chris Glasz <cglasz@mitre.org>",
6
6
  "Chris Tohline <ctohline@mitre.org>", "William Macke <wmacke@mitre.org>",
File without changes
File without changes
File without changes