graphrag/tests/unit/litellm_services/utils.py
Derek Worthen 2b70e4a4f3
Tokenizer (#2051)
* Add LiteLLM chat and embedding model providers.

* Fix code review findings.

* Add litellm.

* Fix formatting.

* Update dictionary.

* Update litellm.

* Fix embedding.

* Remove manual use of tiktoken and replace with
Tokenizer interface. Adds support for encoding
and decoding the models supported by litellm.

* Update litellm.

* Configure litellm to drop unsupported params.

* Cleanup semversioner release notes.

* Add num_tokens util to Tokenizer interface.

* Update litellm service factories.

* Cleanup litellm chat/embedding model argument assignment.

* Update chat and embedding type field for litellm use and future migration away from fnllm.

* Flatten litellm service organization.

* Update litellm.

* Update litellm factory validation.

* Flatten litellm rate limit service organization.

* Update rate limiter - disable with None/null instead of 0.

* Fix usage of get_tokenizer.

* Update litellm service registrations.

* Add jitter to exponential retry.

* Update validation.

* Update validation.

* Add litellm request logging layer.

* Update cache key.

* Update defaults.

---------

Co-authored-by: Alonso Guevara <alonsog@microsoft.com>
2025-09-22 13:55:14 -06:00

38 lines
1.1 KiB
Python

# Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""LiteLLM Test Utilities."""
def bin_time_intervals(
time_values: list[float], time_interval: int
) -> list[list[float]]:
"""Bin values."""
bins: list[list[float]] = []
bin_number = 0
for time_value in time_values:
upper_bound = (bin_number * time_interval) + time_interval
while time_value >= upper_bound:
bin_number += 1
upper_bound = (bin_number * time_interval) + time_interval
while len(bins) <= bin_number:
bins.append([])
bins[bin_number].append(time_value)
return bins
def assert_max_num_values_per_period(
periods: list[list[float]], max_values_per_period: int
):
"""Assert the number of values per period."""
for period in periods:
assert len(period) <= max_values_per_period
def assert_stagger(time_values: list[float], stagger: float):
"""Assert stagger."""
for i in range(1, len(time_values)):
assert time_values[i] - time_values[i - 1] >= stagger