vectorvein 0.1.29__py3-none-any.whl → 0.1.30__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.
@@ -21,8 +21,22 @@ from ..types.llm_parameters import (
21
21
  )
22
22
 
23
23
 
24
- chatgpt_encoding = tiktoken.encoding_for_model("gpt-3.5-turbo")
25
- gpt_4o_encoding = tiktoken.encoding_for_model("gpt-4o")
24
+ gpt_35_encoding = None
25
+ gpt_4o_encoding = None
26
+
27
+
28
+ def get_gpt_35_encoding():
29
+ global gpt_35_encoding
30
+ if gpt_35_encoding is None:
31
+ gpt_35_encoding = tiktoken.encoding_for_model("gpt-3.5-turbo")
32
+ return gpt_35_encoding
33
+
34
+
35
+ def get_gpt_4o_encoding():
36
+ global gpt_4o_encoding
37
+ if gpt_4o_encoding is None:
38
+ gpt_4o_encoding = tiktoken.encoding_for_model("gpt-4o")
39
+ return gpt_4o_encoding
26
40
 
27
41
 
28
42
  class ToolCallContentProcessor:
@@ -106,9 +120,9 @@ def get_token_counts(text: str | dict, model: str = "") -> int:
106
120
  if not isinstance(text, str):
107
121
  text = str(text)
108
122
  if model == "gpt-3.5-turbo":
109
- return len(chatgpt_encoding.encode(text))
123
+ return len(get_gpt_35_encoding().encode(text))
110
124
  elif model in ("gpt-4o", "gpt-4o-mini"):
111
- return len(gpt_4o_encoding.encode(text))
125
+ return len(get_gpt_4o_encoding().encode(text))
112
126
  elif model.startswith("abab"):
113
127
  model_setting = settings.minimax.models[model]
114
128
  if len(model_setting.endpoints) == 0:
@@ -140,7 +154,7 @@ def get_token_counts(text: str | dict, model: str = "") -> int:
140
154
  elif model in ("moonshot-v1-8k", "moonshot-v1-32k", "moonshot-v1-128k"):
141
155
  model_setting = settings.moonshot.models[model]
142
156
  if len(model_setting.endpoints) == 0:
143
- return len(chatgpt_encoding.encode(text))
157
+ return len(get_gpt_35_encoding().encode(text))
144
158
  endpoint_id = model_setting.endpoints[0]
145
159
  endpoint = settings.get_endpoint(endpoint_id)
146
160
  tokenize_url = "https://api.moonshot.cn/v1/tokenizers/estimate-token-count"
@@ -165,7 +179,7 @@ def get_token_counts(text: str | dict, model: str = "") -> int:
165
179
  elif model.startswith("gemini"):
166
180
  model_setting = settings.gemini.models[model]
167
181
  if len(model_setting.endpoints) == 0:
168
- return len(chatgpt_encoding.encode(text))
182
+ return len(get_gpt_35_encoding().encode(text))
169
183
  endpoint_id = model_setting.endpoints[0]
170
184
  endpoint = settings.get_endpoint(endpoint_id)
171
185
  url = f"{endpoint.api_base}/models/{model_setting.id}:countTokens"
@@ -198,7 +212,7 @@ def get_token_counts(text: str | dict, model: str = "") -> int:
198
212
  elif model.startswith("stepfun"):
199
213
  model_setting = settings.moonshot.models[model]
200
214
  if len(model_setting.endpoints) == 0:
201
- return len(chatgpt_encoding.encode(text))
215
+ return len(get_gpt_35_encoding().encode(text))
202
216
  endpoint_id = model_setting.endpoints[0]
203
217
  endpoint = settings.get_endpoint(endpoint_id)
204
218
  tokenize_url = "https://api.stepfun.com/v1/token/count"
@@ -221,7 +235,7 @@ def get_token_counts(text: str | dict, model: str = "") -> int:
221
235
  result = response.json()
222
236
  return result["data"]["total_tokens"]
223
237
  else:
224
- return len(chatgpt_encoding.encode(text))
238
+ return len(get_gpt_35_encoding().encode(text))
225
239
 
226
240
 
227
241
  def calculate_image_tokens(width: int, height: int, model: str = "gpt-4o"):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: vectorvein
3
- Version: 0.1.29
3
+ Version: 0.1.30
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.29.dist-info/METADATA,sha256=Azvf3VhV-V6iJzO4lsm_85TFVZfvQirxRiSXQSUXVeY,502
2
- vectorvein-0.1.29.dist-info/WHEEL,sha256=Vza3XR51HW1KmFP0iIMUVYIvz0uQuKJpIXKYOBGQyFQ,90
3
- vectorvein-0.1.29.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
1
+ vectorvein-0.1.30.dist-info/METADATA,sha256=qQaonL-BtvdvT7Je-k_57GwYRjhMyOAtzG9_ABSj-JQ,502
2
+ vectorvein-0.1.30.dist-info/WHEEL,sha256=Vza3XR51HW1KmFP0iIMUVYIvz0uQuKJpIXKYOBGQyFQ,90
3
+ vectorvein-0.1.30.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=4AfQql41X0705EstkbV783vT6N4bBrJhZ5DgMwRrt5s,16018
6
6
  vectorvein/chat_clients/anthropic_client.py,sha256=h82GxBi7h22B7leBuPofwBstxH_c12tEgGjpnKg6UDc,25007
@@ -17,7 +17,7 @@ vectorvein/chat_clients/openai_client.py,sha256=Nz6tV45pWcsOupxjnsRsGTicbQNJWIZy
17
17
  vectorvein/chat_clients/openai_compatible_client.py,sha256=gfCTXji8pgFUiultiNDKcmPIGu7lFfQ9VmA8o2_Mm6c,18823
18
18
  vectorvein/chat_clients/qwen_client.py,sha256=-ryh-m9PgsO0fc4ulcCmPTy1155J8YUy15uPoJQOHA0,513
19
19
  vectorvein/chat_clients/stepfun_client.py,sha256=zsD2W5ahmR4DD9cqQTXmJr3txrGuvxbRWhFlRdwNijI,519
20
- vectorvein/chat_clients/utils.py,sha256=zwuXY7Bs14xXFdhBlnTmCTOezMeYr2cf5DeF0_5_WNE,24016
20
+ vectorvein/chat_clients/utils.py,sha256=1LddLLVf8r8_Hj5LEYrQRus2qfsuXkJPMOu9VsiKMys,24338
21
21
  vectorvein/chat_clients/yi_client.py,sha256=RNf4CRuPJfixrwLZ3-DEc3t25QDe1mvZeb9sku2f8Bc,484
22
22
  vectorvein/chat_clients/zhipuai_client.py,sha256=Ys5DSeLCuedaDXr3PfG1EW2zKXopt-awO2IylWSwY0s,519
23
23
  vectorvein/settings/__init__.py,sha256=0L-2WicBq9ctaJRoSwx8ZhVtX4slS5tHrIlSGf-tJxg,3564
@@ -27,4 +27,4 @@ vectorvein/types/exception.py,sha256=gnW4GnJ76jND6UGnodk9xmqkcbeS7Cz2rvncA2HpD5E
27
27
  vectorvein/types/llm_parameters.py,sha256=N6RQ8tqO1RCywMFRWPooffeAEPd9x3JW6Bl4UgQtF5I,4379
28
28
  vectorvein/utilities/media_processing.py,sha256=BujciRmw1GMmc3ELRvafL8STcy6r5b2rVnh27-uA7so,2256
29
29
  vectorvein/utilities/retry.py,sha256=9ePuJdeUUGx-qMWfaFxmlOvG_lQPwCQ4UB1z3Edlo34,993
30
- vectorvein-0.1.29.dist-info/RECORD,,
30
+ vectorvein-0.1.30.dist-info/RECORD,,