Skip to content

Commit

Permalink
fix(benchmark): fix TTFT calculation error when chat service cannot r…
Browse files Browse the repository at this point in the history
…espond a valid token.
  • Loading branch information
DearPlanet committed Jun 27, 2024
1 parent 6eabc6c commit da3c8bd
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions benchmarks/backend_request_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ async def async_request_openai_completions(
async with session.post(url=api_url, json=payload,
headers=headers) as response:
if response.status == 200:
first_valid_chunk_received = False
async for chunk_bytes in response.content:
chunk_bytes = chunk_bytes.strip()
if not chunk_bytes:
Expand All @@ -268,7 +269,8 @@ async def async_request_openai_completions(
if data["choices"][0]["text"]:
timestamp = time.perf_counter()
# First token
if ttft == 0.0:
if not first_valid_chunk_received:
first_chunk_received = True
ttft = time.perf_counter() - st
output.ttft = ttft

Expand All @@ -282,9 +284,14 @@ async def async_request_openai_completions(

most_recent_timestamp = timestamp
generated_text += data["choices"][0]["text"]

if first_chunk_received:
output.success = True
else:
output.success = False
output.error = (
"Never received a valid chunk to calculate TTFT."
"This response will be marked as failed!")
output.generated_text = generated_text
output.success = True
output.latency = latency
else:
output.error = response.reason or ""
Expand Down

0 comments on commit da3c8bd

Please sign in to comment.