Skip to content

Commit

Permalink
Update to throw IndexError if model name not registered (#1475)
Browse files Browse the repository at this point in the history
I wasn't really sure where else this change needed to be done. I added
this error message in this registry code since it will be called by the
same run_batch call that checks for prompts too
  • Loading branch information
Ankush-lastmile authored Mar 24, 2024
2 parents fc9e3ae + 4211b26 commit 92b4f9f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion python/src/aiconfig/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ async def run_batch(
Raises:
IndexError: If the identifier for the prompt doesn't exist in the list of available prompts.
IndexError: If the model name doesn't exist in the list of available model parsers.
Returns:
list[Tuple["ExecuteResult", JSONObject | Any, Dict[str, Any]]]: A list of tuples, each tuple consisting of the inference result, the corresponding resolved completion parameters, and the parameters dict used.
Expand Down
4 changes: 4 additions & 0 deletions python/src/aiconfig/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ def get_model_parser(model_id: str) -> ModelParser:
Returns:
ModelParser: The retrieved model parser
"""
if model_id not in ModelParserRegistry.parser_ids():
raise IndexError(
f"Model parser '{model_id}' not found in registry, available model parsers are:\n {ModelParserRegistry.parser_ids()}"
)
return ModelParserRegistry._parsers[model_id]

@staticmethod
Expand Down
6 changes: 3 additions & 3 deletions python/tests/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_retrieve_model_parser(self):

def test_retrieve_nonexistent_model_parser(self):
# Attempt to retrieve a model parser that is not registered
with pytest.raises(KeyError):
with pytest.raises(IndexError):
ModelParserRegistry.get_model_parser("nonexistent-model")

def test_retrieve_model_parser_for_prompt(
Expand Down Expand Up @@ -134,7 +134,7 @@ def test_retrieve_model_parser_for_prompt_with_nonexistent_model(
ai_config_runtime.add_prompt(prompt.name, prompt)

# Attempt to retrieve a model parser for the Prompt
with pytest.raises(KeyError):
with pytest.raises(IndexError):
ModelParserRegistry.get_model_parser_for_prompt(
prompt, ai_config_runtime
).id()
Expand All @@ -153,7 +153,7 @@ def test_remove_model_parser(self):
ModelParserRegistry.remove_model_parser("model-8")

# Attempt to retrieve the removed model parser
with pytest.raises(KeyError):
with pytest.raises(IndexError):
parser = ModelParserRegistry.get_model_parser("model-8") == None

def test_clear_registry(self):
Expand Down

0 comments on commit 92b4f9f

Please sign in to comment.