修复token计数失败导致中断的问题
This commit is contained in:
@@ -107,7 +107,7 @@ def extract_token_info(response_data: dict) -> tuple[int, int, int, int]:
|
||||
# 初始化token详细统计
|
||||
cached_tokens = 0
|
||||
reasoning_tokens = 0
|
||||
|
||||
try:
|
||||
# 尝试从不同格式获取cached_tokens
|
||||
# 格式1: input_tokens_details.cached_tokens
|
||||
if (
|
||||
@@ -138,8 +138,10 @@ def extract_token_info(response_data: dict) -> tuple[int, int, int, int]:
|
||||
and "reasoning_tokens" in usage["completion_tokens_details"]
|
||||
):
|
||||
reasoning_tokens = usage["completion_tokens_details"]["reasoning_tokens"]
|
||||
|
||||
return input_tokens, cached_tokens, output_tokens, reasoning_tokens
|
||||
except TypeError as e:
|
||||
print(f"获取token发生错误:{e.__repr__()}")
|
||||
return -1,-1,-1,-1
|
||||
|
||||
|
||||
class TokenCounter:
|
||||
|
||||
@@ -26,12 +26,14 @@ dynamic = ["version"]
|
||||
docling = [
|
||||
"opencv-python>=4.11.0.86",
|
||||
"docling>=2.40.0",
|
||||
"hf-xet>=1.1.10"
|
||||
]
|
||||
|
||||
[dependency-groups]
|
||||
dev = [
|
||||
"opencv-python>=4.11.0.86",
|
||||
"docling>=2.40.0",
|
||||
"hf-xet>=1.1.10"
|
||||
]
|
||||
[project.scripts]
|
||||
docutranslate = "docutranslate.cli:main"
|
||||
|
||||
Reference in New Issue
Block a user