smgc commited on
Commit
d4a68ea
1 Parent(s): f512727

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -7
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
- 使用 tiktoken 库来计算输入和输出文本的 token 数量。
81
- Claude 模型可能有不同的 tokenization 规则,但 tiktoken 是一个很好的近似工具。
82
  """
83
- # 使用 tiktoken GPT-3.5 模型进行 tokenization
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():