vectorvein 0.1.50__tar.gz → 0.1.52__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {vectorvein-0.1.50 → vectorvein-0.1.52}/PKG-INFO +1 -1
- {vectorvein-0.1.50 → vectorvein-0.1.52}/pyproject.toml +1 -1
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/chat_clients/minimax_client.py +20 -4
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/chat_clients/utils.py +27 -8
- {vectorvein-0.1.50 → vectorvein-0.1.52}/README.md +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/__init__.py +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/chat_clients/__init__.py +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/chat_clients/anthropic_client.py +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/chat_clients/baichuan_client.py +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/chat_clients/base_client.py +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/chat_clients/deepseek_client.py +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/chat_clients/gemini_client.py +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/chat_clients/groq_client.py +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/chat_clients/local_client.py +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/chat_clients/mistral_client.py +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/chat_clients/moonshot_client.py +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/chat_clients/openai_client.py +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/chat_clients/openai_compatible_client.py +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/chat_clients/py.typed +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/chat_clients/qwen_client.py +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/chat_clients/stepfun_client.py +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/chat_clients/yi_client.py +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/chat_clients/zhipuai_client.py +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/py.typed +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/server/token_server.py +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/settings/__init__.py +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/settings/py.typed +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/types/defaults.py +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/types/enums.py +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/types/exception.py +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/types/llm_parameters.py +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/types/py.typed +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/utilities/media_processing.py +0 -0
- {vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/utilities/retry.py +0 -0
@@ -193,11 +193,19 @@ class MiniMaxChatClient(BaseChatClient):
|
|
193
193
|
if max_tokens is None:
|
194
194
|
max_output_tokens = self.model_setting.max_output_tokens
|
195
195
|
if max_output_tokens is not None:
|
196
|
-
token_counts = get_token_counts(
|
196
|
+
token_counts = get_token_counts(
|
197
|
+
text={"messages": messages, "tools_params": tools_params},
|
198
|
+
model=self.model,
|
199
|
+
use_token_server_first=True,
|
200
|
+
)
|
197
201
|
max_tokens = self.model_setting.context_length - token_counts
|
198
202
|
max_tokens = min(max(max_tokens, 1), max_output_tokens)
|
199
203
|
else:
|
200
|
-
token_counts = get_token_counts(
|
204
|
+
token_counts = get_token_counts(
|
205
|
+
text={"messages": messages, "tools_params": tools_params},
|
206
|
+
model=self.model,
|
207
|
+
use_token_server_first=True,
|
208
|
+
)
|
201
209
|
max_tokens = self.model_setting.context_length - token_counts
|
202
210
|
|
203
211
|
self.url = self.endpoint.api_base
|
@@ -418,11 +426,19 @@ class AsyncMiniMaxChatClient(BaseAsyncChatClient):
|
|
418
426
|
if max_tokens is None:
|
419
427
|
max_output_tokens = self.model_setting.max_output_tokens
|
420
428
|
if max_output_tokens is not None:
|
421
|
-
token_counts = get_token_counts(
|
429
|
+
token_counts = get_token_counts(
|
430
|
+
text={"messages": messages, "tools_params": tools_params},
|
431
|
+
model=self.model,
|
432
|
+
use_token_server_first=True,
|
433
|
+
)
|
422
434
|
max_tokens = self.model_setting.context_length - token_counts
|
423
435
|
max_tokens = min(max(max_tokens, 1), max_output_tokens)
|
424
436
|
else:
|
425
|
-
token_counts = get_token_counts(
|
437
|
+
token_counts = get_token_counts(
|
438
|
+
text={"messages": messages, "tools_params": tools_params},
|
439
|
+
model=self.model,
|
440
|
+
use_token_server_first=True,
|
441
|
+
)
|
426
442
|
max_tokens = self.model_setting.context_length - token_counts
|
427
443
|
|
428
444
|
self.url = self.endpoint.api_base
|
@@ -2,6 +2,7 @@
|
|
2
2
|
# @Date: 2024-07-26 14:48:55
|
3
3
|
import re
|
4
4
|
import json
|
5
|
+
import warnings
|
5
6
|
from math import ceil
|
6
7
|
from typing import Iterable
|
7
8
|
|
@@ -114,7 +115,7 @@ def convert_type(value, value_type):
|
|
114
115
|
return value # 如果类型未知,返回原始值
|
115
116
|
|
116
117
|
|
117
|
-
def get_token_counts(text: str | dict, model: str = "", use_token_server_first: bool =
|
118
|
+
def get_token_counts(text: str | dict, model: str = "", use_token_server_first: bool = True) -> int:
|
118
119
|
if use_token_server_first and settings.token_server is not None:
|
119
120
|
base_url = (
|
120
121
|
settings.token_server.url
|
@@ -177,7 +178,7 @@ def get_token_counts(text: str | dict, model: str = "", use_token_server_first:
|
|
177
178
|
if isinstance(endpoint_id, dict):
|
178
179
|
endpoint_id = endpoint_id["endpoint_id"]
|
179
180
|
endpoint = settings.get_endpoint(endpoint_id)
|
180
|
-
tokenize_url = "
|
181
|
+
tokenize_url = f"{endpoint.api_base}/tokenizers/estimate-token-count"
|
181
182
|
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {endpoint.api_key}"}
|
182
183
|
request_body = {
|
183
184
|
"model": model,
|
@@ -226,11 +227,29 @@ def get_token_counts(text: str | dict, model: str = "", use_token_server_first:
|
|
226
227
|
result = response.json()
|
227
228
|
return result["totalTokens"]
|
228
229
|
elif model.startswith("claude"):
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
230
|
+
backend_settings = settings.get_backend(BackendType.Anthropic)
|
231
|
+
for endpoint_choice in backend_settings.models[model].endpoints:
|
232
|
+
if isinstance(endpoint_choice, dict):
|
233
|
+
endpoint_id = endpoint_choice["endpoint_id"]
|
234
|
+
else:
|
235
|
+
endpoint_id = endpoint_choice
|
236
|
+
endpoint = settings.get_endpoint(endpoint_id)
|
237
|
+
|
238
|
+
if endpoint.is_vertex:
|
239
|
+
continue
|
240
|
+
elif endpoint.api_schema_type == "default":
|
241
|
+
return (
|
242
|
+
Anthropic(
|
243
|
+
api_key=endpoint.api_key,
|
244
|
+
base_url=endpoint.api_base,
|
245
|
+
)
|
246
|
+
.beta.messages.count_tokens(messages=[{"role": "user", "content": text}], model=model)
|
247
|
+
.input_tokens
|
248
|
+
)
|
249
|
+
|
250
|
+
# TODO: Use anthropic token counting
|
251
|
+
warnings.warn("Anthropic token counting is not implemented yet")
|
252
|
+
return len(get_gpt_4o_encoding().encode(text))
|
234
253
|
elif model.startswith("deepseek"):
|
235
254
|
from deepseek_tokenizer import deepseek_tokenizer
|
236
255
|
|
@@ -248,7 +267,7 @@ def get_token_counts(text: str | dict, model: str = "", use_token_server_first:
|
|
248
267
|
if isinstance(endpoint_id, dict):
|
249
268
|
endpoint_id = endpoint_id["endpoint_id"]
|
250
269
|
endpoint = settings.get_endpoint(endpoint_id)
|
251
|
-
tokenize_url = "
|
270
|
+
tokenize_url = f"{endpoint.api_base}/token/count"
|
252
271
|
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {endpoint.api_key}"}
|
253
272
|
request_body = {
|
254
273
|
"model": model,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{vectorvein-0.1.50 → vectorvein-0.1.52}/src/vectorvein/chat_clients/openai_compatible_client.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|