Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
|
|
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 |
# Удаляем лишние маркеры кода и форматирования
|