vectorvein 0.1.51__py3-none-any.whl → 0.1.52__py3-none-any.whl

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.
@@ -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
 
@@ -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 = "https://api.moonshot.cn/v1/tokenizers/estimate-token-count"
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
- return (
230
- Anthropic()
231
- .beta.messages.count_tokens(messages=[{"role": "user", "content": text}], model=model)
232
- .input_tokens
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 = "https://api.stepfun.com/v1/token/count"
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,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: vectorvein
3
- Version: 0.1.51
3
+ Version: 0.1.52
4
4
  Summary: Default template for PDM package
5
5
  Author-Email: Anderson <andersonby@163.com>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
- vectorvein-0.1.51.dist-info/METADATA,sha256=Z6zB6JLQZR-jyMfrG8gldHY6DQSdC3hjEDJKoWnDUOc,644
2
- vectorvein-0.1.51.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
3
- vectorvein-0.1.51.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
1
+ vectorvein-0.1.52.dist-info/METADATA,sha256=7Tl7WKTmbcQa7SG_fgPtxaZJbR8pOGzM5mOi07ivvpo,644
2
+ vectorvein-0.1.52.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
3
+ vectorvein-0.1.52.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
4
  vectorvein/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  vectorvein/chat_clients/__init__.py,sha256=dW169oK1n3v8Z0uD8itghzlCP72rxiaS-XYn6fvI2xM,16788
6
6
  vectorvein/chat_clients/anthropic_client.py,sha256=i1fMYSkUovd-Lc9B64bWMgzSTUFw4S3fj3AJ_pDokT4,34029
@@ -18,7 +18,7 @@ vectorvein/chat_clients/openai_compatible_client.py,sha256=D2VmhpDVct4w2y58s87An
18
18
  vectorvein/chat_clients/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  vectorvein/chat_clients/qwen_client.py,sha256=-ryh-m9PgsO0fc4ulcCmPTy1155J8YUy15uPoJQOHA0,513
20
20
  vectorvein/chat_clients/stepfun_client.py,sha256=zsD2W5ahmR4DD9cqQTXmJr3txrGuvxbRWhFlRdwNijI,519
21
- vectorvein/chat_clients/utils.py,sha256=gL2B_q3FeCqLGml8rpfKfXkTHcBQlxP5U3jH9eUEsa8,25604
21
+ vectorvein/chat_clients/utils.py,sha256=HUPtdn-OSxghJNCF5Q8PsL3Ye-1Nu16O84lntPqKyao,26439
22
22
  vectorvein/chat_clients/yi_client.py,sha256=RNf4CRuPJfixrwLZ3-DEc3t25QDe1mvZeb9sku2f8Bc,484
23
23
  vectorvein/chat_clients/zhipuai_client.py,sha256=Ys5DSeLCuedaDXr3PfG1EW2zKXopt-awO2IylWSwY0s,519
24
24
  vectorvein/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -32,4 +32,4 @@ vectorvein/types/llm_parameters.py,sha256=5o-C_yXxxQWZy_e8OWowB2107GTS-Eawx4Mvb1
32
32
  vectorvein/types/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
33
33
  vectorvein/utilities/media_processing.py,sha256=cnzLrU1OaJvSv87IOnc36FrDXtmGMDStPbxtIJ33YN4,5880
34
34
  vectorvein/utilities/retry.py,sha256=6KFS9R2HdhqM3_9jkjD4F36ZSpEx2YNFGOVlpOsUetM,2208
35
- vectorvein-0.1.51.dist-info/RECORD,,
35
+ vectorvein-0.1.52.dist-info/RECORD,,