mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-05 20:23:18 +00:00
Revert "Fix audio cost per second override (#19158)"
This reverts commit 2a0f87bde0.
This commit is contained in:
@@ -2,10 +2,7 @@
|
||||
|
||||
Register custom pricing for sagemaker completion model.
|
||||
|
||||
For cost per second pricing, register `input_cost_per_second`. If your provider
|
||||
charges for audio output duration (e.g., TTS), also set `output_cost_per_second`.
|
||||
Values of `0` are treated as not billable, so `output_cost_per_second: 0` will
|
||||
not override `input_cost_per_second`.
|
||||
For cost per second pricing, you **just** need to register `input_cost_per_second`.
|
||||
|
||||
```python
|
||||
# !pip install boto3
|
||||
|
||||
@@ -105,21 +105,25 @@ def cost_per_second(
|
||||
prompt_cost = 0.0
|
||||
completion_cost = 0.0
|
||||
## Speech / Audio cost calculation
|
||||
output_cost_per_second = model_info.get("output_cost_per_second")
|
||||
input_cost_per_second = model_info.get("input_cost_per_second")
|
||||
|
||||
if output_cost_per_second is not None and output_cost_per_second > 0:
|
||||
if (
|
||||
"output_cost_per_second" in model_info
|
||||
and model_info["output_cost_per_second"] is not None
|
||||
):
|
||||
verbose_logger.debug(
|
||||
f"For model={model} - output_cost_per_second: {output_cost_per_second}; duration: {duration}"
|
||||
f"For model={model} - output_cost_per_second: {model_info.get('output_cost_per_second')}; duration: {duration}"
|
||||
)
|
||||
## COST PER SECOND ##
|
||||
completion_cost = output_cost_per_second * duration
|
||||
if input_cost_per_second is not None and input_cost_per_second > 0:
|
||||
completion_cost = model_info["output_cost_per_second"] * duration
|
||||
elif (
|
||||
"input_cost_per_second" in model_info
|
||||
and model_info["input_cost_per_second"] is not None
|
||||
):
|
||||
verbose_logger.debug(
|
||||
f"For model={model} - input_cost_per_second: {input_cost_per_second}; duration: {duration}"
|
||||
f"For model={model} - input_cost_per_second: {model_info.get('input_cost_per_second')}; duration: {duration}"
|
||||
)
|
||||
## COST PER SECOND ##
|
||||
prompt_cost = input_cost_per_second * duration
|
||||
prompt_cost = model_info["input_cost_per_second"] * duration
|
||||
completion_cost = 0.0
|
||||
|
||||
return prompt_cost, completion_cost
|
||||
|
||||
|
||||
@@ -192,40 +192,6 @@ def test_transcription_cost_falls_back_to_duration():
|
||||
assert pytest.approx(cost, rel=1e-6) == expected_cost
|
||||
|
||||
|
||||
def test_transcription_cost_prefers_input_when_output_zero(monkeypatch):
|
||||
from litellm import completion_cost
|
||||
|
||||
os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"
|
||||
litellm.model_cost = litellm.get_model_cost_map(url="")
|
||||
|
||||
model_name = "custom-whisper-input-only"
|
||||
custom_model_info = {
|
||||
"input_cost_per_second": 0.00005,
|
||||
"output_cost_per_second": 0.0,
|
||||
"litellm_provider": "openai",
|
||||
"mode": "audio_transcription",
|
||||
"supported_endpoints": ["/v1/audio/transcriptions"],
|
||||
}
|
||||
monkeypatch.setattr(
|
||||
litellm,
|
||||
"model_cost",
|
||||
{**litellm.model_cost, model_name: custom_model_info},
|
||||
)
|
||||
|
||||
response = TranscriptionResponse(text="demo text")
|
||||
response.duration = 300.0
|
||||
|
||||
cost = completion_cost(
|
||||
completion_response=response,
|
||||
model=model_name,
|
||||
custom_llm_provider="openai",
|
||||
call_type="atranscription",
|
||||
)
|
||||
|
||||
expected_cost = 300.0 * 0.00005
|
||||
assert pytest.approx(cost, rel=1e-6) == expected_cost
|
||||
|
||||
|
||||
def test_handle_realtime_stream_cost_calculation():
|
||||
from litellm.cost_calculator import RealtimeAPITokenUsageProcessor
|
||||
|
||||
|
||||
Reference in New Issue
Block a user