Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files
app.py
CHANGED
@@ -1150,17 +1150,17 @@ def num_tokens_from_string(string, model=""):
|
|
1150 |
result = response.json()
|
1151 |
if "input_tokens" in result:
|
1152 |
print(f"使用估算token值: {result.get('input_tokens')}")
|
1153 |
-
return result.get("input_tokens", 0), "
|
1154 |
# 如果没有提供估算值,使用字符数/4作为预估
|
1155 |
-
return len(string) // 4, "
|
1156 |
else:
|
1157 |
# 如果服务返回其他错误,记录错误并返回字符串长度/4作为预估值
|
1158 |
print(f"Tokenizer服务错误: {response.status_code} - {response.text}")
|
1159 |
-
return len(string) // 4, "
|
1160 |
except Exception as e:
|
1161 |
# 如果发生其他错误,记录错误并返回字符串长度/4作为预估值
|
1162 |
print(f"计算token错误: {e}")
|
1163 |
-
return len(string) // 4, "
|
1164 |
|
1165 |
|
1166 |
# 更新模型使用统计
|
@@ -1179,7 +1179,7 @@ def update_model_stats(model, prompt_tokens, completion_tokens, calculation_meth
|
|
1179 |
"call_time": call_time,
|
1180 |
"prompt_tokens": prompt_tokens,
|
1181 |
"completion_tokens": completion_tokens,
|
1182 |
-
"calculation_method": calculation_method,
|
1183 |
"compute_points": compute_points
|
1184 |
}
|
1185 |
model_usage_records.append(record)
|
|
|
1150 |
result = response.json()
|
1151 |
if "input_tokens" in result:
|
1152 |
print(f"使用估算token值: {result.get('input_tokens')}")
|
1153 |
+
return result.get("input_tokens", 0), "估算"
|
1154 |
# 如果没有提供估算值,使用字符数/4作为预估
|
1155 |
+
return len(string) // 4, "估算"
|
1156 |
else:
|
1157 |
# 如果服务返回其他错误,记录错误并返回字符串长度/4作为预估值
|
1158 |
print(f"Tokenizer服务错误: {response.status_code} - {response.text}")
|
1159 |
+
return len(string) // 4, "估算"
|
1160 |
except Exception as e:
|
1161 |
# 如果发生其他错误,记录错误并返回字符串长度/4作为预估值
|
1162 |
print(f"计算token错误: {e}")
|
1163 |
+
return len(string) // 4, "估算"
|
1164 |
|
1165 |
|
1166 |
# 更新模型使用统计
|
|
|
1179 |
"call_time": call_time,
|
1180 |
"prompt_tokens": prompt_tokens,
|
1181 |
"completion_tokens": completion_tokens,
|
1182 |
+
"calculation_method": "精确" if calculation_method == "api" else "估算",
|
1183 |
"compute_points": compute_points
|
1184 |
}
|
1185 |
model_usage_records.append(record)
|