vectorvein 0.1.23__py3-none-any.whl → 0.1.25__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/anthropic_client.py +175 -56
- vectorvein/chat_clients/base_client.py +92 -15
- vectorvein/chat_clients/gemini_client.py +84 -15
- vectorvein/chat_clients/minimax_client.py +82 -13
- vectorvein/chat_clients/openai_compatible_client.py +136 -36
- vectorvein/chat_clients/utils.py +45 -17
- vectorvein/types/defaults.py +57 -1
- vectorvein/types/llm_parameters.py +24 -3
- {vectorvein-0.1.23.dist-info → vectorvein-0.1.25.dist-info}/METADATA +1 -1
- {vectorvein-0.1.23.dist-info → vectorvein-0.1.25.dist-info}/RECORD +12 -12
- {vectorvein-0.1.23.dist-info → vectorvein-0.1.25.dist-info}/WHEEL +1 -1
- {vectorvein-0.1.23.dist-info → vectorvein-0.1.25.dist-info}/entry_points.txt +0 -0
vectorvein/chat_clients/utils.py
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
import re
|
4
4
|
import json
|
5
5
|
from math import ceil
|
6
|
+
from typing import Iterable
|
6
7
|
import httpx
|
7
8
|
import tiktoken
|
8
9
|
from anthropic import Anthropic
|
@@ -13,6 +14,11 @@ from ..settings import settings
|
|
13
14
|
from ..utilities.retry import Retry
|
14
15
|
from ..types.enums import BackendType
|
15
16
|
from ..utilities.media_processing import ImageProcessor
|
17
|
+
from ..types.llm_parameters import (
|
18
|
+
NotGiven,
|
19
|
+
NOT_GIVEN,
|
20
|
+
ToolParam,
|
21
|
+
)
|
16
22
|
|
17
23
|
|
18
24
|
chatgpt_encoding = tiktoken.encoding_for_model("gpt-3.5-turbo")
|
@@ -127,8 +133,10 @@ def get_token_counts(text: str | dict, model: str = "") -> int:
|
|
127
133
|
.sleep_time(10)
|
128
134
|
.run()
|
129
135
|
)
|
130
|
-
response
|
131
|
-
|
136
|
+
if response is None:
|
137
|
+
return 1000
|
138
|
+
result = response.json()
|
139
|
+
return result["segments_num"]
|
132
140
|
elif model in ("moonshot-v1-8k", "moonshot-v1-32k", "moonshot-v1-128k"):
|
133
141
|
model_setting = settings.moonshot.models[model]
|
134
142
|
if len(model_setting.endpoints) == 0:
|
@@ -150,8 +158,10 @@ def get_token_counts(text: str | dict, model: str = "") -> int:
|
|
150
158
|
.sleep_time(10)
|
151
159
|
.run()
|
152
160
|
)
|
153
|
-
response
|
154
|
-
|
161
|
+
if response is None:
|
162
|
+
return 1000
|
163
|
+
result = response.json()
|
164
|
+
return result["data"]["total_tokens"]
|
155
165
|
elif model.startswith("gemini"):
|
156
166
|
model_setting = settings.gemini.models[model]
|
157
167
|
if len(model_setting.endpoints) == 0:
|
@@ -175,6 +185,8 @@ def get_token_counts(text: str | dict, model: str = "") -> int:
|
|
175
185
|
.sleep_time(10)
|
176
186
|
.run()
|
177
187
|
)
|
188
|
+
if response is None:
|
189
|
+
return 1000
|
178
190
|
result = response.json()
|
179
191
|
return result["totalTokens"]
|
180
192
|
elif model.startswith("claude"):
|
@@ -207,7 +219,11 @@ def calculate_image_tokens(width: int, height: int, model: str = "gpt-4o"):
|
|
207
219
|
return total_tokens
|
208
220
|
|
209
221
|
|
210
|
-
def get_message_token_counts(
|
222
|
+
def get_message_token_counts(
|
223
|
+
messages: list,
|
224
|
+
tools: list | Iterable[ToolParam] | NotGiven = NOT_GIVEN,
|
225
|
+
model: str = "gpt-4o",
|
226
|
+
) -> int:
|
211
227
|
tokens = 0
|
212
228
|
formatted_messages = format_messages(messages, backend=BackendType.OpenAI, native_multimodal=True)
|
213
229
|
for message in formatted_messages:
|
@@ -221,7 +237,7 @@ def get_message_token_counts(messages: list, tools: dict | None = None, model: s
|
|
221
237
|
elif isinstance(item, dict) and item["type"].startswith("image"):
|
222
238
|
# TODO: Get real image size
|
223
239
|
tokens += calculate_image_tokens(2048, 2048, model)
|
224
|
-
if tools
|
240
|
+
if tools:
|
225
241
|
tokens += get_token_counts(str(tools), model)
|
226
242
|
|
227
243
|
return tokens
|
@@ -297,15 +313,20 @@ def cutoff_messages(
|
|
297
313
|
if index == 0:
|
298
314
|
# 一条消息就超过长度则将该消息内容进行截断,保留该消息最后的一部分
|
299
315
|
if backend == BackendType.Gemini:
|
300
|
-
|
316
|
+
return system_message + [
|
317
|
+
{
|
318
|
+
"role": message["role"],
|
319
|
+
content_key: [{"text": message[content_key][-max_count:]}],
|
320
|
+
}
|
321
|
+
]
|
301
322
|
else:
|
302
323
|
content = message[content_key][max_count - messages_length :]
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
324
|
+
return system_message + [
|
325
|
+
{
|
326
|
+
"role": message["role"],
|
327
|
+
content_key: content,
|
328
|
+
}
|
329
|
+
]
|
309
330
|
return system_message + messages[-index:]
|
310
331
|
return system_message + messages
|
311
332
|
|
@@ -340,7 +361,7 @@ def format_image_message(image: str, backend: BackendType = BackendType.OpenAI)
|
|
340
361
|
}
|
341
362
|
|
342
363
|
|
343
|
-
def format_workflow_messages(message, content, backend):
|
364
|
+
def format_workflow_messages(message: dict, content: str, backend: BackendType):
|
344
365
|
formatted_messages = []
|
345
366
|
|
346
367
|
# 工具调用消息
|
@@ -505,7 +526,6 @@ def format_messages(
|
|
505
526
|
def is_vectorvein_message(message):
|
506
527
|
return "content_type" in message
|
507
528
|
|
508
|
-
backend = backend.lower()
|
509
529
|
formatted_messages = []
|
510
530
|
|
511
531
|
for message in messages:
|
@@ -528,7 +548,13 @@ def format_messages(
|
|
528
548
|
return formatted_messages
|
529
549
|
|
530
550
|
|
531
|
-
def format_text_message(
|
551
|
+
def format_text_message(
|
552
|
+
content: str,
|
553
|
+
role: str,
|
554
|
+
attachments: list,
|
555
|
+
backend: BackendType,
|
556
|
+
native_multimodal: bool,
|
557
|
+
):
|
532
558
|
images_extensions = ("jpg", "jpeg", "png", "bmp")
|
533
559
|
has_images = any(attachment.lower().endswith(images_extensions) for attachment in attachments)
|
534
560
|
|
@@ -564,7 +590,7 @@ def format_text_message(content, role, attachments, backend, native_multimodal):
|
|
564
590
|
return {"role": role, "content": content}
|
565
591
|
|
566
592
|
|
567
|
-
def generate_tool_use_system_prompt(tools: list, format_type: str = "json") -> str:
|
593
|
+
def generate_tool_use_system_prompt(tools: list | str, format_type: str = "json") -> str:
|
568
594
|
if format_type == "json":
|
569
595
|
return (
|
570
596
|
"You have access to the following tools. Use them if required and wait for the tool call result. Stop output after calling a tool.\n\n"
|
@@ -585,3 +611,5 @@ def generate_tool_use_system_prompt(tools: list, format_type: str = "json") -> s
|
|
585
611
|
"## 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"
|
586
612
|
"## Example output\n<|▶|><invoke><tool_name>calculator</tool_name><parameters><first_operand>1984135</first_operand><second_operand>9343116</second_operand><operator>*</operator></parameters></invoke><|◀|>"
|
587
613
|
)
|
614
|
+
else:
|
615
|
+
return ""
|
vectorvein/types/defaults.py
CHANGED
@@ -150,7 +150,7 @@ GROQ_MODELS = {
|
|
150
150
|
}
|
151
151
|
|
152
152
|
# Qwen models
|
153
|
-
QWEN_DEFAULT_MODEL = "qwen2-72b-instruct"
|
153
|
+
QWEN_DEFAULT_MODEL = "qwen2.5-72b-instruct"
|
154
154
|
QWEN_MODELS = {
|
155
155
|
"qwen1.5-1.8b-chat": {
|
156
156
|
"id": "qwen1.5-1.8b-chat",
|
@@ -208,6 +208,62 @@ QWEN_MODELS = {
|
|
208
208
|
"function_call_available": False,
|
209
209
|
"response_format_available": True,
|
210
210
|
},
|
211
|
+
"qwen2.5-7b-instruct": {
|
212
|
+
"id": "qwen2.5-7b-instruct",
|
213
|
+
"context_length": 131072,
|
214
|
+
"max_output_tokens": 8192,
|
215
|
+
"function_call_available": False,
|
216
|
+
"response_format_available": True,
|
217
|
+
},
|
218
|
+
"qwen2.5-14b-instruct": {
|
219
|
+
"id": "qwen2.5-14b-instruct",
|
220
|
+
"context_length": 131072,
|
221
|
+
"max_output_tokens": 8192,
|
222
|
+
"function_call_available": False,
|
223
|
+
"response_format_available": True,
|
224
|
+
},
|
225
|
+
"qwen2.5-32b-instruct": {
|
226
|
+
"id": "qwen2.5-32b-instruct",
|
227
|
+
"context_length": 131072,
|
228
|
+
"max_output_tokens": 8192,
|
229
|
+
"function_call_available": False,
|
230
|
+
"response_format_available": True,
|
231
|
+
},
|
232
|
+
"qwen2.5-72b-instruct": {
|
233
|
+
"id": "qwen2.5-72b-instruct",
|
234
|
+
"context_length": 131072,
|
235
|
+
"max_output_tokens": 8192,
|
236
|
+
"function_call_available": False,
|
237
|
+
"response_format_available": True,
|
238
|
+
},
|
239
|
+
"qwen-max": {
|
240
|
+
"id": "qwen-max",
|
241
|
+
"context_length": 8096,
|
242
|
+
"max_output_tokens": 2048,
|
243
|
+
"function_call_available": False,
|
244
|
+
"response_format_available": True,
|
245
|
+
},
|
246
|
+
"qwen-max-longcontext": {
|
247
|
+
"id": "qwen-max-longcontext",
|
248
|
+
"context_length": 30000,
|
249
|
+
"max_output_tokens": 2048,
|
250
|
+
"function_call_available": False,
|
251
|
+
"response_format_available": True,
|
252
|
+
},
|
253
|
+
"qwen-plus": {
|
254
|
+
"id": "qwen-plus",
|
255
|
+
"context_length": 131072,
|
256
|
+
"max_output_tokens": 8096,
|
257
|
+
"function_call_available": False,
|
258
|
+
"response_format_available": True,
|
259
|
+
},
|
260
|
+
"qwen-turbo": {
|
261
|
+
"id": "qwen-turbo",
|
262
|
+
"context_length": 8096,
|
263
|
+
"max_output_tokens": 1500,
|
264
|
+
"function_call_available": False,
|
265
|
+
"response_format_available": True,
|
266
|
+
},
|
211
267
|
}
|
212
268
|
|
213
269
|
# Yi models
|
@@ -1,10 +1,19 @@
|
|
1
1
|
# @Author: Bi Ying
|
2
2
|
# @Date: 2024-07-26 23:48:04
|
3
|
-
from typing import List, Dict, Optional
|
3
|
+
from typing import List, Dict, Optional, Union, Iterable
|
4
4
|
|
5
5
|
from pydantic import BaseModel, Field
|
6
|
-
|
6
|
+
|
7
|
+
from anthropic.types import ToolParam as AnthropicToolParam
|
8
|
+
from anthropic._types import NotGiven as AnthropicNotGiven
|
9
|
+
from anthropic.types.message_create_params import ToolChoice as AnthropicToolChoice
|
10
|
+
|
11
|
+
from openai._types import NotGiven as OpenAINotGiven
|
12
|
+
from openai._types import NOT_GIVEN as OpenAINOT_GIVEN
|
7
13
|
from openai.types.chat.chat_completion_chunk import ChoiceDeltaToolCall
|
14
|
+
from openai.types.chat.chat_completion_tool_param import ChatCompletionToolParam
|
15
|
+
from openai.types.chat.chat_completion_message_tool_call import ChatCompletionMessageToolCall
|
16
|
+
from openai.types.chat.chat_completion_tool_choice_option_param import ChatCompletionToolChoiceOptionParam
|
8
17
|
|
9
18
|
from . import defaults as defs
|
10
19
|
|
@@ -26,7 +35,7 @@ class EndpointSetting(BaseModel):
|
|
26
35
|
|
27
36
|
|
28
37
|
class ModelSetting(BaseModel):
|
29
|
-
id:
|
38
|
+
id: str = Field(..., description="The id of the model.")
|
30
39
|
endpoints: List[str] = Field(default_factory=list, description="Available endpoints for the model.")
|
31
40
|
function_call_available: bool = Field(False, description="Indicates if function call is available.")
|
32
41
|
response_format_available: bool = Field(False, description="Indicates if response format is available.")
|
@@ -80,3 +89,15 @@ class ChatCompletionDeltaMessage(BaseModel):
|
|
80
89
|
function_call_arguments: Optional[dict] = None
|
81
90
|
|
82
91
|
usage: Optional[Usage] = None
|
92
|
+
|
93
|
+
|
94
|
+
NotGiven = Union[AnthropicNotGiven, OpenAINotGiven]
|
95
|
+
|
96
|
+
NOT_GIVEN = OpenAINOT_GIVEN
|
97
|
+
|
98
|
+
OpenAIToolParam = ChatCompletionToolParam
|
99
|
+
ToolParam = OpenAIToolParam
|
100
|
+
|
101
|
+
Tools = Iterable[ToolParam]
|
102
|
+
|
103
|
+
ToolChoice = ChatCompletionToolChoiceOptionParam
|
@@ -1,28 +1,28 @@
|
|
1
|
-
vectorvein-0.1.
|
2
|
-
vectorvein-0.1.
|
3
|
-
vectorvein-0.1.
|
1
|
+
vectorvein-0.1.25.dist-info/METADATA,sha256=DtT3VCr5gTtj-j25i_7Kf28DmLVG8Ui-QPc0soqt9w8,502
|
2
|
+
vectorvein-0.1.25.dist-info/WHEEL,sha256=Vza3XR51HW1KmFP0iIMUVYIvz0uQuKJpIXKYOBGQyFQ,90
|
3
|
+
vectorvein-0.1.25.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=lOGrIEBGN-EoxJ-dF5uMsO6viNCIFIeNL8whDwE6x3g,4657
|
6
|
-
vectorvein/chat_clients/anthropic_client.py,sha256=
|
6
|
+
vectorvein/chat_clients/anthropic_client.py,sha256=h82GxBi7h22B7leBuPofwBstxH_c12tEgGjpnKg6UDc,25007
|
7
7
|
vectorvein/chat_clients/baichuan_client.py,sha256=CVMvpgjdrZGv0BWnTOBD-f2ufZ3wq3496wqukumsAr4,526
|
8
|
-
vectorvein/chat_clients/base_client.py,sha256=
|
8
|
+
vectorvein/chat_clients/base_client.py,sha256=jSUSZNowUBg1Fl0Z2c9soPwx6glomoPyi7NFZIPLVBQ,7402
|
9
9
|
vectorvein/chat_clients/deepseek_client.py,sha256=3qWu01NlJAP2N-Ff62d5-CZXZitlizE1fzb20LNetig,526
|
10
|
-
vectorvein/chat_clients/gemini_client.py,sha256=
|
10
|
+
vectorvein/chat_clients/gemini_client.py,sha256=2SrREa_wJqTXOAvv-2LSo3DVR2vONsMzmBV9WFkNQuA,17640
|
11
11
|
vectorvein/chat_clients/groq_client.py,sha256=Uow4pgdmFi93ZQSoOol2-0PhhqkW-S0XuSldvppz5U4,498
|
12
12
|
vectorvein/chat_clients/local_client.py,sha256=55nOsxzqUf79q3Y14MKROA71zxhsT7p7FsDZ89rts2M,422
|
13
|
-
vectorvein/chat_clients/minimax_client.py,sha256=
|
13
|
+
vectorvein/chat_clients/minimax_client.py,sha256=dNMhCP74gRCnReR_xNosUkGc0_NP3IfNhp48WvBpU-4,16189
|
14
14
|
vectorvein/chat_clients/mistral_client.py,sha256=1aKSylzBDaLYcFnaBIL4-sXSzWmXfBeON9Q0rq-ziWw,534
|
15
15
|
vectorvein/chat_clients/moonshot_client.py,sha256=gbu-6nGxx8uM_U2WlI4Wus881rFRotzHtMSoYOcruGU,526
|
16
16
|
vectorvein/chat_clients/openai_client.py,sha256=Nz6tV45pWcsOupxjnsRsGTicbQNJWIZyxuJoJ5DGMpg,527
|
17
|
-
vectorvein/chat_clients/openai_compatible_client.py,sha256=
|
17
|
+
vectorvein/chat_clients/openai_compatible_client.py,sha256=Ojsxs7j6s4Hne7vMDbR0u-CtDx0WZQZ1NIsQIFm5BcA,17758
|
18
18
|
vectorvein/chat_clients/qwen_client.py,sha256=-ryh-m9PgsO0fc4ulcCmPTy1155J8YUy15uPoJQOHA0,513
|
19
|
-
vectorvein/chat_clients/utils.py,sha256=
|
19
|
+
vectorvein/chat_clients/utils.py,sha256=8Md6XOF_io0ACKRQ7ruqP1eJu7g9uo80eUiGbWrLx7k,23041
|
20
20
|
vectorvein/chat_clients/yi_client.py,sha256=RNf4CRuPJfixrwLZ3-DEc3t25QDe1mvZeb9sku2f8Bc,484
|
21
21
|
vectorvein/chat_clients/zhipuai_client.py,sha256=Ys5DSeLCuedaDXr3PfG1EW2zKXopt-awO2IylWSwY0s,519
|
22
22
|
vectorvein/settings/__init__.py,sha256=jVHbhHn1BuMcyfZGXrxWKiI4NdY9wzvYyGMvKYmUtqg,3378
|
23
|
-
vectorvein/types/defaults.py,sha256=
|
23
|
+
vectorvein/types/defaults.py,sha256=EouXmZvjbvDQhYJ-5FIz6Ee6Xyc7Ud1wlOPMIDnaAfY,17811
|
24
24
|
vectorvein/types/enums.py,sha256=PNK_pTIyjJFy-yAG2PHaMIO1ey3W6fReMCkH8M8VRW4,1595
|
25
|
-
vectorvein/types/llm_parameters.py,sha256=
|
25
|
+
vectorvein/types/llm_parameters.py,sha256=N6RQ8tqO1RCywMFRWPooffeAEPd9x3JW6Bl4UgQtF5I,4379
|
26
26
|
vectorvein/utilities/media_processing.py,sha256=BujciRmw1GMmc3ELRvafL8STcy6r5b2rVnh27-uA7so,2256
|
27
27
|
vectorvein/utilities/retry.py,sha256=9ePuJdeUUGx-qMWfaFxmlOvG_lQPwCQ4UB1z3Edlo34,993
|
28
|
-
vectorvein-0.1.
|
28
|
+
vectorvein-0.1.25.dist-info/RECORD,,
|
File without changes
|