Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to throw IndexError if model name not registered #1475

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading