Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,6 @@ import socketio
|
|
7 |
import requests
|
8 |
import logging
|
9 |
from threading import Event
|
10 |
-
import tiktoken # 使用 tiktoken 库进行 tokenization
|
11 |
|
12 |
app = Flask(__name__)
|
13 |
logging.basicConfig(level=logging.INFO)
|
@@ -77,13 +76,10 @@ def normalize_content(content):
|
|
77 |
|
78 |
def calculate_tokens(text):
|
79 |
"""
|
80 |
-
|
81 |
-
|
82 |
"""
|
83 |
-
#
|
84 |
-
encoding = tiktoken.encoding_for_model("gpt-3.5-turbo") # 使用 gpt-3.5-turbo 作为近似模型
|
85 |
-
tokens = encoding.encode(text)
|
86 |
-
return len(tokens)
|
87 |
|
88 |
@app.route('/')
|
89 |
def root():
|
|
|
7 |
import requests
|
8 |
import logging
|
9 |
from threading import Event
|
|
|
10 |
|
11 |
app = Flask(__name__)
|
12 |
logging.basicConfig(level=logging.INFO)
|
|
|
76 |
|
77 |
def calculate_tokens(text):
|
78 |
"""
|
79 |
+
使用字符数近似计算 token 数量。
|
80 |
+
这里假设平均每 4 个字符代表 1 个 token。
|
81 |
"""
|
82 |
+
return len(text) // 4 # 近似每 4 个字符为 1 个 token
|
|
|
|
|
|
|
83 |
|
84 |
@app.route('/')
|
85 |
def root():
|