Spaces:
Sleeping
Sleeping
Update dynamic_cheatsheet/language_model.py
Browse files
dynamic_cheatsheet/language_model.py
CHANGED
@@ -118,10 +118,15 @@ class LanguageModel:
|
|
118 |
print('history\n', history)
|
119 |
from litellm import num_tokens_from_messages
|
120 |
|
121 |
-
tokens_num = num_tokens_from_messages(
|
122 |
-
|
123 |
-
|
124 |
-
)
|
|
|
|
|
|
|
|
|
|
|
125 |
print("prompt tokens:", tokens_num)
|
126 |
|
127 |
# The self.client is already a partial function with model, api_key, base_url, etc., pre-filled for SambaNova
|
|
|
118 |
print('history\n', history)
|
119 |
from litellm import num_tokens_from_messages
|
120 |
|
121 |
+
# tokens_num = num_tokens_from_messages(
|
122 |
+
# messages=history,
|
123 |
+
# model=self.model_name
|
124 |
+
# )
|
125 |
+
try:
|
126 |
+
token_count = litellm.token_counter(model=self.model_name, messages=history)
|
127 |
+
print(f"DEBUG: litellm token_counter for '{model_name}' estimates: {token_count} tokens")
|
128 |
+
except Exception as e:
|
129 |
+
print(f"DEBUG: Error using litellm.token_counter: {e}")
|
130 |
print("prompt tokens:", tokens_num)
|
131 |
|
132 |
# The self.client is already a partial function with model, api_key, base_url, etc., pre-filled for SambaNova
|