BerriAI / litellm

Call all LLM APIs using the OpenAI format. Use Bedrock, Azure, OpenAI, Cohere, Anthropic, Ollama, Sagemaker, HuggingFace, Replicate (100+ LLMs)
https://docs.litellm.ai/docs/
Other
10.05k stars 1.12k forks source link

fix: add more type hints to init methods #4258

Closed nejch closed 1 week ago

nejch commented 1 week ago

fix: add more type hints to init methods

This just adds a few type hints to user-facing init methods. Seems like recent additions to typing made mypy complain about unnecessary ignores, but removing that exposes more issues, e.g.:

tests/test_custom_callbacks.py:80: error: Call to untyped function "GeneratedCodeLogger" in typed context  [no-untyped-call]
tests/test_custom_callbacks.py:94: error: Call to untyped function "GeneratedCodeLogger" in typed context  [no-untyped-call]
tests/test_custom_callbacks.py:96: error: Call to untyped function "ModelResponse" in typed context  [no-untyped-call]
tests/test_custom_callbacks.py:152: error: Call to untyped function "ModelResponse" in typed context  [no-untyped-call]
tests/test_custom_callbacks.py:178: error: Call to untyped function "ModelResponse" in typed context  [no-untyped-call]
tests/test_custom_callbacks.py:198: error: Call to untyped function "ModelResponse" in typed context  [no-untyped-call]
tests/test_custom_callbacks.py:219: error: Call to untyped function "ModelResponse" in typed context  [no-untyped-call]

Relevant issues

Related to https://github.com/BerriAI/litellm/issues/4206

Type

🐛 Bug Fix

Changes

Typing changes only, so no added tests.

vercel[bot] commented 1 week ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
litellm ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 18, 2024 10:16am
krrishdholakia commented 1 week ago

thanks @nejch

how can we improve here? Will probably have more cleanups as we look to improve code quality. Would like to avoid these errors!

nejch commented 1 week ago

thanks @nejch

how can we improve here? Will probably have more cleanups as we look to improve code quality. Would like to avoid these errors!

Thanks for the merge @krrishdholakia!

The way I'd do it is also enable typing for tests covering a particular module, that way if mypy complains about production code typing usage inside the test, you get a pretty good idea of what kinds of errors a user would also see.

krrishdholakia commented 1 week ago

@nejch what would a module in this context be?

e2e example would be helpful for me

(really appreciate your help here!)