mirror of
https://github.com/BerriAI/litellm.git
synced 2026-08-28 05:25:59 +00:00
* test: drop the cwd-relative sys.path.insert calls from the test suite
TQ003 stands at 1,077 across 1,058 files, and 1,015 of them are the same shape:
sys.path.insert(0, os.path.abspath("../..")) and its deeper siblings. The
argument resolves against the working directory rather than the file, so from
the repo root, where every job runs pytest, it inserts the directory two levels
above the checkout. It has never pointed at litellm. The package is installed
into the environment anyway, which is what actually makes the import work, and
what the rule's message has said all along.
Removing them leaves 1,634 imports of sys and os with no remaining reference,
and those go too, except where another test module imports the name back out of
the file. The rest of TQ003 is 62 call sites that resolve against __file__ or a
variable, which are a different question and are left alone.
Collection is identical either way: 45,871 tests and the same 51 pre-existing
collection errors before and after, and ruff reports no new undefined name.
* test: drop the duplicate imports the sys.path sweep exposed to F811
* test(pre-call-utils): restore the os import the new bedrock tests need
79 lines
2.8 KiB
Python
79 lines
2.8 KiB
Python
"""
|
|
Regression test: ``command-r7b-12-2024`` had its input/output per-token
|
|
costs transposed in the model-cost maps (input=1.5e-07 / output=3.75e-08),
|
|
even though Cohere publishes $0.0375/1M input and $0.15/1M output, i.e.
|
|
output is ~4x input like every other ``command-r`` entry.
|
|
|
|
These tests pin the corrected values in both the primary price map and the
|
|
``litellm/`` backup, and verify ``get_model_info`` surfaces them, so the
|
|
swap cannot silently regress.
|
|
"""
|
|
|
|
import json
|
|
import os
|
|
|
|
|
|
import litellm
|
|
|
|
MODEL = "command-r7b-12-2024"
|
|
EXPECTED_INPUT_COST = 3.75e-08
|
|
EXPECTED_OUTPUT_COST = 1.5e-07
|
|
|
|
|
|
def _load_json(path: str) -> dict:
|
|
with open(path, encoding="utf-8") as f:
|
|
return json.load(f)
|
|
|
|
|
|
def _backup_path() -> str:
|
|
return os.path.join(
|
|
os.path.dirname(litellm.__file__),
|
|
"model_prices_and_context_window_backup.json",
|
|
)
|
|
|
|
|
|
def _main_path() -> str:
|
|
# This test lives at ``tests/test_litellm/``; the primary price map sits at
|
|
# the repo root, two directories up. Resolve it relative to this file so the
|
|
# test works regardless of where ``litellm`` itself is installed (e.g. a pip
|
|
# install into site-packages).
|
|
return os.path.join(
|
|
os.path.dirname(__file__),
|
|
"..",
|
|
"..",
|
|
"model_prices_and_context_window.json",
|
|
)
|
|
|
|
|
|
class TestCommandR7bPricingData:
|
|
"""The JSON price maps must carry Cohere's published costs, with output
|
|
more expensive than input."""
|
|
|
|
def test_backup_costs_not_swapped(self):
|
|
entry = _load_json(_backup_path())[MODEL]
|
|
assert entry["input_cost_per_token"] == EXPECTED_INPUT_COST
|
|
assert entry["output_cost_per_token"] == EXPECTED_OUTPUT_COST
|
|
assert entry["output_cost_per_token"] > entry["input_cost_per_token"]
|
|
|
|
def test_main_costs_not_swapped(self):
|
|
entry = _load_json(_main_path())[MODEL]
|
|
assert entry["input_cost_per_token"] == EXPECTED_INPUT_COST
|
|
assert entry["output_cost_per_token"] == EXPECTED_OUTPUT_COST
|
|
assert entry["output_cost_per_token"] > entry["input_cost_per_token"]
|
|
|
|
|
|
class TestCommandR7bPricingModelInfo:
|
|
"""``get_model_info`` must report the corrected, un-swapped costs."""
|
|
|
|
def test_get_model_info_costs(self):
|
|
# Patch litellm.model_cost with the local backup so the test is not
|
|
# dependent on the remote fetch hitting a not-yet-merged main branch.
|
|
original = litellm.model_cost
|
|
try:
|
|
litellm.model_cost = _load_json(_backup_path())
|
|
info = litellm.get_model_info(MODEL)
|
|
assert info["input_cost_per_token"] == EXPECTED_INPUT_COST
|
|
assert info["output_cost_per_token"] == EXPECTED_OUTPUT_COST
|
|
assert info["output_cost_per_token"] > info["input_cost_per_token"]
|
|
finally:
|
|
litellm.model_cost = original
|