From fb5a760dbe82da34df41a3a1ae771ca25a5523f1 Mon Sep 17 00:00:00 2001 From: Micheal X Date: Wed, 15 Nov 2023 22:19:23 +1300 Subject: [PATCH] 5.8.7 update openai consuming calculation. --- code/default/x_tunnel/local/openai_handler.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/code/default/x_tunnel/local/openai_handler.py b/code/default/x_tunnel/local/openai_handler.py index 26cb0f0a49..498d4371d5 100644 --- a/code/default/x_tunnel/local/openai_handler.py +++ b/code/default/x_tunnel/local/openai_handler.py @@ -80,9 +80,8 @@ def handle_openai(method, path, headers, req_body, sock): data = content dat = json.loads(data) - total_tokens = dat["usage"]["total_tokens"] - cost = total_tokens * openai_chat_token_price - g.openai_balance -= cost + consumed_balance = dat["usage"]["consumed_balance"] + g.openai_balance -= consumed_balance except Exception as e1: xlog.exception("cal tokens err:%r", e1)