Files
litellm/tests
Alexsander Hamir ddb90c9ad7 [Fix] - Router: add model_name index for O(1) deployment lookups (#15113)
* perf(router): add model_name index for O(1) deployment lookups

Add model_name_to_deployment_indices mapping to optimize _get_all_deployments()
from O(n) to O(1) + O(k) lookups.

- Add model_name_to_deployment_indices: Dict[str, List[int]]
- Add _build_model_name_index() to build/maintain the index
- Update _add_model_to_list_and_index_map() to maintain both indices
- Refactor to use idx = len(self.model_list) before append (cleaner)
- Optimize _get_all_deployments() to use index instead of linear scan

* test(router): add test coverage for _build_model_name_index

Add single comprehensive test for _build_model_name_index() function to fix
code coverage CI failure.

The test verifies:
- Index correctly maps model_name to deployment indices
- Handles multiple deployments per model_name
- Clears and rebuilds index correctly

Fixes: CI code coverage error for _build_model_name_index
2025-10-06 08:14:11 -07:00
..
2025-10-04 14:55:04 -07:00
2025-10-04 09:18:26 -07:00
2025-10-04 10:39:17 -07:00
2025-09-30 07:25:32 +09:00
2025-09-27 12:40:34 -07:00
2025-09-16 15:41:52 -07:00
2025-10-04 10:57:02 -07:00
2025-10-04 16:11:22 -07:00
2025-09-27 10:59:25 -07:00

In total litellm runs 1000+ tests

[02/20/2025] Update:

To make it easier to contribute and map what behavior is tested,

we've started mapping the litellm directory in tests/test_litellm

This folder can only run mock tests.