vectorvein 0.2.88__py3-none-any.whl → 0.2.90__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.
@@ -4,7 +4,7 @@ import re
4
4
  import json
5
5
  import warnings
6
6
  from math import ceil
7
- from typing import Iterable
7
+ from typing import Iterable, cast
8
8
 
9
9
  import httpx
10
10
  import tiktoken
@@ -18,6 +18,9 @@ from ..types.llm_parameters import (
18
18
  NotGiven,
19
19
  NOT_GIVEN,
20
20
  ToolParam,
21
+ VectorVeinMessage,
22
+ VectorVeinTextMessage,
23
+ VectorVeinWorkflowMessage,
21
24
  )
22
25
 
23
26
 
@@ -435,7 +438,7 @@ def format_image_message(image: str, backend: BackendType = BackendType.OpenAI,
435
438
  return {"type": "image_url", "image_url": {"url": image}}
436
439
 
437
440
 
438
- def format_workflow_messages(message: dict, content: str, backend: BackendType):
441
+ def format_workflow_messages(message: VectorVeinWorkflowMessage, content: str, backend: BackendType):
439
442
  formatted_messages = []
440
443
 
441
444
  # 工具调用消息
@@ -626,7 +629,7 @@ def transform_from_openai_message(
626
629
 
627
630
 
628
631
  def format_messages(
629
- messages: list,
632
+ messages: Iterable[ChatCompletionMessageParam | VectorVeinMessage],
630
633
  backend: BackendType = BackendType.OpenAI,
631
634
  native_multimodal: bool = False,
632
635
  function_call_available: bool = False,
@@ -652,16 +655,27 @@ def format_messages(
652
655
 
653
656
  for message in messages:
654
657
  if is_vectorvein_message(message):
658
+ message = cast(VectorVeinMessage, message)
659
+ match message["content_type"]:
660
+ case "TXT":
661
+ message = cast(VectorVeinTextMessage, message)
662
+ case "WKF":
663
+ message = cast(VectorVeinWorkflowMessage, message)
664
+ case _:
665
+ raise ValueError(f"Unsupported message type: {message['content_type']}")
655
666
  # 处理 VectorVein 格式的消息
656
667
  content = message["content"]["text"]
657
668
  if message["content_type"] == "TXT":
669
+ message = cast(VectorVeinTextMessage, message)
658
670
  role = "user" if message["author_type"] == "U" else "assistant"
659
671
  formatted_message = format_text_message(content, role, message.get("attachments", []), backend, native_multimodal, process_image)
660
672
  formatted_messages.append(formatted_message)
661
673
  elif message["content_type"] == "WKF" and message["status"] in ("S", "R"):
674
+ message = cast(VectorVeinWorkflowMessage, message)
662
675
  formatted_messages.extend(format_workflow_messages(message, content, backend))
663
676
  else:
664
677
  # 处理 OpenAI 格式的消息
678
+ message = cast(ChatCompletionMessageParam, message)
665
679
  formatted_message = transform_from_openai_message(message, backend, native_multimodal, function_call_available, process_image)
666
680
  formatted_messages.append(formatted_message)
667
681
 
@@ -44,12 +44,18 @@ from .llm_parameters import (
44
44
  Usage,
45
45
  ChatCompletionMessage,
46
46
  ChatCompletionDeltaMessage,
47
+ ChatCompletionStreamOptionsParam,
47
48
  NotGiven,
48
49
  NOT_GIVEN,
49
50
  OpenAIToolParam,
50
51
  ToolParam,
51
52
  Tools,
52
53
  ToolChoice,
54
+ AnthropicToolParam,
55
+ AnthropicToolChoice,
56
+ OPENAI_NOT_GIVEN,
57
+ ANTHROPIC_NOT_GIVEN,
58
+ VectorVeinMessage,
53
59
  )
54
60
  from .settings import (
55
61
  RedisConfigDict,
@@ -117,6 +123,12 @@ __all__ = [
117
123
  "Usage",
118
124
  "ChatCompletionMessage",
119
125
  "ChatCompletionDeltaMessage",
126
+ "ChatCompletionStreamOptionsParam",
127
+ "AnthropicToolParam",
128
+ "AnthropicToolChoice",
129
+ "OPENAI_NOT_GIVEN",
130
+ "ANTHROPIC_NOT_GIVEN",
131
+ "VectorVeinMessage",
120
132
  "NotGiven",
121
133
  "NOT_GIVEN",
122
134
  "OpenAIToolParam",
@@ -1,6 +1,7 @@
1
1
  # @Author: Bi Ying
2
2
  # @Date: 2024-07-26 23:48:04
3
3
  from typing import List, Dict, Optional, Union, Iterable, Literal
4
+ from typing_extensions import TypedDict, NotRequired
4
5
 
5
6
  import httpx
6
7
  from pydantic import BaseModel, Field
@@ -26,6 +27,33 @@ from . import defaults as defs
26
27
  from .settings import EndpointOptionDict
27
28
 
28
29
 
30
+ class VectorVeinTextMessage(TypedDict):
31
+ mid: NotRequired[str]
32
+ author_type: Literal["U", "A"] # "U" for user, "A" for assistant
33
+ content_type: Literal["TXT"]
34
+ status: NotRequired[str]
35
+ create_time: NotRequired[int]
36
+ update_time: NotRequired[int]
37
+ metadata: NotRequired[dict]
38
+ content: Dict[str, str]
39
+ attachments: NotRequired[List[str]]
40
+
41
+
42
+ class VectorVeinWorkflowMessage(TypedDict):
43
+ mid: NotRequired[str]
44
+ author_type: Literal["U", "A"] # "U" for user, "A" for assistant
45
+ content_type: Literal["WKF"]
46
+ status: str
47
+ create_time: NotRequired[int]
48
+ update_time: NotRequired[int]
49
+ metadata: dict
50
+ content: Dict[str, str]
51
+ attachments: NotRequired[List[str]]
52
+
53
+
54
+ VectorVeinMessage = Union[VectorVeinTextMessage, VectorVeinWorkflowMessage]
55
+
56
+
29
57
  class EndpointSetting(BaseModel):
30
58
  id: str = Field(..., description="The id of the endpoint.")
31
59
  region: Optional[str] = Field(None, description="The region for the endpoint.")
@@ -215,4 +243,5 @@ __all__ = [
215
243
  "ResponseFormat",
216
244
  "ThinkingConfigParam",
217
245
  "ThinkingConfigEnabledParam",
246
+ "VectorVeinMessage",
218
247
  ]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: vectorvein
3
- Version: 0.2.88
3
+ Version: 0.2.90
4
4
  Summary: VectorVein Python SDK
5
5
  Author-Email: Anderson <andersonby@163.com>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
- vectorvein-0.2.88.dist-info/METADATA,sha256=KK0m-TMf6XK5cp8kW6fpkYBGcc1xUDYJynmfLAug6dk,4567
2
- vectorvein-0.2.88.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
3
- vectorvein-0.2.88.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
1
+ vectorvein-0.2.90.dist-info/METADATA,sha256=uxiyZMribelfH7JrV7nseeEMhm_XTR9Chcg8bcX2Y80,4567
2
+ vectorvein-0.2.90.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
3
+ vectorvein-0.2.90.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
4
  vectorvein/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  vectorvein/api/__init__.py,sha256=lfY-XA46fgD2iIZTU0VYP8i07AwA03Egj4Qua0vUKrQ,738
6
6
  vectorvein/api/client.py,sha256=xF-leKDQzVyyy9FnIRaz0k4eElYW1XbbzeRLcpnyk90,33047
@@ -23,7 +23,7 @@ vectorvein/chat_clients/openai_compatible_client.py,sha256=0nj5DwnY8llctoxbW-UXs
23
23
  vectorvein/chat_clients/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
24
  vectorvein/chat_clients/qwen_client.py,sha256=-ryh-m9PgsO0fc4ulcCmPTy1155J8YUy15uPoJQOHA0,513
25
25
  vectorvein/chat_clients/stepfun_client.py,sha256=zsD2W5ahmR4DD9cqQTXmJr3txrGuvxbRWhFlRdwNijI,519
26
- vectorvein/chat_clients/utils.py,sha256=2p2FJT4YNapJCI_kgWj81h0tgTj9-drSY33IizMoFrE,29723
26
+ vectorvein/chat_clients/utils.py,sha256=rMLRLF0l-D0LjamlZsJOtzQlaqqh-34EapxdCVCQq7E,30486
27
27
  vectorvein/chat_clients/xai_client.py,sha256=eLFJJrNRJ-ni3DpshODcr3S1EJQLbhVwxyO1E54LaqM,491
28
28
  vectorvein/chat_clients/yi_client.py,sha256=RNf4CRuPJfixrwLZ3-DEc3t25QDe1mvZeb9sku2f8Bc,484
29
29
  vectorvein/chat_clients/zhipuai_client.py,sha256=Ys5DSeLCuedaDXr3PfG1EW2zKXopt-awO2IylWSwY0s,519
@@ -31,11 +31,11 @@ vectorvein/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
31
31
  vectorvein/server/token_server.py,sha256=36F9PKSNOX8ZtYBXY_l-76GQTpUSmQ2Y8EMy1H7wtdQ,1353
32
32
  vectorvein/settings/__init__.py,sha256=j8BNRqJ23GWI83vFzOQJZvZuy-WtKMeOTJRghG4cG5I,11471
33
33
  vectorvein/settings/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
- vectorvein/types/__init__.py,sha256=ypg8c8AwF49FrFBMqmgH_eIBH4LFf0KN4kjqQa7zrvM,3376
34
+ vectorvein/types/__init__.py,sha256=2PIMllSLIhgIuM0Ijtms7yDS1dkiGlJVQ1ab9AM2iwk,3714
35
35
  vectorvein/types/defaults.py,sha256=v6hE1TGWoYcSBzPtlGlRVy4eg0T9qBJAcn7u_a7EZSE,37593
36
36
  vectorvein/types/enums.py,sha256=LplSVkXLBK-t8TWtJKj_f7ktWTd6CSHWRLb67XKMm54,1716
37
37
  vectorvein/types/exception.py,sha256=KtnqZ-1DstHm95SZAyZdHhkGq1bJ4A9Aw3Zfdu-VIFo,130
38
- vectorvein/types/llm_parameters.py,sha256=Fo_-_rFkBvl_dUsCZxy2xNMC9Q4qVGLzDBL9jRVbXIQ,8489
38
+ vectorvein/types/llm_parameters.py,sha256=ZQXASYCbct95tVUOXU_rgE3dxffKzyXJG6tVp6FHFkY,9388
39
39
  vectorvein/types/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
40
40
  vectorvein/types/settings.py,sha256=5wINBiT9qj3ZwDiE6Kf4r6wD3yY1bKN40xxZ7F6jEfI,4844
41
41
  vectorvein/utilities/media_processing.py,sha256=TPm73MS_a1WVqpYv0N9BrZcOK-kxWa3QHSFUI_7WgmU,8257
@@ -65,4 +65,4 @@ vectorvein/workflow/utils/analyse.py,sha256=msmvyz35UTYTwqQR5sg9H0sm1vxmGDSmep9X
65
65
  vectorvein/workflow/utils/check.py,sha256=B_NdwqIqnc7Ko2HHqFpfOmWVaAu21tPITe0szKfiZKc,11414
66
66
  vectorvein/workflow/utils/json_to_code.py,sha256=P8dhhSNgKhTnW17qXNjLO2aLdb0rA8qMAWxhObol2TU,7295
67
67
  vectorvein/workflow/utils/layout.py,sha256=j0bRD3uaXu40xCS6U6BGahBI8FrHa5MiF55GbTrZ1LM,4565
68
- vectorvein-0.2.88.dist-info/RECORD,,
68
+ vectorvein-0.2.90.dist-info/RECORD,,