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

[Bug]: typing of model_list passed to litellm.Router is bit off #4231

Open
fingon opened this issue Jun 17, 2024 · 2 comments
Open

[Bug]: typing of model_list passed to litellm.Router is bit off #4231

fingon opened this issue Jun 17, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@fingon
Copy link

fingon commented Jun 17, 2024

What happened?

I attempted to pass list[litellm.DeploymentTypedDict] to the litellm.Router as a parameter. That doesn't really work, unfortunately, as shown below.

I would perhaps rather type it as

list[DeploymentTypedDict] | list[dict[Any, Any]] | None

Relevant log output

...: error: Argument "model_list" to "Router" has incompatible type "list[DeploymentTypedDict]"; expected "list[DeploymentTypedDict | dict[Any, Any]] | None"  [arg-type]


### Twitter / LinkedIn details

_No response_
@fingon fingon added the bug Something isn't working label Jun 17, 2024
@krrishdholakia
Copy link
Contributor

hey @fingon can you share your sample code for repro'ing the typing error?

@fingon
Copy link
Author

fingon commented Jun 18, 2024

Given this ,litellm.py:

import litellm

model_list: list[litellm.DeploymentTypedDict] = [
        {
            "model_name": "gpt-3.5-turbo",
            "litellm_params": {
                "model": "azure/gpt-35-turbo",
                "api_key": "x",
                "api_version": "y",
                "api_base": "z",
            },
        },
]

router = litellm.Router(model_list=model_list)

Shell action:

mstenber@koneko ~>python3 --version
Python 3.11.9
mstenber@koneko ~>mypy --version
mypy 1.10.0 (compiled: yes)
mstenber@koneko ~>mypy ,litellm.py 
,litellm.py:30: error: Argument "model_list" to "Router" has incompatible type "list[DeploymentTypedDict]"; expected "list[DeploymentTypedDict | dict[Any, Any]] | None"  [arg-type]
,litellm.py:30: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
,litellm.py:30: note: Consider using "Sequence" instead, which is covariant
Found 1 error in 1 file (checked 1 source file)

Note that your typing should really use Sequence instead of list too, as it is covariant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants