nitrox commited on
Commit
893627d
·
verified ·
1 Parent(s): cf7a28a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -34,8 +34,12 @@ class ChatCompletionRequest(BaseModel):
34
  temperature: float = 0.7
35
 
36
  def count_tokens(text: str) -> int:
37
- # Простой подсчет токенов (слова + знаки препинания)
38
- return len(text.split()) + len([c for c in text if c in ".,!?;:()[]{}"])
 
 
 
 
39
 
40
  def clean_assistant_response(text: str) -> str:
41
  # Удаляем лишние маркеры кода и форматирования
 
34
  temperature: float = 0.7
35
 
36
  def count_tokens(text: str) -> int:
37
+ # Более точный подсчет токенов
38
+ # Считаем слова, знаки препинания и специальные символы
39
+ words = text.split()
40
+ punctuation = sum(1 for c in text if c in ".,!?;:()[]{}")
41
+ special_chars = sum(1 for c in text if c in "—«»…")
42
+ return len(words) + punctuation + special_chars
43
 
44
  def clean_assistant_response(text: str) -> str:
45
  # Удаляем лишние маркеры кода и форматирования