Update main.py
Browse files
main.py
CHANGED
@@ -519,7 +519,9 @@ async def chat_completions(request: ChatRequest, req: Request, api_key: str = De
|
|
519 |
yield f"data: {json.dumps(response_chunk)}\n\n"
|
520 |
|
521 |
# After all chunks are sent, send the final message with finish_reason
|
522 |
-
|
|
|
|
|
523 |
completion_tokens = len(assistant_content.split())
|
524 |
total_tokens = prompt_tokens + completion_tokens
|
525 |
estimated_cost = calculate_estimated_cost(prompt_tokens, completion_tokens)
|
|
|
519 |
yield f"data: {json.dumps(response_chunk)}\n\n"
|
520 |
|
521 |
# After all chunks are sent, send the final message with finish_reason
|
522 |
+
# *** Key Correction Starts Here ***
|
523 |
+
prompt_tokens = sum(len(msg.content.split()) for msg in request.messages)
|
524 |
+
# *** Key Correction Ends Here ***
|
525 |
completion_tokens = len(assistant_content.split())
|
526 |
total_tokens = prompt_tokens + completion_tokens
|
527 |
estimated_cost = calculate_estimated_cost(prompt_tokens, completion_tokens)
|