vectorvein 0.1.1__tar.gz → 0.1.3__tar.gz
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-0.1.1 → vectorvein-0.1.3}/PKG-INFO +2 -2
- {vectorvein-0.1.1 → vectorvein-0.1.3}/pyproject.toml +2 -2
- {vectorvein-0.1.1 → vectorvein-0.1.3}/src/vectorvein/chat_clients/__init__.py +5 -3
- {vectorvein-0.1.1 → vectorvein-0.1.3}/src/vectorvein/chat_clients/openai_compatible_client.py +9 -8
- {vectorvein-0.1.1 → vectorvein-0.1.3}/src/vectorvein/chat_clients/utils.py +50 -222
- vectorvein-0.1.3/tests/sample_settings.py +467 -0
- {vectorvein-0.1.1 → vectorvein-0.1.3}/tests/test_create_chat_client.py +4 -2
- vectorvein-0.1.3/tests/test_tool_use_multi_turns.py +160 -0
- vectorvein-0.1.1/tests/sample_settings.py +0 -88
- {vectorvein-0.1.1 → vectorvein-0.1.3}/README.md +0 -0
- {vectorvein-0.1.1 → vectorvein-0.1.3}/src/vectorvein/__init__.py +0 -0
- {vectorvein-0.1.1 → vectorvein-0.1.3}/src/vectorvein/chat_clients/anthropic_client.py +0 -0
- {vectorvein-0.1.1 → vectorvein-0.1.3}/src/vectorvein/chat_clients/base_client.py +0 -0
- {vectorvein-0.1.1 → vectorvein-0.1.3}/src/vectorvein/chat_clients/deepseek_client.py +0 -0
- {vectorvein-0.1.1 → vectorvein-0.1.3}/src/vectorvein/chat_clients/gemini_client.py +0 -0
- {vectorvein-0.1.1 → vectorvein-0.1.3}/src/vectorvein/chat_clients/groq_client.py +0 -0
- {vectorvein-0.1.1 → vectorvein-0.1.3}/src/vectorvein/chat_clients/local_client.py +0 -0
- {vectorvein-0.1.1 → vectorvein-0.1.3}/src/vectorvein/chat_clients/minimax_client.py +0 -0
- {vectorvein-0.1.1 → vectorvein-0.1.3}/src/vectorvein/chat_clients/mistral_client.py +0 -0
- {vectorvein-0.1.1 → vectorvein-0.1.3}/src/vectorvein/chat_clients/moonshot_client.py +0 -0
- {vectorvein-0.1.1 → vectorvein-0.1.3}/src/vectorvein/chat_clients/openai_client.py +0 -0
- {vectorvein-0.1.1 → vectorvein-0.1.3}/src/vectorvein/chat_clients/qwen_client.py +0 -0
- {vectorvein-0.1.1 → vectorvein-0.1.3}/src/vectorvein/chat_clients/yi_client.py +0 -0
- {vectorvein-0.1.1 → vectorvein-0.1.3}/src/vectorvein/chat_clients/zhipuai_client.py +0 -0
- {vectorvein-0.1.1 → vectorvein-0.1.3}/src/vectorvein/settings/__init__.py +0 -0
- {vectorvein-0.1.1 → vectorvein-0.1.3}/src/vectorvein/types/defaults.py +0 -0
- {vectorvein-0.1.1 → vectorvein-0.1.3}/src/vectorvein/types/enums.py +0 -0
- {vectorvein-0.1.1 → vectorvein-0.1.3}/src/vectorvein/types/llm_parameters.py +0 -0
- {vectorvein-0.1.1 → vectorvein-0.1.3}/src/vectorvein/utilities/media_processing.py +0 -0
- {vectorvein-0.1.1 → vectorvein-0.1.3}/tests/__init__.py +0 -0
- {vectorvein-0.1.1 → vectorvein-0.1.3}/tests/cat.png +0 -0
- {vectorvein-0.1.1 → vectorvein-0.1.3}/tests/test_format_messages.py +0 -0
- {vectorvein-0.1.1 → vectorvein-0.1.3}/tests/test_image_input_chat_client.py +0 -0
@@ -1,10 +1,10 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: vectorvein
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.3
|
4
4
|
Summary: Default template for PDM package
|
5
5
|
Author-Email: Anderson <andersonby@163.com>
|
6
6
|
License: MIT
|
7
|
-
Requires-Python: >=3.
|
7
|
+
Requires-Python: >=3.10
|
8
8
|
Requires-Dist: openai>=1.37.1
|
9
9
|
Requires-Dist: tiktoken>=0.7.0
|
10
10
|
Requires-Dist: httpx>=0.27.0
|
@@ -13,8 +13,8 @@ dependencies = [
|
|
13
13
|
description = "Default template for PDM package"
|
14
14
|
name = "vectorvein"
|
15
15
|
readme = "README.md"
|
16
|
-
requires-python = ">=3.
|
17
|
-
version = "0.1.
|
16
|
+
requires-python = ">=3.10"
|
17
|
+
version = "0.1.3"
|
18
18
|
|
19
19
|
[project.license]
|
20
20
|
text = "MIT"
|
@@ -17,7 +17,7 @@ from .deepseek_client import DeepSeekChatClient, AsyncDeepSeekChatClient
|
|
17
17
|
from ..types import defaults as defs
|
18
18
|
from ..types.enums import BackendType, ContextLengthControlType
|
19
19
|
from .anthropic_client import AnthropicChatClient, AsyncAnthropicChatClient
|
20
|
-
from .utils import format_messages
|
20
|
+
from .utils import format_messages, get_token_counts, ToolCallContentProcessor
|
21
21
|
|
22
22
|
|
23
23
|
BackendMap = {
|
@@ -103,8 +103,10 @@ def create_async_chat_client(
|
|
103
103
|
|
104
104
|
|
105
105
|
__all__ = [
|
106
|
+
"BackendType",
|
107
|
+
"format_messages",
|
108
|
+
"get_token_counts",
|
106
109
|
"create_chat_client",
|
107
110
|
"create_async_chat_client",
|
108
|
-
"
|
109
|
-
"BackendType",
|
111
|
+
"ToolCallContentProcessor",
|
110
112
|
]
|
{vectorvein-0.1.1 → vectorvein-0.1.3}/src/vectorvein/chat_clients/openai_compatible_client.py
RENAMED
@@ -11,9 +11,8 @@ from openai import OpenAI, AsyncOpenAI, AzureOpenAI, AsyncAzureOpenAI
|
|
11
11
|
|
12
12
|
from .base_client import BaseChatClient, BaseAsyncChatClient
|
13
13
|
from .utils import (
|
14
|
-
tool_use_re,
|
15
14
|
cutoff_messages,
|
16
|
-
|
15
|
+
ToolCallContentProcessor,
|
17
16
|
generate_tool_use_system_prompt,
|
18
17
|
)
|
19
18
|
from ..settings import settings
|
@@ -128,7 +127,7 @@ class OpenAICompatibleChatClient(BaseChatClient):
|
|
128
127
|
message = chunk.choices[0].delta.model_dump()
|
129
128
|
full_content += message["content"] if message["content"] else ""
|
130
129
|
if tools:
|
131
|
-
tool_call_data =
|
130
|
+
tool_call_data = ToolCallContentProcessor(result["content"]).tool_calls
|
132
131
|
if tool_call_data:
|
133
132
|
message["tool_calls"] = tool_call_data["tool_calls"]
|
134
133
|
if full_content in ("<", "<|", "<|▶", "<|▶|") or full_content.startswith("<|▶|>"):
|
@@ -151,10 +150,11 @@ class OpenAICompatibleChatClient(BaseChatClient):
|
|
151
150
|
tool_call.model_dump() for tool_call in response.choices[0].message.tool_calls
|
152
151
|
]
|
153
152
|
else:
|
154
|
-
|
153
|
+
tool_call_content_processor = ToolCallContentProcessor(result["content"])
|
154
|
+
tool_call_data = tool_call_content_processor.tool_calls
|
155
155
|
if tool_call_data:
|
156
156
|
result["tool_calls"] = tool_call_data["tool_calls"]
|
157
|
-
result["content"] =
|
157
|
+
result["content"] = tool_call_content_processor.non_tool_content
|
158
158
|
return result
|
159
159
|
|
160
160
|
|
@@ -265,7 +265,7 @@ class AsyncOpenAICompatibleChatClient(BaseAsyncChatClient):
|
|
265
265
|
message = chunk.choices[0].delta.model_dump()
|
266
266
|
full_content += message["content"] if message["content"] else ""
|
267
267
|
if tools:
|
268
|
-
tool_call_data =
|
268
|
+
tool_call_data = ToolCallContentProcessor(result["content"]).tool_calls
|
269
269
|
if tool_call_data:
|
270
270
|
message["tool_calls"] = tool_call_data["tool_calls"]
|
271
271
|
if full_content in ("<", "<|", "<|▶", "<|▶|") or full_content.startswith("<|▶|>"):
|
@@ -288,8 +288,9 @@ class AsyncOpenAICompatibleChatClient(BaseAsyncChatClient):
|
|
288
288
|
tool_call.model_dump() for tool_call in response.choices[0].message.tool_calls
|
289
289
|
]
|
290
290
|
else:
|
291
|
-
|
291
|
+
tool_call_content_processor = ToolCallContentProcessor(result["content"])
|
292
|
+
tool_call_data = tool_call_content_processor.tool_calls
|
292
293
|
if tool_call_data:
|
293
294
|
result["tool_calls"] = tool_call_data["tool_calls"]
|
294
|
-
result["content"] =
|
295
|
+
result["content"] = tool_call_content_processor.non_tool_content
|
295
296
|
return result
|
@@ -12,7 +12,49 @@ from ..utilities.media_processing import ImageProcessor
|
|
12
12
|
chatgpt_encoding = tiktoken.encoding_for_model("gpt-3.5-turbo")
|
13
13
|
gpt_4o_encoding = tiktoken.encoding_for_model("gpt-4o")
|
14
14
|
|
15
|
-
|
15
|
+
|
16
|
+
class ToolCallContentProcessor:
|
17
|
+
tool_use_re = re.compile(r"<\|▶\|>(.*?)<\|◀\|>", re.DOTALL)
|
18
|
+
|
19
|
+
def __init__(self, content: str):
|
20
|
+
self.content = content
|
21
|
+
|
22
|
+
@property
|
23
|
+
def non_tool_content(self):
|
24
|
+
return re.sub(self.tool_use_re, "", self.content).strip()
|
25
|
+
|
26
|
+
@property
|
27
|
+
def tool_calls(self):
|
28
|
+
if "<|▶|>" not in self.content or "<|◀|>" not in self.content:
|
29
|
+
return {}
|
30
|
+
tool_calls_matches = re.findall(self.tool_use_re, self.content)
|
31
|
+
if tool_calls_matches:
|
32
|
+
tool_call_data = {}
|
33
|
+
for match in tool_calls_matches:
|
34
|
+
try:
|
35
|
+
tool_call_data = json.loads(match)
|
36
|
+
except json.JSONDecodeError:
|
37
|
+
print(f"Failed to parse tool call data:\nContent: {self.content}\nMatch: {match}")
|
38
|
+
|
39
|
+
if not tool_call_data:
|
40
|
+
return {}
|
41
|
+
|
42
|
+
arguments = json.dumps(tool_call_data["arguments"], ensure_ascii=False)
|
43
|
+
return {
|
44
|
+
"tool_calls": [
|
45
|
+
{
|
46
|
+
"index": 0,
|
47
|
+
"id": "fc1",
|
48
|
+
"function": {
|
49
|
+
"arguments": arguments,
|
50
|
+
"name": tool_call_data["name"],
|
51
|
+
},
|
52
|
+
"type": "function",
|
53
|
+
}
|
54
|
+
]
|
55
|
+
}
|
56
|
+
else:
|
57
|
+
return {}
|
16
58
|
|
17
59
|
|
18
60
|
def get_assistant_role_key(backend: BackendType) -> str:
|
@@ -48,7 +90,7 @@ def convert_type(value, value_type):
|
|
48
90
|
return value # 如果类型未知,返回原始值
|
49
91
|
|
50
92
|
|
51
|
-
def get_token_counts(text: str, model: str = "") -> int:
|
93
|
+
def get_token_counts(text: str | dict, model: str = "") -> int:
|
52
94
|
if not isinstance(text, str):
|
53
95
|
text = str(text)
|
54
96
|
if model == "gpt-3.5-turbo":
|
@@ -178,7 +220,7 @@ def format_workflow_messages(message, content, backend):
|
|
178
220
|
formatted_messages = []
|
179
221
|
|
180
222
|
# 工具调用消息
|
181
|
-
if backend in (BackendType.OpenAI, BackendType.ZhiPuAI, BackendType.Mistral):
|
223
|
+
if backend in (BackendType.OpenAI, BackendType.ZhiPuAI, BackendType.Mistral, BackendType.Yi):
|
182
224
|
tool_call_message = {
|
183
225
|
"content": None,
|
184
226
|
"role": "assistant",
|
@@ -235,7 +277,7 @@ def format_workflow_messages(message, content, backend):
|
|
235
277
|
formatted_messages.append(tool_call_message)
|
236
278
|
|
237
279
|
# 工具调用结果消息
|
238
|
-
if backend in (BackendType.OpenAI, BackendType.ZhiPuAI, BackendType.Mistral):
|
280
|
+
if backend in (BackendType.OpenAI, BackendType.ZhiPuAI, BackendType.Mistral, BackendType.Yi):
|
239
281
|
tool_call_result_message = {
|
240
282
|
"role": "tool",
|
241
283
|
"tool_call_id": message["metadata"]["selected_workflow"]["tool_call_id"],
|
@@ -321,12 +363,14 @@ def format_openai_message(message, backend):
|
|
321
363
|
|
322
364
|
|
323
365
|
def format_messages(
|
324
|
-
messages: list,
|
366
|
+
messages: list,
|
367
|
+
backend: BackendType = BackendType.OpenAI,
|
368
|
+
native_multimodal: bool = False,
|
325
369
|
) -> list:
|
326
370
|
"""将 VectorVein 和 OpenAI 的 Message 序列化后的格式转换为不同模型支持的格式
|
327
371
|
|
328
372
|
Args:
|
329
|
-
messages (list): VectorVein
|
373
|
+
messages (list): VectorVein Or OpenAI messages list.
|
330
374
|
backend (str, optional): Messages format target backend. Defaults to BackendType.OpenAI.
|
331
375
|
native_multimodal (bool, optional): Use native multimodal ability. Defaults to False.
|
332
376
|
|
@@ -396,189 +440,6 @@ def format_text_message(content, role, attachments, backend, native_multimodal):
|
|
396
440
|
return {"role": role, "content": content}
|
397
441
|
|
398
442
|
|
399
|
-
def format_messages_v1(
|
400
|
-
messages: list, backend: BackendType = BackendType.OpenAI, native_multimodal: bool = False
|
401
|
-
) -> list:
|
402
|
-
"""将 VectorVein 的 Message 序列化后的格式转换为不同模型支持的格式
|
403
|
-
|
404
|
-
Args:
|
405
|
-
messages (list): VectorVein messages list.
|
406
|
-
backend (str, optional): Messages format target backend. Defaults to BackendType.OpenAI.
|
407
|
-
native_multimodal (bool, optional): Use native multimodal ability. Defaults to False.
|
408
|
-
|
409
|
-
Returns:
|
410
|
-
list: _description_
|
411
|
-
"""
|
412
|
-
|
413
|
-
backend = backend.lower()
|
414
|
-
formatted_messages = []
|
415
|
-
for message in messages:
|
416
|
-
content = message["content"]["text"]
|
417
|
-
if message["content_type"] == "TXT":
|
418
|
-
role = "user" if message["author_type"] == "U" else get_assistant_role_key(backend)
|
419
|
-
if not message.get("attachments"):
|
420
|
-
if backend == BackendType.Gemini:
|
421
|
-
formatted_message = {"role": role, "parts": [{"text": content}]}
|
422
|
-
else:
|
423
|
-
formatted_message = {"role": role, "content": content}
|
424
|
-
formatted_messages.append(formatted_message)
|
425
|
-
continue
|
426
|
-
|
427
|
-
images_extensions = ("jpg", "jpeg", "png", "bmp")
|
428
|
-
has_images = any(attachment.lower().endswith(images_extensions) for attachment in message["attachments"])
|
429
|
-
|
430
|
-
content += "\n# Attachments:\n"
|
431
|
-
content += "\n".join([f"- {attachment}" for attachment in message["attachments"]])
|
432
|
-
|
433
|
-
if native_multimodal and has_images:
|
434
|
-
if backend == BackendType.Gemini:
|
435
|
-
parts = [{"text": content}]
|
436
|
-
for attachment in message["attachments"]:
|
437
|
-
if attachment.lower().endswith(images_extensions):
|
438
|
-
parts.append(format_image_message(image=attachment, backend=backend))
|
439
|
-
formatted_message = {"role": role, "parts": parts}
|
440
|
-
else:
|
441
|
-
formatted_message = {
|
442
|
-
"role": role,
|
443
|
-
"content": [
|
444
|
-
{"type": "text", "text": content},
|
445
|
-
*[
|
446
|
-
format_image_message(image=attachment, backend=backend)
|
447
|
-
for attachment in message["attachments"]
|
448
|
-
if attachment.lower().endswith(images_extensions)
|
449
|
-
],
|
450
|
-
],
|
451
|
-
}
|
452
|
-
formatted_messages.append(formatted_message)
|
453
|
-
else:
|
454
|
-
if backend == BackendType.Gemini:
|
455
|
-
formatted_message = {"role": role, "parts": [{"text": content}]}
|
456
|
-
else:
|
457
|
-
formatted_message = {"role": role, "content": content}
|
458
|
-
formatted_messages.append(formatted_message)
|
459
|
-
elif message["content_type"] == "WKF" and message["status"] in ("S", "R"):
|
460
|
-
# TODO: 目前只考虑单个 tool_call 的情况
|
461
|
-
if backend in (BackendType.OpenAI, BackendType.ZhiPuAI, BackendType.Mistral):
|
462
|
-
tool_call_message = {
|
463
|
-
"content": None,
|
464
|
-
"role": "assistant",
|
465
|
-
"tool_calls": [
|
466
|
-
{
|
467
|
-
"id": message["metadata"]["selected_workflow"]["tool_call_id"],
|
468
|
-
"type": "function",
|
469
|
-
"function": {
|
470
|
-
"name": message["metadata"]["selected_workflow"]["function_name"],
|
471
|
-
"arguments": json.dumps(message["metadata"]["selected_workflow"]["params"]),
|
472
|
-
},
|
473
|
-
}
|
474
|
-
],
|
475
|
-
}
|
476
|
-
elif backend == BackendType.Anthropic:
|
477
|
-
tool_call_message = {
|
478
|
-
"role": "assistant",
|
479
|
-
"content": [
|
480
|
-
{
|
481
|
-
"type": "tool_use",
|
482
|
-
"id": message["metadata"]["selected_workflow"]["tool_call_id"],
|
483
|
-
"name": message["metadata"]["selected_workflow"]["function_name"],
|
484
|
-
"input": message["metadata"]["selected_workflow"]["params"],
|
485
|
-
},
|
486
|
-
],
|
487
|
-
}
|
488
|
-
if content:
|
489
|
-
tool_call_message["content"].insert(
|
490
|
-
0,
|
491
|
-
{
|
492
|
-
"type": "text",
|
493
|
-
"text": content,
|
494
|
-
},
|
495
|
-
)
|
496
|
-
elif backend == BackendType.Gemini:
|
497
|
-
tool_call_message = {
|
498
|
-
"role": "model",
|
499
|
-
"parts": [
|
500
|
-
{
|
501
|
-
"functionCall": {
|
502
|
-
"name": message["metadata"]["selected_workflow"]["function_name"],
|
503
|
-
"args": message["metadata"]["selected_workflow"]["params"],
|
504
|
-
}
|
505
|
-
},
|
506
|
-
],
|
507
|
-
}
|
508
|
-
if content:
|
509
|
-
tool_call_message["parts"].insert(
|
510
|
-
0,
|
511
|
-
{
|
512
|
-
"text": content,
|
513
|
-
},
|
514
|
-
)
|
515
|
-
else:
|
516
|
-
tool_call_message = {
|
517
|
-
"content": json.dumps(
|
518
|
-
{
|
519
|
-
"name": message["metadata"]["selected_workflow"]["function_name"],
|
520
|
-
"arguments": json.dumps(message["metadata"]["selected_workflow"]["params"]),
|
521
|
-
},
|
522
|
-
ensure_ascii=False,
|
523
|
-
),
|
524
|
-
"role": "assistant",
|
525
|
-
}
|
526
|
-
formatted_messages.append(tool_call_message)
|
527
|
-
|
528
|
-
if backend in (BackendType.OpenAI, BackendType.ZhiPuAI, BackendType.Mistral):
|
529
|
-
tool_call_result_message = {
|
530
|
-
"role": "tool",
|
531
|
-
"tool_call_id": message["metadata"]["selected_workflow"]["tool_call_id"],
|
532
|
-
"name": message["metadata"]["selected_workflow"]["function_name"],
|
533
|
-
"content": message["metadata"].get("workflow_result", ""),
|
534
|
-
}
|
535
|
-
elif backend == BackendType.Anthropic:
|
536
|
-
tool_call_result_message = {
|
537
|
-
"role": "user",
|
538
|
-
"content": [
|
539
|
-
{
|
540
|
-
"type": "tool_result",
|
541
|
-
"tool_use_id": message["metadata"]["selected_workflow"]["tool_call_id"],
|
542
|
-
"content": message["metadata"].get("workflow_result", ""),
|
543
|
-
}
|
544
|
-
],
|
545
|
-
}
|
546
|
-
elif backend == BackendType.Gemini:
|
547
|
-
tool_call_result_message = {
|
548
|
-
"role": "function",
|
549
|
-
"parts": [
|
550
|
-
{
|
551
|
-
"functionResponse": {
|
552
|
-
"name": message["metadata"]["selected_workflow"]["function_name"],
|
553
|
-
"response": {
|
554
|
-
"name": message["metadata"]["selected_workflow"]["function_name"],
|
555
|
-
"content": message["metadata"].get("workflow_result", ""),
|
556
|
-
},
|
557
|
-
}
|
558
|
-
}
|
559
|
-
],
|
560
|
-
}
|
561
|
-
else:
|
562
|
-
tool_call_result_message = {
|
563
|
-
"role": "user",
|
564
|
-
"content": json.dumps(
|
565
|
-
{
|
566
|
-
"function": message["metadata"]["selected_workflow"]["function_name"],
|
567
|
-
"result": message["metadata"].get("workflow_result", ""),
|
568
|
-
},
|
569
|
-
ensure_ascii=False,
|
570
|
-
),
|
571
|
-
}
|
572
|
-
formatted_messages.append(tool_call_result_message)
|
573
|
-
|
574
|
-
if content and backend not in (BackendType.Mistral, BackendType.Anthropic, BackendType.Gemini):
|
575
|
-
formatted_messages.append({"role": "assistant", "content": content})
|
576
|
-
else:
|
577
|
-
continue
|
578
|
-
|
579
|
-
return formatted_messages
|
580
|
-
|
581
|
-
|
582
443
|
def generate_tool_use_system_prompt(tools: list, format_type: str = "json") -> str:
|
583
444
|
if format_type == "json":
|
584
445
|
return (
|
@@ -600,36 +461,3 @@ def generate_tool_use_system_prompt(tools: list, format_type: str = "json") -> s
|
|
600
461
|
"## Output format\n<|▶|><invoke><tool_name>[function name:str]</tool_name><parameters><parameter_1_name>[parameter_1_value]</parameter_1_name><parameter_2_name>[parameter_2_value]</parameter_2_name>...</parameters></invoke><|◀|>\n\n"
|
601
462
|
"## Example output\n<|▶|><invoke><tool_name>calculator</tool_name><parameters><first_operand>1984135</first_operand><second_operand>9343116</second_operand><operator>*</operator></parameters></invoke><|◀|>"
|
602
463
|
)
|
603
|
-
|
604
|
-
|
605
|
-
def extract_tool_calls(content: str) -> dict:
|
606
|
-
if "<|▶|>" not in content or "<|◀|>" not in content:
|
607
|
-
return {}
|
608
|
-
tool_calls_matches = tool_use_re.findall(content)
|
609
|
-
if tool_calls_matches:
|
610
|
-
tool_call_data = {}
|
611
|
-
for match in tool_calls_matches:
|
612
|
-
try:
|
613
|
-
tool_call_data = json.loads(match)
|
614
|
-
except json.JSONDecodeError:
|
615
|
-
print(f"Failed to parse tool call data:\nContent: {content}\nMatch: {match}")
|
616
|
-
|
617
|
-
if not tool_call_data:
|
618
|
-
return {}
|
619
|
-
|
620
|
-
arguments = json.dumps(tool_call_data["arguments"], ensure_ascii=False)
|
621
|
-
return {
|
622
|
-
"tool_calls": [
|
623
|
-
{
|
624
|
-
"index": 0,
|
625
|
-
"id": "fc1",
|
626
|
-
"function": {
|
627
|
-
"arguments": arguments,
|
628
|
-
"name": tool_call_data["name"],
|
629
|
-
},
|
630
|
-
"type": "function",
|
631
|
-
}
|
632
|
-
]
|
633
|
-
}
|
634
|
-
else:
|
635
|
-
return {}
|
@@ -0,0 +1,467 @@
|
|
1
|
+
# @Author: Bi Ying
|
2
|
+
# @Date: 2024-07-27 18:26:05
|
3
|
+
sample_settings = {
|
4
|
+
"endpoints": [
|
5
|
+
{
|
6
|
+
"id": "moonshot-default",
|
7
|
+
"api_base": "https://api.moonshot.cn/v1",
|
8
|
+
"api_key": "",
|
9
|
+
"rpm": 30,
|
10
|
+
"tpm": 3000000,
|
11
|
+
"concurrent_requests": 30,
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"id": "azure-openai",
|
15
|
+
"region": "East US",
|
16
|
+
"api_base": "",
|
17
|
+
"endpoint_name": "",
|
18
|
+
"api_key": "",
|
19
|
+
"rpm": 900,
|
20
|
+
"tpm": 150000,
|
21
|
+
"is_azure": True,
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"id": "vertex-anthropic",
|
25
|
+
"region": "europe-west1",
|
26
|
+
"api_base": "",
|
27
|
+
"credentials": {},
|
28
|
+
"is_vertex": True,
|
29
|
+
},
|
30
|
+
{
|
31
|
+
"id": "minimax-default",
|
32
|
+
"api_base": "https://api.minimax.chat/v1/text/chatcompletion_v2",
|
33
|
+
"api_key": "",
|
34
|
+
},
|
35
|
+
{
|
36
|
+
"id": "gemini-default",
|
37
|
+
"api_base": "",
|
38
|
+
"api_key": "",
|
39
|
+
},
|
40
|
+
{
|
41
|
+
"id": "deepseek-default",
|
42
|
+
"api_base": "https://api.deepseek.com/v1",
|
43
|
+
"api_key": "",
|
44
|
+
},
|
45
|
+
{
|
46
|
+
"id": "groq-default",
|
47
|
+
"api_base": "",
|
48
|
+
"api_key": "",
|
49
|
+
},
|
50
|
+
{
|
51
|
+
"id": "mistral-default",
|
52
|
+
"api_base": "https://api.mistral.ai/v1",
|
53
|
+
"api_key": "",
|
54
|
+
},
|
55
|
+
{
|
56
|
+
"id": "lingyiwanwu-default",
|
57
|
+
"api_base": "https://api.lingyiwanwu.com/v1",
|
58
|
+
"api_key": "",
|
59
|
+
},
|
60
|
+
{
|
61
|
+
"id": "zhipuai-default",
|
62
|
+
"api_base": "https://open.bigmodel.cn/api/paas/v4",
|
63
|
+
"api_key": "",
|
64
|
+
},
|
65
|
+
],
|
66
|
+
"moonshot_models": {
|
67
|
+
"moonshot-custom": {
|
68
|
+
"id": "moonshot-v1-8k",
|
69
|
+
"endpoints": ["moonshot-default"],
|
70
|
+
"function_call_available": True,
|
71
|
+
"response_format_available": True,
|
72
|
+
"context_length": 8000,
|
73
|
+
"max_output_tokens": 4000,
|
74
|
+
},
|
75
|
+
"moonshot-v1-8k": {"endpoints": ["moonshot-default"]},
|
76
|
+
"moonshot-v1-32k": {"endpoints": ["moonshot-default"]},
|
77
|
+
"moonshot-v1-128k": {"endpoints": ["moonshot-default"]},
|
78
|
+
},
|
79
|
+
"openai_models": {
|
80
|
+
"gpt-4o": {
|
81
|
+
"id": "gpt-4o",
|
82
|
+
"endpoints": ["azure-openai"],
|
83
|
+
},
|
84
|
+
"gpt-4": {
|
85
|
+
"id": "gpt-4",
|
86
|
+
"endpoints": ["azure-openai"],
|
87
|
+
},
|
88
|
+
"gpt-35-turbo": {
|
89
|
+
"id": "gpt-35-turbo",
|
90
|
+
"endpoints": ["azure-openai"],
|
91
|
+
},
|
92
|
+
},
|
93
|
+
"anthropic_models": {
|
94
|
+
"claude-3-5-sonnet-20240620": {
|
95
|
+
"id": "claude-3-5-sonnet@20240620",
|
96
|
+
"endpoints": ["vertex-anthropic"],
|
97
|
+
}
|
98
|
+
},
|
99
|
+
"minimax_models": {"abab6.5s-chat": {"id": "abab6.5s-chat", "endpoints": ["minimax-default"]}},
|
100
|
+
"gemini_models": {
|
101
|
+
"gemini-1.5-pro": {"id": "gemini-1.5-pro", "endpoints": ["gemini-default"]},
|
102
|
+
"gemini-1.5-flash": {"id": "gemini-1.5-flash", "endpoints": ["gemini-default"]},
|
103
|
+
},
|
104
|
+
"deepseek_models": {
|
105
|
+
"deepseek-chat": {"id": "deepseek-chat", "endpoints": ["deepseek-default"]},
|
106
|
+
"deepseek-coder": {"id": "deepseek-coder", "endpoints": ["deepseek-default"]},
|
107
|
+
},
|
108
|
+
"groq_models": {
|
109
|
+
"mixtral-8x7b-32768": {"id": "mixtral-8x7b-32768", "endpoints": ["groq-default"]},
|
110
|
+
"llama3-70b-8192": {"id": "llama3-70b-8192", "endpoints": ["groq-default"]},
|
111
|
+
"llama3-8b-8192": {"id": "llama3-8b-8192", "endpoints": ["groq-default"]},
|
112
|
+
"gemma-7b-it": {"id": "gemma-7b-it", "endpoints": ["groq-default"]},
|
113
|
+
},
|
114
|
+
"mistral_models": {
|
115
|
+
"mistral-small-latest": {
|
116
|
+
"id": "mistral-small-latest",
|
117
|
+
"context_length": 30000,
|
118
|
+
"function_call_available": True,
|
119
|
+
"response_format_available": True,
|
120
|
+
"endpoints": ["mistral-default"],
|
121
|
+
},
|
122
|
+
"mistral-medium-latest": {
|
123
|
+
"id": "mistral-medium-latest",
|
124
|
+
"context_length": 30000,
|
125
|
+
"function_call_available": False,
|
126
|
+
"response_format_available": True,
|
127
|
+
"endpoints": ["mistral-default"],
|
128
|
+
},
|
129
|
+
"mistral-large-latest": {
|
130
|
+
"id": "mistral-large-latest",
|
131
|
+
"context_length": 128000,
|
132
|
+
"function_call_available": True,
|
133
|
+
"response_format_available": True,
|
134
|
+
"endpoints": ["mistral-default"],
|
135
|
+
},
|
136
|
+
},
|
137
|
+
"yi_models": {
|
138
|
+
"yi-large": {
|
139
|
+
"id": "yi-large",
|
140
|
+
"endpoints": ["lingyiwanwu-default"],
|
141
|
+
},
|
142
|
+
"yi-large-turbo": {
|
143
|
+
"id": "yi-large-turbo",
|
144
|
+
"endpoints": ["lingyiwanwu-default"],
|
145
|
+
},
|
146
|
+
"yi-large-fc": {
|
147
|
+
"id": "yi-large-fc",
|
148
|
+
"endpoints": ["lingyiwanwu-default"],
|
149
|
+
},
|
150
|
+
"yi-medium": {
|
151
|
+
"id": "yi-medium",
|
152
|
+
"endpoints": ["lingyiwanwu-default"],
|
153
|
+
},
|
154
|
+
"yi-medium-200k": {
|
155
|
+
"id": "yi-medium-200k",
|
156
|
+
"endpoints": ["lingyiwanwu-default"],
|
157
|
+
},
|
158
|
+
"yi-spark": {
|
159
|
+
"id": "yi-spark",
|
160
|
+
"endpoints": ["lingyiwanwu-default"],
|
161
|
+
},
|
162
|
+
"yi-vision": {
|
163
|
+
"id": "yi-vision",
|
164
|
+
"endpoints": ["lingyiwanwu-default"],
|
165
|
+
},
|
166
|
+
},
|
167
|
+
"zhipuai_models": {
|
168
|
+
"glm-3-turbo": {
|
169
|
+
"id": "glm-3-turbo",
|
170
|
+
"endpoints": ["zhipuai-default"],
|
171
|
+
},
|
172
|
+
"glm-4": {
|
173
|
+
"id": "glm-4",
|
174
|
+
"endpoints": ["zhipuai-default"],
|
175
|
+
},
|
176
|
+
"glm-4-0520": {
|
177
|
+
"id": "glm-4-0520",
|
178
|
+
"endpoints": ["zhipuai-default"],
|
179
|
+
},
|
180
|
+
"glm-4-air": {
|
181
|
+
"id": "glm-4-air",
|
182
|
+
"endpoints": ["zhipuai-default"],
|
183
|
+
},
|
184
|
+
"glm-4-airx": {
|
185
|
+
"id": "glm-4-airx",
|
186
|
+
"endpoints": ["zhipuai-default"],
|
187
|
+
},
|
188
|
+
"glm-4-flash": {
|
189
|
+
"id": "glm-4-flash",
|
190
|
+
"endpoints": ["zhipuai-default"],
|
191
|
+
},
|
192
|
+
"glm-4v": {
|
193
|
+
"id": "glm-4v",
|
194
|
+
"endpoints": ["zhipuai-default"],
|
195
|
+
},
|
196
|
+
},
|
197
|
+
}
|
198
|
+
|
199
|
+
sample_settings = {
|
200
|
+
"endpoints": [
|
201
|
+
{
|
202
|
+
"id": "moonshot-default",
|
203
|
+
"api_base": "https://api.moonshot.cn/v1",
|
204
|
+
"api_key": "Y2xwbG9jNTB0YzEwYmc0MHRrNmc6bXNrLXN6OFBZZ2NicEZCZ2hUMlRJU2NQeVNTd1FEeVI=",
|
205
|
+
"rpm": 30,
|
206
|
+
"tpm": 3000000,
|
207
|
+
"concurrent_requests": 30,
|
208
|
+
},
|
209
|
+
{
|
210
|
+
"id": "azure-openai-vectorvein-east-us",
|
211
|
+
"region": "East US",
|
212
|
+
"api_base": "https://vectorvein-east-us.openai.azure.com/",
|
213
|
+
"endpoint_name": "vectorvein-east-us",
|
214
|
+
"api_key": "57f4af89bb744d44be407aaea3ee2a88",
|
215
|
+
"rpm": 900,
|
216
|
+
"tpm": 150000,
|
217
|
+
"is_azure": True,
|
218
|
+
},
|
219
|
+
{
|
220
|
+
"id": "azure-openai-vectorvein-noth-central-us",
|
221
|
+
"region": "North Central US",
|
222
|
+
"api_base": "https://vectorvein-north-central-us.openai.azure.com/",
|
223
|
+
"endpoint_name": "vectorvein-north-central-us",
|
224
|
+
"api_key": "e260ed4195dc415bafad14e9463a82a5",
|
225
|
+
"rpm": 900,
|
226
|
+
"tpm": 150000,
|
227
|
+
"is_azure": True,
|
228
|
+
},
|
229
|
+
{
|
230
|
+
"id": "azure-openai-vectorvein-west-us",
|
231
|
+
"region": "West US",
|
232
|
+
"api_base": "https://vectorvein-west-us.openai.azure.com/",
|
233
|
+
"endpoint_name": "vectorvein-west-us",
|
234
|
+
"api_key": "5934e58d0637456ab644960fe5506ca8",
|
235
|
+
"rpm": 900,
|
236
|
+
"tpm": 150000,
|
237
|
+
"is_azure": True,
|
238
|
+
},
|
239
|
+
{
|
240
|
+
"id": "azure-openai-vectorvein-east-us-2",
|
241
|
+
"region": "East US 2",
|
242
|
+
"api_base": "https://vectorvein-east-us-2.openai.azure.com/",
|
243
|
+
"endpoint_name": "vectorvein-east-us-2",
|
244
|
+
"api_key": "363e5d12b3824090b66115a7d4214c89",
|
245
|
+
"rpm": 900,
|
246
|
+
"tpm": 150000,
|
247
|
+
"is_azure": True,
|
248
|
+
},
|
249
|
+
{
|
250
|
+
"id": "azure-openai-vectorvein-au-east",
|
251
|
+
"region": "Australia East",
|
252
|
+
"api_base": "https://vectorvein-au-east.openai.azure.com",
|
253
|
+
"endpoint_name": "vectorvein-au-east",
|
254
|
+
"api_key": "726c05228236484a91496be6e1c704eb",
|
255
|
+
"rpm": 480,
|
256
|
+
"tpm": 80000,
|
257
|
+
"is_azure": True,
|
258
|
+
},
|
259
|
+
{
|
260
|
+
"id": "vertex-anthropic-vectorvein",
|
261
|
+
"region": "europe-west1",
|
262
|
+
"api_base": "https://googleapis-subdomain.pages.dev/",
|
263
|
+
"credentials": {
|
264
|
+
"account": "",
|
265
|
+
"token_uri": "https://vectorvein-oauth2-googleapis.pages.dev/token",
|
266
|
+
"client_id": "764086051850-6qr4p6gpi6hn506pt8ejuq83di341hur.apps.googleusercontent.com",
|
267
|
+
"client_secret": "d-FL95Q19q7MQmFpd7hHD0Ty",
|
268
|
+
"quota_project_id": "claude-420106",
|
269
|
+
"refresh_token": "1//0g7B8-kg6qgXyCgYIARAAGBASNwF-L9Irnn4WxFpE9__nMKcF4AbyIOi84ZXBMcsG48w99rw1vywbEUI9L6z2YQiyt3KOySnexTo",
|
270
|
+
"type": "authorized_user",
|
271
|
+
"universe_domain": "googleapis.com",
|
272
|
+
},
|
273
|
+
"is_vertex": True,
|
274
|
+
},
|
275
|
+
{
|
276
|
+
"id": "minimax-default",
|
277
|
+
"api_base": "https://api.minimax.chat/v1/text/chatcompletion_v2",
|
278
|
+
"api_key": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJOYW1lIjoidmVjdG9ydmVpbiIsIlN1YmplY3RJRCI6IjE2ODczMzQ1NTQ4NzMxNjkiLCJQaG9uZSI6Ik1UVXlNVEExT1RBNE16ST0iLCJHcm91cElEIjoiMTY4NzMzNDU1NDQxOTE4NyIsIlBhZ2VOYW1lIjoiIiwiTWFpbCI6ImJpeWluZ0B0aW5ndGFsa3MuY29tIiwiQ3JlYXRlVGltZSI6IjIwMjMtMDYtMjEgMTY6MjI6MDkiLCJpc3MiOiJtaW5pbWF4In0.jeptv5f2GSB6UrYZF-DBS9t0F4-is2d4Z3wqe2iA-cWto3VNholf1xCWOU61uNkzbvNEX7QhhGvyed_u7W6Z94t5XdIDIZpVnhmKS2El0FGDoaC63XF5dTtXgrFg5R3hUxMqbC6af8V-FR-AdIvhtW_vQmlNNO2NCSyCTpR1hSnETAdq1JErV7mjwEhi0QJevm_LVXcWJ0-2By3eIvc4cP0oZ2XDXBTtNj1kMC72W7HfqcNbXpcWsOgVOldOhTV2Yag_77dWaPlFwvz3b8ySK6CrNyhNgk2OFmj556R4VT7AlDL5IkTPz2iRsvB6x8sAzOxspZbUfAY8c5Hn13Hh-Q",
|
279
|
+
},
|
280
|
+
{
|
281
|
+
"id": "gemini-default",
|
282
|
+
"api_base": "https://vectorvein-gemini.pages.dev/v1beta",
|
283
|
+
"api_key": "AIzaSyAmMpIYtRsQqulOVJvfQ0ctKMSMXAdY5xw",
|
284
|
+
},
|
285
|
+
{
|
286
|
+
"id": "deepseek-default",
|
287
|
+
"api_base": "https://api.deepseek.com/v1",
|
288
|
+
"api_key": "sk-6dad42e7154743cd80b77dff5d0ecaaa",
|
289
|
+
},
|
290
|
+
{
|
291
|
+
"id": "groq-default",
|
292
|
+
"api_base": "https://vectorvein-groq.pages.dev/openai/v1",
|
293
|
+
"api_key": "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",
|
294
|
+
},
|
295
|
+
{
|
296
|
+
"id": "mistral-default",
|
297
|
+
"api_base": "https://api.mistral.ai/v1",
|
298
|
+
"api_key": "7fIGcygGYHjiEyCiijWgB3CNWvepOFjb",
|
299
|
+
},
|
300
|
+
{
|
301
|
+
"id": "together-default",
|
302
|
+
"api_base": "https://api.together.xyz/v1",
|
303
|
+
"api_key": "bb028183093cd22c9c9e7aa108b43a1eeb103e1954e3be8c06665756ca0d76cc",
|
304
|
+
},
|
305
|
+
{
|
306
|
+
"id": "lingyiwanwu-default",
|
307
|
+
"api_base": "https://api.lingyiwanwu.com/v1",
|
308
|
+
"api_key": "15eb1320966748518702ee7167f87429",
|
309
|
+
},
|
310
|
+
{
|
311
|
+
"id": "zhipuai-default",
|
312
|
+
"api_base": "https://open.bigmodel.cn/api/paas/v4",
|
313
|
+
"api_key": "6bc7b05100ca83d062d4af2dd0331e7a.u2U0kz1Ip2MilIDQ",
|
314
|
+
},
|
315
|
+
],
|
316
|
+
"moonshot_models": {
|
317
|
+
"moonshot-custom": {
|
318
|
+
"id": "moonshot-v1-8k",
|
319
|
+
"endpoints": ["moonshot-default"],
|
320
|
+
"function_call_available": True,
|
321
|
+
"response_format_available": True,
|
322
|
+
"context_length": 8000,
|
323
|
+
"max_output_tokens": 4000,
|
324
|
+
},
|
325
|
+
"moonshot-v1-8k": {"endpoints": ["moonshot-default"]},
|
326
|
+
"moonshot-v1-32k": {"endpoints": ["moonshot-default"]},
|
327
|
+
"moonshot-v1-128k": {"endpoints": ["moonshot-default"]},
|
328
|
+
},
|
329
|
+
"openai_models": {
|
330
|
+
"gpt-4o": {
|
331
|
+
"id": "gpt-4o",
|
332
|
+
"endpoints": [
|
333
|
+
"azure-openai-vectorvein-east-us",
|
334
|
+
"azure-openai-vectorvein-noth-central-us",
|
335
|
+
"azure-openai-vectorvein-west-us",
|
336
|
+
"azure-openai-vectorvein-east-us-2",
|
337
|
+
],
|
338
|
+
},
|
339
|
+
"gpt-4": {
|
340
|
+
"id": "gpt-4",
|
341
|
+
"endpoints": [
|
342
|
+
"azure-openai-vectorvein-east-us",
|
343
|
+
"azure-openai-vectorvein-east-us-2",
|
344
|
+
"azure-openai-vectorvein-au-east",
|
345
|
+
],
|
346
|
+
},
|
347
|
+
"gpt-35-turbo": {
|
348
|
+
"id": "gpt-35-turbo",
|
349
|
+
"endpoints": [
|
350
|
+
"azure-openai-vectorvein-east-us",
|
351
|
+
"azure-openai-vectorvein-east-us-2",
|
352
|
+
"azure-openai-vectorvein-au-east",
|
353
|
+
],
|
354
|
+
},
|
355
|
+
},
|
356
|
+
"anthropic_models": {
|
357
|
+
"claude-3-5-sonnet-20240620": {
|
358
|
+
"id": "claude-3-5-sonnet@20240620",
|
359
|
+
"endpoints": ["vertex-anthropic-vectorvein"],
|
360
|
+
}
|
361
|
+
},
|
362
|
+
"minimax_models": {"abab6.5s-chat": {"id": "abab6.5s-chat", "endpoints": ["minimax-default"]}},
|
363
|
+
"gemini_models": {
|
364
|
+
"gemini-1.5-pro": {"id": "gemini-1.5-pro", "endpoints": ["gemini-default"]},
|
365
|
+
"gemini-1.5-flash": {"id": "gemini-1.5-flash", "endpoints": ["gemini-default"]},
|
366
|
+
},
|
367
|
+
"deepseek_models": {
|
368
|
+
"deepseek-chat": {"id": "deepseek-chat", "endpoints": ["deepseek-default"]},
|
369
|
+
"deepseek-coder": {"id": "deepseek-coder", "endpoints": ["deepseek-default"]},
|
370
|
+
},
|
371
|
+
"groq_models": {
|
372
|
+
"mixtral-8x7b-32768": {"id": "mixtral-8x7b-32768", "endpoints": ["groq-default"]},
|
373
|
+
"llama3-70b-8192": {"id": "llama3-70b-8192", "endpoints": ["groq-default"]},
|
374
|
+
"llama3-8b-8192": {"id": "llama3-8b-8192", "endpoints": ["groq-default"]},
|
375
|
+
"gemma-7b-it": {"id": "gemma-7b-it", "endpoints": ["groq-default"]},
|
376
|
+
},
|
377
|
+
"mistral_models": {
|
378
|
+
"mixtral-8x7b": {
|
379
|
+
"id": "mistralai/Mixtral-8x7B-Instruct-v0.1",
|
380
|
+
"context_length": 32000,
|
381
|
+
"function_call_available": False,
|
382
|
+
"response_format_available": True,
|
383
|
+
"endpoints": ["together-default"],
|
384
|
+
},
|
385
|
+
"mistral-small": {
|
386
|
+
"id": "mistral-small-latest",
|
387
|
+
"context_length": 30000,
|
388
|
+
"function_call_available": True,
|
389
|
+
"response_format_available": True,
|
390
|
+
"endpoints": ["mistral-default"],
|
391
|
+
},
|
392
|
+
"mistral-medium": {
|
393
|
+
"id": "mistral-medium-latest",
|
394
|
+
"context_length": 30000,
|
395
|
+
"function_call_available": False,
|
396
|
+
"response_format_available": True,
|
397
|
+
"endpoints": ["mistral-default"],
|
398
|
+
},
|
399
|
+
"mistral-large": {
|
400
|
+
"id": "mistral-large-latest",
|
401
|
+
"context_length": 128000,
|
402
|
+
"function_call_available": True,
|
403
|
+
"response_format_available": True,
|
404
|
+
"endpoints": ["mistral-default"],
|
405
|
+
},
|
406
|
+
},
|
407
|
+
"yi_models": {
|
408
|
+
"yi-large": {
|
409
|
+
"id": "yi-large",
|
410
|
+
"endpoints": ["lingyiwanwu-default"],
|
411
|
+
},
|
412
|
+
"yi-large-turbo": {
|
413
|
+
"id": "yi-large-turbo",
|
414
|
+
"endpoints": ["lingyiwanwu-default"],
|
415
|
+
},
|
416
|
+
"yi-large-fc": {
|
417
|
+
"id": "yi-large-fc",
|
418
|
+
"endpoints": ["lingyiwanwu-default"],
|
419
|
+
},
|
420
|
+
"yi-medium": {
|
421
|
+
"id": "yi-medium",
|
422
|
+
"endpoints": ["lingyiwanwu-default"],
|
423
|
+
},
|
424
|
+
"yi-medium-200k": {
|
425
|
+
"id": "yi-medium-200k",
|
426
|
+
"endpoints": ["lingyiwanwu-default"],
|
427
|
+
},
|
428
|
+
"yi-spark": {
|
429
|
+
"id": "yi-spark",
|
430
|
+
"endpoints": ["lingyiwanwu-default"],
|
431
|
+
},
|
432
|
+
"yi-vision": {
|
433
|
+
"id": "yi-vision",
|
434
|
+
"endpoints": ["lingyiwanwu-default"],
|
435
|
+
},
|
436
|
+
},
|
437
|
+
"zhipuai_models": {
|
438
|
+
"glm-3-turbo": {
|
439
|
+
"id": "glm-3-turbo",
|
440
|
+
"endpoints": ["zhipuai-default"],
|
441
|
+
},
|
442
|
+
"glm-4": {
|
443
|
+
"id": "glm-4",
|
444
|
+
"endpoints": ["zhipuai-default"],
|
445
|
+
},
|
446
|
+
"glm-4-0520": {
|
447
|
+
"id": "glm-4-0520",
|
448
|
+
"endpoints": ["zhipuai-default"],
|
449
|
+
},
|
450
|
+
"glm-4-air": {
|
451
|
+
"id": "glm-4-air",
|
452
|
+
"endpoints": ["zhipuai-default"],
|
453
|
+
},
|
454
|
+
"glm-4-airx": {
|
455
|
+
"id": "glm-4-airx",
|
456
|
+
"endpoints": ["zhipuai-default"],
|
457
|
+
},
|
458
|
+
"glm-4-flash": {
|
459
|
+
"id": "glm-4-flash",
|
460
|
+
"endpoints": ["zhipuai-default"],
|
461
|
+
},
|
462
|
+
"glm-4v": {
|
463
|
+
"id": "glm-4v",
|
464
|
+
"endpoints": ["zhipuai-default"],
|
465
|
+
},
|
466
|
+
},
|
467
|
+
}
|
@@ -183,14 +183,16 @@ backend = BackendType.Gemini
|
|
183
183
|
model = "gemini-1.5-flash"
|
184
184
|
backend = BackendType.OpenAI
|
185
185
|
model = "gpt-35-turbo"
|
186
|
+
backend = BackendType.Yi
|
187
|
+
model = "yi-large-fc"
|
186
188
|
start_time = time.perf_counter()
|
187
189
|
# test_sync(backend=backend, model=model, stream=False, use_tool=False)
|
188
|
-
|
190
|
+
test_sync(backend=backend, model=model, stream=False, use_tool=True)
|
189
191
|
# test_sync(backend=backend, model=model, stream=True, use_tool=False)
|
190
192
|
# test_sync(backend=backend, model=model, stream=True, use_tool=True)
|
191
193
|
# asyncio.run(test_async(backend=backend, model=model, stream=False, use_tool=False))
|
192
194
|
# asyncio.run(test_async(backend=backend, model=model, stream=False, use_tool=True))
|
193
|
-
asyncio.run(test_async(backend=backend, model=model, stream=True, use_tool=False))
|
195
|
+
# asyncio.run(test_async(backend=backend, model=model, stream=True, use_tool=False))
|
194
196
|
# asyncio.run(test_async(backend=backend, model=model, stream=True, use_tool=True))
|
195
197
|
end_time = time.perf_counter()
|
196
198
|
print(f"Stream time elapsed: {end_time - start_time} seconds")
|
@@ -0,0 +1,160 @@
|
|
1
|
+
# @Author: Bi Ying
|
2
|
+
# @Date: 2024-07-27 11:51:28
|
3
|
+
import time
|
4
|
+
import json
|
5
|
+
|
6
|
+
from vectorvein.settings import settings
|
7
|
+
from vectorvein.chat_clients import (
|
8
|
+
BackendType,
|
9
|
+
format_messages,
|
10
|
+
create_chat_client,
|
11
|
+
)
|
12
|
+
|
13
|
+
from sample_settings import sample_settings
|
14
|
+
|
15
|
+
|
16
|
+
settings.load(sample_settings)
|
17
|
+
|
18
|
+
system_prompt = "# 角色\n你是播客制作人,你的主要任务是帮助用户整理各类新闻、报告、文档等信息,将其最终呈现为播客的形式。\n\n# 工作流程\n1. 用户会向你提出了解不同的信息需求(如 Bilibili 视频内容、科技新闻、Arxiv 论文等),你需要根据用户需求决定调用的工作流。\n 1.1 论文检索优先使用工作流【search_arxiv_papers】\n2. 在用户了解某个信息后你需要向用户明确是否要将该信息加入到最终的播客内容里。\n3. 每轮对话完成后都需要向用户提问是否还需要了解更多信息还是可以开始制作播客。\n4. 当用户决定制作播客时,向用户询问最终播客稿件的风格,如严谨、幽默等。\n5. 当用户已经明确稿件风格后先根据要求生成一份文字版的稿件,然后询问用户是否满意,如果用户回复满意则调用工作流【text_to_speech_conversion】进行音频生成。\n\n# 要求\n- 调用工作流时参数名称务必准确不能写错\n- 生成回复时必须始终和用户的语言一致!\n- 如果工作流的运行结果与用户语言不一致,则务必翻译后回复用户。"
|
19
|
+
|
20
|
+
messages = [
|
21
|
+
{
|
22
|
+
"mid": "cea20838433f486dab6f17831b0df084",
|
23
|
+
"author_type": "U",
|
24
|
+
"content_type": "TXT",
|
25
|
+
"status": "S",
|
26
|
+
"create_time": 1722415381031,
|
27
|
+
"update_time": 1722415381031,
|
28
|
+
"metadata": {},
|
29
|
+
"content": {"text": "Arxiv 上关于 AI Agent的论文总结成一个播客"},
|
30
|
+
"attachments": [],
|
31
|
+
},
|
32
|
+
{
|
33
|
+
"mid": "1749e50508ed483d9d8f5ef17ecd4fa8",
|
34
|
+
"author_type": "A",
|
35
|
+
"content_type": "WKF",
|
36
|
+
"status": "S",
|
37
|
+
"create_time": 1722415381031,
|
38
|
+
"update_time": 1722415398031,
|
39
|
+
"metadata": {
|
40
|
+
"record_id": "2c92432544114dc4ab218dd3709a0585",
|
41
|
+
"workflow_result": "[{'Title': 'A Tutorial on the Use of Physics-Informed Neural Networks to Compute the Spectrum of Quantum Systems', 'arXiv Link': 'https://arxiv.org/abs/2407.20669', 'arXiv ID': 'arXiv:2407.20669[pdf,other]', 'Abstract': 'Quantum many-body systems are of great interest for many research areas, including physics, biology and chemistry. However, their simulation is extremely challenging, due to the exponential growth of the Hilbert space with the system size, making it exceedingly difficult to parameterize the wave functions of large systems by using exact methods. Neural networks and machine learning in general are a way to face this challenge. For instance, methods like Tensor networks and Neural Quantum States are being investigated as promising tools to obtain the wave function of a quantum mechanical system. In this tutorial, we focus on a particularly promising class of deep learning algorithms. We explain how to construct a Physics-Informed Neural Network (PINN) able to solve the Schrödinger equation for a given potential, by finding its eigenvalues and eigenfunctions. This technique is unsupervised, and utilizes a novel computational method in a manner that is barely explored. PINNs are a deep learning method that exploits Automatic Differentiation to solve Integro-Differential Equations in a mesh-free way. We show how to find both the ground and the excited states. The method discovers the states progressively by starting from the ground state. We explain how to introduce inductive biases in the loss to exploit further knowledge of the physical system. Such additional constraints allow for a faster and more accurate convergence. This technique can then be enhanced by a smart choice of collocation points in order to take advantage of the mesh-free nature of the PINN. The methods are made explicit by applying them to the infinite potential well and the particle in a ring, a challenging problem to be learned by anAIagentdue to the presence of complex-valued eigenfunctions and degenerate states.△ Less'}, {'Title': 'Domain Adaptable PrescriptiveAIAgentfor Enterprise', 'arXiv Link': 'https://arxiv.org/abs/2407.20447', 'arXiv ID': 'arXiv:2407.20447[pdf,other]', 'Abstract': 'Despite advancements in causal inference and prescriptiveAI, its adoption in enterprise settings remains hindered primarily due to its technical complexity. Many users lack the necessary knowledge and appropriate tools to effectively leverage these technologies. This work at the MIT-IBM WatsonAILab focuses on developing the proof-of-conceptagent, PrecAIse, a domain-adaptable conversationalagentequipped with a suite of causal and prescriptive tools to help enterprise users make better business decisions. The objective is to make advanced, novel causal inference and prescriptive tools widely accessible through natural language interactions. The presented Natural Language User Interface (NLUI) enables users with limited expertise in machine learning and data science to harness prescriptive analytics in their decision-making processes without requiring intensive computing resources. We present anagentcapable of function calling, maintaining faithful, interactive, and dynamic conversations, and supporting new domains.△ Less'}, {'Title': 'Appraisal-Guided Proximal Policy Optimization: Modeling Psychological Disorders in Dynamic Grid World', 'arXiv Link': 'https://arxiv.org/abs/2407.20383', 'arXiv ID': 'arXiv:2407.20383[pdf]', 'Abstract': \"The integration of artificial intelligence across multiple domains has emphasized the importance of replicating human-like cognitive processes inAI. By incorporating emotional intelligence intoAIagents, their emotional stability can be evaluated to enhance their resilience and dependability in critical decision-making tasks. In this work, we develop a methodology for modeling psychological disorders using Reinforcement Learning (RL)agents. We utilized Appraisal theory to train RLagentsin a dynamic grid world environment with an Appraisal-Guided Proximal Policy Optimization (AG-PPO) algorithm. Additionally, we investigated numerous reward-shaping strategies to simulate psychological disorders and regulate the behavior of theagents. A comparison of various configurations of the modified PPO algorithm identified variants that simulate Anxiety disorder and Obsessive-Compulsive Disorder (OCD)-like behavior inagents. Furthermore, we compared standard PPO with AG-PPO and its configurations, highlighting the performance improvement in terms of generalization capabilities. Finally, we conducted an analysis of theagents' behavioral patterns in complex test environments to evaluate the associated symptoms corresponding to the psychological disorders. Overall, our work showcases the benefits of the appraisal-guided PPO algorithm over the standard PPO algorithm and the potential to simulate psychological disorders in a controlled artificial environment and evaluate them on RLagents.△ Less\"}, {'Title': 'MindSearch: Mimicking Human Minds Elicits DeepAISearcher', 'arXiv Link': 'https://arxiv.org/abs/2407.20183', 'arXiv ID': 'arXiv:2407.20183[pdf,other]', 'Abstract': 'Information seeking and integration is a complex cognitive task that consumes enormous time and effort. Inspired by the remarkable progress of Large Language Models, recent works attempt to solve this task by combining LLMs and search engines. However, these methods still obtain unsatisfying performance due to three challenges: (1) complex requests often cannot be accurately and completely retrieved by the search engine once (2) corresponding information to be integrated is spread over multiple web pages along with massive noise, and (3) a large number of web pages with long contents may quickly exceed the maximum context length of LLMs. Inspired by the cognitive process when humans solve these problems, we introduce MindSearch to mimic the human minds in web information seeking and integration, which can be instantiated by a simple yet effective LLM-based multi-agentframework. The WebPlanner models the human mind of multi-step information seeking as a dynamic graph construction process: it decomposes the user query into atomic sub-questions as nodes in the graph and progressively extends the graph based on the search result from WebSearcher. Tasked with each sub-question, WebSearcher performs hierarchical information retrieval with search engines and collects valuable information for WebPlanner. The multi-agentdesign of MindSearch enables the whole framework to seek and integrate information parallelly from larger-scale (e.g., more than 300) web pages in 3 minutes, which is worth 3 hours of human effort. MindSearch demonstrates significant improvement in the response quality in terms of depth and breadth, on both close-set and open-set QA problems. Besides, responses from MindSearch based on InternLM2.5-7B are preferable by humans to ChatGPT-Web and Perplexity.ai applications, which implies that MindSearch can already deliver a competitive solution to the proprietaryAIsearch engine.△ Less'}, {'Title': 'Quantum Machine Learning Architecture Search via Deep Reinforcement Learning', 'arXiv Link': 'https://arxiv.org/abs/2407.20147', 'arXiv ID': 'arXiv:2407.20147[pdf,other]', 'Abstract': \"The rapid advancement of quantum computing (QC) and machine learning (ML) has given rise to the burgeoning field of quantum machine learning (QML), aiming to capitalize on the strengths of quantum computing to propel ML forward. Despite its promise, crafting effective QML models necessitates profound expertise to strike a delicate balance between model intricacy and feasibility on Noisy Intermediate-Scale Quantum (NISQ) devices. While complex models offer robust representation capabilities, their extensive circuit depth may impede seamless execution on extant noisy quantum platforms. In this paper, we address this quandary of QML model design by employing deep reinforcement learning to explore proficient QML model architectures tailored for designated supervised learning tasks. Specifically, our methodology involves training an RLagentto devise policies that facilitate the discovery of QML models without predetermined ansatz. Furthermore, we integrate an adaptive mechanism to dynamically adjust the learning objectives, fostering continuous improvement in theagent'slearning process. Through extensive numerical simulations, we illustrate the efficacy of our approach within the realm of classification tasks. Our proposed method successfully identifies VQC architectures capable of achieving high classification accuracy while minimizing gate depth. This pioneering approach not only advances the study ofAI-driven quantum circuit design but also holds significant promise for enhancing performance in the NISQ era.△ Less\"}]",
|
42
|
+
"selected_workflow": {
|
43
|
+
"tid": "3b0ba398b5de4439b8a22fda7d0d35b4",
|
44
|
+
"type": "WorkflowTemplate",
|
45
|
+
"brief": '输入搜索关键词和数量,返回在 Arxiv 上检索到的论文基本信息。\n返回一个列表,列表里每个元素结构如下:\n```json\n{\n "Title": "",\n "arXiv Link": "",\n "arXiv ID": "",\n "Abstract": "",\n}\n```',
|
46
|
+
"title": "搜索 Arxiv 论文",
|
47
|
+
"params": {"count": 5, "search_text": "AI Agent"},
|
48
|
+
"tool_call_id": "call_bF6aM6ChQ1-irt2DLY5Idw",
|
49
|
+
"function_name": "search_arxiv_papers",
|
50
|
+
},
|
51
|
+
},
|
52
|
+
"content": {"text": ""},
|
53
|
+
"attachments": [],
|
54
|
+
},
|
55
|
+
{
|
56
|
+
"mid": "fe89a143be9e482587e36ca309e25794",
|
57
|
+
"author_type": "A",
|
58
|
+
"content_type": "TXT",
|
59
|
+
"status": "S",
|
60
|
+
"create_time": 1722415401031,
|
61
|
+
"update_time": 1722415404031,
|
62
|
+
"metadata": {"selected_workflow": {}},
|
63
|
+
"content": {"text": "好的,我找到了关于AI Agent的一些论文。您希望将哪篇论文的内容加入到最终的播客中呢?"},
|
64
|
+
"attachments": [],
|
65
|
+
},
|
66
|
+
{
|
67
|
+
"mid": "c223b530a53b4ef68662afb69018a59b",
|
68
|
+
"author_type": "U",
|
69
|
+
"content_type": "TXT",
|
70
|
+
"status": "S",
|
71
|
+
"create_time": 1722415560031,
|
72
|
+
"update_time": 1722415560031,
|
73
|
+
"metadata": {},
|
74
|
+
"content": {"text": "都加入到播客里吧,然后画一个播客封面图吧我看看"},
|
75
|
+
"attachments": [],
|
76
|
+
},
|
77
|
+
]
|
78
|
+
|
79
|
+
|
80
|
+
tools = [
|
81
|
+
{
|
82
|
+
"type": "function",
|
83
|
+
"function": {
|
84
|
+
"name": "read_web_content",
|
85
|
+
"description": "给定网址,输出这个网址的网页正文内容",
|
86
|
+
"parameters": {
|
87
|
+
"type": "object",
|
88
|
+
"required": ["url"],
|
89
|
+
"properties": {"url": {"type": "string"}, "use_oversea_crawler": {"type": "boolean"}},
|
90
|
+
},
|
91
|
+
},
|
92
|
+
},
|
93
|
+
{
|
94
|
+
"type": "function",
|
95
|
+
"function": {
|
96
|
+
"name": "fetch_latest_tech_news",
|
97
|
+
"description": "输入要抓取的科技新闻要求,输出相关的科技新闻标题、链接、总结等信息。",
|
98
|
+
"parameters": {
|
99
|
+
"type": "object",
|
100
|
+
"required": ["user_requirements"],
|
101
|
+
"properties": {"user_requirements": {"type": "string", "description": "检索新闻的要求"}},
|
102
|
+
},
|
103
|
+
},
|
104
|
+
},
|
105
|
+
{
|
106
|
+
"type": "function",
|
107
|
+
"function": {
|
108
|
+
"name": "search_arxiv_papers",
|
109
|
+
"description": '输入搜索关键词和数量,返回在 Arxiv 上检索到的论文基本信息。\n返回一个列表,列表里每个元素结构如下:\n```json\n{\n "Title": "",\n "arXiv Link": "",\n "arXiv ID": "",\n "Abstract": "",\n}\n```\n参数1:count\n参数2:search_text',
|
110
|
+
"parameters": {
|
111
|
+
"type": "object",
|
112
|
+
"required": ["search_text"],
|
113
|
+
"properties": {"count": {"type": "integer"}, "search_text": {"type": "string"}},
|
114
|
+
},
|
115
|
+
},
|
116
|
+
},
|
117
|
+
{
|
118
|
+
"type": "function",
|
119
|
+
"function": {
|
120
|
+
"name": "dall_e_image_generation",
|
121
|
+
"description": "输入一段文字,Dall-E 根据文字内容生成一张图片。",
|
122
|
+
"parameters": {
|
123
|
+
"type": "object",
|
124
|
+
"required": ["prompt"],
|
125
|
+
"properties": {"prompt": {"type": "string", "description": "简洁的画面描述词组、语句"}},
|
126
|
+
},
|
127
|
+
},
|
128
|
+
},
|
129
|
+
{
|
130
|
+
"type": "function",
|
131
|
+
"function": {
|
132
|
+
"name": "text_to_speech_conversion",
|
133
|
+
"description": "输入文字,生成合成的音频。",
|
134
|
+
"parameters": {"type": "object", "required": ["text"], "properties": {"text": {"type": "string"}}},
|
135
|
+
},
|
136
|
+
},
|
137
|
+
]
|
138
|
+
|
139
|
+
|
140
|
+
backend = BackendType.Moonshot
|
141
|
+
model = "moonshot-v1-8k"
|
142
|
+
backend = BackendType.OpenAI
|
143
|
+
model = "gpt-4o"
|
144
|
+
backend = BackendType.Anthropic
|
145
|
+
model = "claude-3-5-sonnet-20240620"
|
146
|
+
backend = BackendType.MiniMax
|
147
|
+
model = "abab6.5s-chat"
|
148
|
+
backend = BackendType.Gemini
|
149
|
+
model = "gemini-1.5-flash"
|
150
|
+
backend = BackendType.OpenAI
|
151
|
+
model = "gpt-35-turbo"
|
152
|
+
backend = BackendType.Yi
|
153
|
+
model = "yi-large-fc"
|
154
|
+
start_time = time.perf_counter()
|
155
|
+
|
156
|
+
client = create_chat_client(backend=backend, model=model, stream=False)
|
157
|
+
response = client.create_completion(messages=format_messages(messages, backend=backend), tools=tools)
|
158
|
+
print(response)
|
159
|
+
end_time = time.perf_counter()
|
160
|
+
print(f"Stream time elapsed: {end_time - start_time} seconds")
|
@@ -1,88 +0,0 @@
|
|
1
|
-
# @Author: Bi Ying
|
2
|
-
# @Date: 2024-07-27 18:26:05
|
3
|
-
sample_settings = {
|
4
|
-
"endpoints": [
|
5
|
-
{
|
6
|
-
"id": "moonshot-default",
|
7
|
-
"api_base": "https://api.moonshot.cn/v1",
|
8
|
-
"api_key": "",
|
9
|
-
"rpm": 30,
|
10
|
-
"tpm": 3000000,
|
11
|
-
"concurrent_requests": 30,
|
12
|
-
},
|
13
|
-
{
|
14
|
-
"id": "azure-openai",
|
15
|
-
"region": "East US",
|
16
|
-
"api_base": "",
|
17
|
-
"endpoint_name": "",
|
18
|
-
"api_key": "",
|
19
|
-
"rpm": 900,
|
20
|
-
"tpm": 150000,
|
21
|
-
"is_azure": True,
|
22
|
-
},
|
23
|
-
{
|
24
|
-
"id": "vertex-anthropic",
|
25
|
-
"region": "europe-west1",
|
26
|
-
"api_base": "",
|
27
|
-
"credentials": {},
|
28
|
-
"is_vertex": True,
|
29
|
-
},
|
30
|
-
{
|
31
|
-
"id": "minimax-default",
|
32
|
-
"api_base": "https://api.minimax.chat/v1/text/chatcompletion_v2",
|
33
|
-
"api_key": "",
|
34
|
-
},
|
35
|
-
{
|
36
|
-
"id": "gemini-default",
|
37
|
-
"api_base": "",
|
38
|
-
"api_key": "",
|
39
|
-
},
|
40
|
-
],
|
41
|
-
"moonshot_models": {
|
42
|
-
"moonshot-custom": {
|
43
|
-
"id": "moonshot-v1-8k",
|
44
|
-
"endpoints": ["moonshot-default"],
|
45
|
-
"function_call_available": True,
|
46
|
-
"response_format_available": True,
|
47
|
-
"context_length": 8000,
|
48
|
-
"max_output_tokens": 4000,
|
49
|
-
},
|
50
|
-
"moonshot-v1-8k": {
|
51
|
-
"endpoints": ["moonshot-default"],
|
52
|
-
},
|
53
|
-
"moonshot-v1-32k": {
|
54
|
-
"endpoints": ["moonshot-default"],
|
55
|
-
},
|
56
|
-
"moonshot-v1-128k": {
|
57
|
-
"endpoints": ["moonshot-default"],
|
58
|
-
},
|
59
|
-
},
|
60
|
-
"openai_models": {
|
61
|
-
"gpt-4o": {
|
62
|
-
"id": "gpt-4o",
|
63
|
-
"endpoints": ["azure-openai"],
|
64
|
-
}
|
65
|
-
},
|
66
|
-
"anthropic_models": {
|
67
|
-
"claude-3-5-sonnet-20240620": {
|
68
|
-
"id": "claude-3-5-sonnet@20240620",
|
69
|
-
"endpoints": ["vertex-anthropic"],
|
70
|
-
}
|
71
|
-
},
|
72
|
-
"minimax_models": {
|
73
|
-
"abab6.5s-chat": {
|
74
|
-
"id": "abab6.5s-chat",
|
75
|
-
"endpoints": ["minimax-default"],
|
76
|
-
}
|
77
|
-
},
|
78
|
-
"gemini_models": {
|
79
|
-
"gemini-1.5-pro": {
|
80
|
-
"id": "gemini-1.5-pro",
|
81
|
-
"endpoints": ["gemini-default"],
|
82
|
-
},
|
83
|
-
"gemini-1.5-flash": {
|
84
|
-
"id": "gemini-1.5-flash",
|
85
|
-
"endpoints": ["gemini-default"],
|
86
|
-
},
|
87
|
-
},
|
88
|
-
}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|