vectorvein 0.1.51__py3-none-any.whl → 0.1.53__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.
@@ -6,6 +6,7 @@ from typing import overload, Literal
6
6
  from .base_client import BaseChatClient, BaseAsyncChatClient
7
7
 
8
8
  from .yi_client import YiChatClient, AsyncYiChatClient
9
+ from .xai_client import XAIChatClient, AsyncXAIChatClient
9
10
  from .groq_client import GroqChatClient, AsyncGroqChatClient
10
11
  from .qwen_client import QwenChatClient, AsyncQwenChatClient
11
12
  from .local_client import LocalChatClient, AsyncLocalChatClient
@@ -41,6 +42,7 @@ BackendMap = {
41
42
  BackendType.ZhiPuAI: ZhiPuAIChatClient,
42
43
  BackendType.Baichuan: BaichuanChatClient,
43
44
  BackendType.StepFun: StepFunChatClient,
45
+ BackendType.XAI: XAIChatClient,
44
46
  },
45
47
  "async": {
46
48
  BackendType.Anthropic: AsyncAnthropicChatClient,
@@ -57,6 +59,7 @@ BackendMap = {
57
59
  BackendType.ZhiPuAI: AsyncZhiPuAIChatClient,
58
60
  BackendType.Baichuan: AsyncBaichuanChatClient,
59
61
  BackendType.StepFun: AsyncStepFunChatClient,
62
+ BackendType.XAI: AsyncXAIChatClient,
60
63
  },
61
64
  }
62
65
 
@@ -257,6 +260,20 @@ def create_chat_client(
257
260
  ) -> StepFunChatClient: ...
258
261
 
259
262
 
263
+ @overload
264
+ def create_chat_client(
265
+ backend: Literal[BackendType.XAI],
266
+ model: str | None = None,
267
+ stream: bool = False,
268
+ temperature: float = 0.7,
269
+ context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
270
+ random_endpoint: bool = True,
271
+ endpoint_id: str = "",
272
+ http_client: httpx.Client | None = None,
273
+ **kwargs,
274
+ ) -> XAIChatClient: ...
275
+
276
+
260
277
  @overload
261
278
  def create_chat_client(
262
279
  backend: BackendType,
@@ -496,6 +513,20 @@ def create_async_chat_client(
496
513
  ) -> AsyncStepFunChatClient: ...
497
514
 
498
515
 
516
+ @overload
517
+ def create_async_chat_client(
518
+ backend: Literal[BackendType.XAI],
519
+ model: str | None = None,
520
+ stream: bool = False,
521
+ temperature: float = 0.7,
522
+ context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
523
+ random_endpoint: bool = True,
524
+ endpoint_id: str = "",
525
+ http_client: httpx.AsyncClient | None = None,
526
+ **kwargs,
527
+ ) -> AsyncXAIChatClient: ...
528
+
529
+
499
530
  @overload
500
531
  def create_async_chat_client(
501
532
  backend: BackendType,
@@ -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,
@@ -0,0 +1,15 @@
1
+ # @Author: Bi Ying
2
+ # @Date: 2024-07-26 14:48:55
3
+ from ..types.enums import BackendType
4
+ from ..types.defaults import XAI_DEFAULT_MODEL
5
+ from .openai_compatible_client import OpenAICompatibleChatClient, AsyncOpenAICompatibleChatClient
6
+
7
+
8
+ class XAIChatClient(OpenAICompatibleChatClient):
9
+ DEFAULT_MODEL = XAI_DEFAULT_MODEL
10
+ BACKEND_NAME = BackendType.XAI
11
+
12
+
13
+ class AsyncXAIChatClient(AsyncOpenAICompatibleChatClient):
14
+ DEFAULT_MODEL = XAI_DEFAULT_MODEL
15
+ BACKEND_NAME = BackendType.XAI
@@ -35,6 +35,7 @@ class Settings(BaseModel):
35
35
  zhipuai: BackendSettings = Field(default_factory=BackendSettings, description="Zhipuai models settings.")
36
36
  baichuan: BackendSettings = Field(default_factory=BackendSettings, description="Baichuan models settings.")
37
37
  stepfun: BackendSettings = Field(default_factory=BackendSettings, description="StepFun models settings.")
38
+ xai: BackendSettings = Field(default_factory=BackendSettings, description="XAI models settings.")
38
39
 
39
40
  def __init__(self, **data):
40
41
  model_types = {
@@ -724,3 +724,14 @@ STEPFUN_MODELS: Final[Dict[str, Dict[str, Any]]] = {
724
724
  "native_multimodal": True,
725
725
  },
726
726
  }
727
+
728
+
729
+ XAI_DEFAULT_MODEL: Final[str] = "grok-beta"
730
+ XAI_MODELS: Final[Dict[str, Dict[str, Any]]] = {
731
+ "grok-beta": {
732
+ "id": "grok-beta",
733
+ "context_length": 131072,
734
+ "function_call_available": True,
735
+ "response_format_available": True,
736
+ },
737
+ }
vectorvein/types/enums.py CHANGED
@@ -50,6 +50,9 @@ class BackendType(str, Enum):
50
50
  # StepFun
51
51
  StepFun = "stepfun"
52
52
 
53
+ # XAI
54
+ XAI = "xai"
55
+
53
56
  def __repr__(self):
54
57
  """Get a string representation."""
55
58
  return f'"{self.value}"'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: vectorvein
3
- Version: 0.1.51
3
+ Version: 0.1.53
4
4
  Summary: Default template for PDM package
5
5
  Author-Email: Anderson <andersonby@163.com>
6
6
  License: MIT
@@ -1,8 +1,8 @@
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.53.dist-info/METADATA,sha256=AW3bZNyB9M8EgCvlgXGKZVpv81EXjtX-N5kJPOgCGHk,644
2
+ vectorvein-0.1.53.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
3
+ vectorvein-0.1.53.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
4
  vectorvein/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- vectorvein/chat_clients/__init__.py,sha256=dW169oK1n3v8Z0uD8itghzlCP72rxiaS-XYn6fvI2xM,16788
5
+ vectorvein/chat_clients/__init__.py,sha256=Oev7Lv1DIEWCMD-2Pm7e2cwzX7JFQTnIK-j6o4iUuyQ,17725
6
6
  vectorvein/chat_clients/anthropic_client.py,sha256=i1fMYSkUovd-Lc9B64bWMgzSTUFw4S3fj3AJ_pDokT4,34029
7
7
  vectorvein/chat_clients/baichuan_client.py,sha256=CVMvpgjdrZGv0BWnTOBD-f2ufZ3wq3496wqukumsAr4,526
8
8
  vectorvein/chat_clients/base_client.py,sha256=0Uj0e-JR0a68sRS_WfUMVd91Av7lzJh6-DukjutlaD0,9497
@@ -18,18 +18,19 @@ 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
+ vectorvein/chat_clients/xai_client.py,sha256=eLFJJrNRJ-ni3DpshODcr3S1EJQLbhVwxyO1E54LaqM,491
22
23
  vectorvein/chat_clients/yi_client.py,sha256=RNf4CRuPJfixrwLZ3-DEc3t25QDe1mvZeb9sku2f8Bc,484
23
24
  vectorvein/chat_clients/zhipuai_client.py,sha256=Ys5DSeLCuedaDXr3PfG1EW2zKXopt-awO2IylWSwY0s,519
24
25
  vectorvein/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
26
  vectorvein/server/token_server.py,sha256=36F9PKSNOX8ZtYBXY_l-76GQTpUSmQ2Y8EMy1H7wtdQ,1353
26
- vectorvein/settings/__init__.py,sha256=dyTCLhevXiKVJhOb1tjgZGMH38Indy4dkWVdDX543g0,3771
27
+ vectorvein/settings/__init__.py,sha256=g01y74x0k2JEAqNpRGG0PDs0NTULjOAZV6HRhydPX1c,3874
27
28
  vectorvein/settings/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
- vectorvein/types/defaults.py,sha256=orYqYQiQj8lj1wzsQdnyHWC3bSVYhRB14Zkm6qQDYcU,22661
29
- vectorvein/types/enums.py,sha256=x_S0IJiEWijOAEiMNdiGDGEWGtmt7TwMriJVDqrDmTo,1637
29
+ vectorvein/types/defaults.py,sha256=BxnXL_Hz_gM8mYDI6Y62J660ipCanFlAturV9lDj3aQ,22940
30
+ vectorvein/types/enums.py,sha256=7KTJSVtQueImmbr1fSwv3rQVtc0RyMWXJmoE2tDOaso,1667
30
31
  vectorvein/types/exception.py,sha256=gnW4GnJ76jND6UGnodk9xmqkcbeS7Cz2rvncA2HpD5E,69
31
32
  vectorvein/types/llm_parameters.py,sha256=5o-C_yXxxQWZy_e8OWowB2107GTS-Eawx4Mvb1q55Co,5256
32
33
  vectorvein/types/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
33
34
  vectorvein/utilities/media_processing.py,sha256=cnzLrU1OaJvSv87IOnc36FrDXtmGMDStPbxtIJ33YN4,5880
34
35
  vectorvein/utilities/retry.py,sha256=6KFS9R2HdhqM3_9jkjD4F36ZSpEx2YNFGOVlpOsUetM,2208
35
- vectorvein-0.1.51.dist-info/RECORD,,
36
+ vectorvein-0.1.53.dist-info/RECORD,,