mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-21 00:21:49 +00:00
fix(proxy): price a deleted Transcribe job from the start response the proxy relayed
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
9d92b10575
commit
2decf3761a
2 changed files with 46 additions and 3 deletions
|
|
@ -654,7 +654,7 @@ class TranscribePassthroughLoggingHandler:
|
|||
job_name if isinstance(job_name, str) else "",
|
||||
aws_region_name,
|
||||
cost_per_second,
|
||||
started_transcription_job(result),
|
||||
started_transcription_job(httpx_response.text),
|
||||
)
|
||||
payload: Final = self.transcribe_passthrough_handler(
|
||||
httpx_response=httpx_response,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import asyncio
|
||||
import io
|
||||
import json
|
||||
import wave
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
|
@ -39,13 +40,13 @@ from litellm.proxy.pass_through_endpoints.success_handler import (
|
|||
COST_PER_SECOND = 0.0001
|
||||
|
||||
|
||||
def _make_response(operation: str) -> httpx.Response:
|
||||
def _make_response(operation: str, text: str = '{"TranscriptionJob": {}}') -> httpx.Response:
|
||||
request = httpx.Request(
|
||||
"POST",
|
||||
"https://transcribe.us-west-2.amazonaws.com/",
|
||||
headers={"X-Amz-Target": f"Transcribe.{operation}"},
|
||||
)
|
||||
return httpx.Response(200, request=request, text='{"TranscriptionJob": {}}')
|
||||
return httpx.Response(200, request=request, text=text)
|
||||
|
||||
|
||||
def _make_logging_obj() -> MagicMock:
|
||||
|
|
@ -826,6 +827,48 @@ class TestStartTranscriptionJobIsLoggedAtJobCost:
|
|||
assert scheduled == ["litellm-job-1"]
|
||||
assert [entry["response_cost"] for entry in immediate] == [0.0]
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_pass_through_success_handler_gives_the_pricer_the_started_job_from_the_response(self):
|
||||
started_jobs: list[TranscriptionJobRecord | None] = []
|
||||
|
||||
async def job_pricer(
|
||||
job_name: str, aws_region_name: str, cost_per_second: float, started_job: TranscriptionJobRecord | None
|
||||
) -> float:
|
||||
started_jobs.append(started_job)
|
||||
return 0.0
|
||||
|
||||
async def log_dispatch(**kwargs: object) -> None:
|
||||
pass
|
||||
|
||||
start_response = (
|
||||
'{"TranscriptionJob": {"TranscriptionJobName": "litellm-job-1", "TranscriptionJobStatus": "IN_PROGRESS",'
|
||||
' "Media": {"MediaFileUri": "s3://b/started.wav"}, "CreationTime": 5.0}}'
|
||||
)
|
||||
logging = PassThroughEndpointLogging(
|
||||
TranscribePassthroughLoggingHandler(job_pricer=job_pricer), log_dispatch=log_dispatch
|
||||
)
|
||||
|
||||
await logging.pass_through_async_success_handler(
|
||||
httpx_response=_make_response("StartTranscriptionJob", text=start_response),
|
||||
response_body=json.loads(start_response),
|
||||
logging_obj=_make_logging_obj(),
|
||||
url_route="https://transcribe.us-west-2.amazonaws.com/",
|
||||
result="",
|
||||
start_time=datetime.now(),
|
||||
end_time=datetime.now(),
|
||||
cache_hit=False,
|
||||
request_body={"TranscriptionJobName": "litellm-job-1"},
|
||||
passthrough_logging_payload={"url": "https://transcribe.us-west-2.amazonaws.com/"},
|
||||
custom_llm_provider="transcribe",
|
||||
)
|
||||
await asyncio.gather(*logging.transcribe_passthrough_logging_handler._pricing_tasks)
|
||||
|
||||
assert started_jobs == [
|
||||
TranscriptionJobRecord(
|
||||
TranscriptionJobStatus="IN_PROGRESS", CreationTime=5.0, Media={"MediaFileUri": "s3://b/started.wav"}
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
class TestIsTranscribeRoute:
|
||||
def test_matches_by_provider_tag(self):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue