Skip to content

Completions.create() does not check for model=None #254

@wendyscook

Description

@wendyscook

In aisuite/client.py, the code in Completions.create() checks if the format of the model string input parameter includes a colon:

        # Check that correct format is used
        if ":" not in model:
            raise ValueError(
                f"Invalid model format. Expected 'provider:model', got '{model}'"
            )

but it doesn't check if model is None. If someone passes in None for the model, the code that checks for ":" will throw the TypeError: they will get the TypeError: "argument of type 'NoneType' is not iterable”. Not too hard to figure, but would be much nicer (and not much work) to add the extra check, like this:

        # Check that correct format is used
        if model = None or ":" not in model:
            raise ValueError(
                f"Invalid model format. Expected 'provider:model', got '{model}'"
            )

This has shown up as an issue for students in the Deeplearning.ai "Agentic AI" course. If they forget to replace a None in the section of code they are supposed to edit, then the unit test for the function they are testing will return the NoneType is not iterable error, which can be hard for them to trace back to that overlooked change. The more specific error message about invalid model format would be a big help for them, and I'm sure for others, too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions