vectorvein 0.2.44__py3-none-any.whl → 0.2.45__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.
- vectorvein/chat_clients/utils.py +58 -5
- {vectorvein-0.2.44.dist-info → vectorvein-0.2.45.dist-info}/METADATA +1 -1
- {vectorvein-0.2.44.dist-info → vectorvein-0.2.45.dist-info}/RECORD +5 -5
- {vectorvein-0.2.44.dist-info → vectorvein-0.2.45.dist-info}/WHEEL +0 -0
- {vectorvein-0.2.44.dist-info → vectorvein-0.2.45.dist-info}/entry_points.txt +0 -0
vectorvein/chat_clients/utils.py
CHANGED
@@ -489,7 +489,9 @@ def format_workflow_messages(message: dict, content: str, backend: BackendType):
|
|
489
489
|
"type": "function",
|
490
490
|
"function": {
|
491
491
|
"name": message["metadata"]["selected_workflow"]["function_name"],
|
492
|
-
"arguments": json.dumps(
|
492
|
+
"arguments": json.dumps(
|
493
|
+
message["metadata"]["selected_workflow"]["params"], ensure_ascii=False
|
494
|
+
),
|
493
495
|
},
|
494
496
|
}
|
495
497
|
],
|
@@ -513,7 +515,7 @@ def format_workflow_messages(message: dict, content: str, backend: BackendType):
|
|
513
515
|
"content": json.dumps(
|
514
516
|
{
|
515
517
|
"name": message["metadata"]["selected_workflow"]["function_name"],
|
516
|
-
"arguments": json.dumps(message["metadata"]["selected_workflow"]["params"]),
|
518
|
+
"arguments": json.dumps(message["metadata"]["selected_workflow"]["params"], ensure_ascii=False),
|
517
519
|
},
|
518
520
|
ensure_ascii=False,
|
519
521
|
),
|
@@ -559,7 +561,12 @@ def format_workflow_messages(message: dict, content: str, backend: BackendType):
|
|
559
561
|
return formatted_messages
|
560
562
|
|
561
563
|
|
562
|
-
def transform_from_openai_message(
|
564
|
+
def transform_from_openai_message(
|
565
|
+
message: ChatCompletionMessageParam,
|
566
|
+
backend: BackendType,
|
567
|
+
native_multimodal: bool = False,
|
568
|
+
function_call_available: bool = False,
|
569
|
+
):
|
563
570
|
role = message.get("role", "user")
|
564
571
|
content = message.get("content", "")
|
565
572
|
tool_calls = message.get("tool_calls", [])
|
@@ -613,13 +620,57 @@ def transform_from_openai_message(message: ChatCompletionMessageParam, backend:
|
|
613
620
|
else:
|
614
621
|
return {"role": role, "content": content}
|
615
622
|
else:
|
616
|
-
|
623
|
+
if isinstance(content, str):
|
624
|
+
if not function_call_available:
|
625
|
+
if message["role"] == "tool":
|
626
|
+
return {
|
627
|
+
"role": "user",
|
628
|
+
"content": f"Tool<tool_call_id: {message['tool_call_id']}> Call result: {content}",
|
629
|
+
}
|
630
|
+
elif message["role"] == "assistant":
|
631
|
+
if tool_calls:
|
632
|
+
tool_calls_content = json.dumps(tool_calls, ensure_ascii=False)
|
633
|
+
content += f"Tool calls: {tool_calls_content}"
|
634
|
+
return {"role": role, "content": content}
|
635
|
+
|
636
|
+
return message
|
637
|
+
elif isinstance(content, list):
|
638
|
+
formatted_content = []
|
639
|
+
for item in content:
|
640
|
+
if item["type"] == "image_url" and not native_multimodal:
|
641
|
+
formatted_content.append({"type": "text", "text": f"Image<image_url: {item['image_url']['url']}>"})
|
642
|
+
else:
|
643
|
+
formatted_content.append(item)
|
644
|
+
|
645
|
+
if not function_call_available:
|
646
|
+
if message["role"] == "tool":
|
647
|
+
role = "user"
|
648
|
+
formatted_content = [
|
649
|
+
{
|
650
|
+
"type": "text",
|
651
|
+
"text": f"Tool<tool_call_id: {message['tool_call_id']}> Call result: {formatted_content}",
|
652
|
+
}
|
653
|
+
]
|
654
|
+
elif message["role"] == "assistant":
|
655
|
+
if tool_calls:
|
656
|
+
tool_calls_content = json.dumps(tool_calls, ensure_ascii=False)
|
657
|
+
formatted_content.append({"type": "text", "text": f"Tool calls: {tool_calls_content}"})
|
658
|
+
|
659
|
+
return {"role": role, "content": formatted_content}
|
660
|
+
|
661
|
+
if tool_calls:
|
662
|
+
return {"role": role, "content": formatted_content, "tool_calls": tool_calls}
|
663
|
+
else:
|
664
|
+
return {"role": role, "content": formatted_content}
|
665
|
+
else:
|
666
|
+
return message
|
617
667
|
|
618
668
|
|
619
669
|
def format_messages(
|
620
670
|
messages: list,
|
621
671
|
backend: BackendType = BackendType.OpenAI,
|
622
672
|
native_multimodal: bool = False,
|
673
|
+
function_call_available: bool = False,
|
623
674
|
) -> list:
|
624
675
|
"""将 VectorVein 和 OpenAI 的 Message 序列化后的格式转换为不同模型支持的格式
|
625
676
|
|
@@ -651,7 +702,9 @@ def format_messages(
|
|
651
702
|
formatted_messages.extend(format_workflow_messages(message, content, backend))
|
652
703
|
else:
|
653
704
|
# 处理 OpenAI 格式的消息
|
654
|
-
formatted_message = transform_from_openai_message(
|
705
|
+
formatted_message = transform_from_openai_message(
|
706
|
+
message, backend, native_multimodal, function_call_available
|
707
|
+
)
|
655
708
|
formatted_messages.append(formatted_message)
|
656
709
|
|
657
710
|
return formatted_messages
|
@@ -1,6 +1,6 @@
|
|
1
|
-
vectorvein-0.2.
|
2
|
-
vectorvein-0.2.
|
3
|
-
vectorvein-0.2.
|
1
|
+
vectorvein-0.2.45.dist-info/METADATA,sha256=MOa2CywVU8Bj0cGja2WL5V1wdAMUf0YKhkxVG2uXxO8,4570
|
2
|
+
vectorvein-0.2.45.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
|
3
|
+
vectorvein-0.2.45.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=HOL7sgWCBgwYdiAnNPCbO
|
|
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=
|
26
|
+
vectorvein/chat_clients/utils.py,sha256=gpayOz5rfoINCAZRiKof5k4z_P2iW2XUxz6DQaheyRU,29393
|
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
|
@@ -62,4 +62,4 @@ vectorvein/workflow/nodes/vector_db.py,sha256=t6I17q6iR3yQreiDHpRrksMdWDPIvgqJs0
|
|
62
62
|
vectorvein/workflow/nodes/video_generation.py,sha256=qmdg-t_idpxq1veukd-jv_ChICMOoInKxprV9Z4Vi2w,4118
|
63
63
|
vectorvein/workflow/nodes/web_crawlers.py,sha256=BhJBX1AZH7-22Gu95Ox4qJqmH5DU-m4dbUb5N5DTA-M,5559
|
64
64
|
vectorvein/workflow/utils/json_to_code.py,sha256=F7dhDy8kGc8ndOeihGLRLGFGlquoxVlb02ENtxnQ0C8,5914
|
65
|
-
vectorvein-0.2.
|
65
|
+
vectorvein-0.2.45.dist-info/RECORD,,
|
File without changes
|
File without changes
|