vectorvein 0.1.37__tar.gz → 0.1.38__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.37 → vectorvein-0.1.38}/PKG-INFO +1 -1
- {vectorvein-0.1.37 → vectorvein-0.1.38}/pyproject.toml +1 -1
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/chat_clients/anthropic_client.py +48 -16
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/chat_clients/openai_compatible_client.py +34 -14
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/types/llm_parameters.py +9 -2
- {vectorvein-0.1.37 → vectorvein-0.1.38}/README.md +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/__init__.py +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/chat_clients/__init__.py +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/chat_clients/baichuan_client.py +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/chat_clients/base_client.py +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/chat_clients/deepseek_client.py +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/chat_clients/gemini_client.py +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/chat_clients/groq_client.py +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/chat_clients/local_client.py +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/chat_clients/minimax_client.py +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/chat_clients/mistral_client.py +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/chat_clients/moonshot_client.py +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/chat_clients/openai_client.py +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/chat_clients/py.typed +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/chat_clients/qwen_client.py +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/chat_clients/stepfun_client.py +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/chat_clients/utils.py +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/chat_clients/yi_client.py +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/chat_clients/zhipuai_client.py +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/py.typed +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/settings/__init__.py +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/settings/py.typed +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/types/defaults.py +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/types/enums.py +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/types/exception.py +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/types/py.typed +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/utilities/media_processing.py +0 -0
- {vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/utilities/retry.py +0 -0
@@ -135,12 +135,19 @@ class AnthropicChatClient(BaseChatClient):
|
|
135
135
|
http_client,
|
136
136
|
backend_name,
|
137
137
|
)
|
138
|
+
self.model_id = None
|
138
139
|
|
139
140
|
@cached_property
|
140
141
|
def raw_client(self):
|
141
142
|
if self.random_endpoint:
|
142
143
|
self.random_endpoint = True
|
143
|
-
|
144
|
+
endpoint = random.choice(self.backend_settings.models[self.model].endpoints)
|
145
|
+
self.model_id = None
|
146
|
+
if isinstance(endpoint, dict):
|
147
|
+
self.endpoint_id = endpoint["endpoint_id"]
|
148
|
+
self.model_id = endpoint["model_id"]
|
149
|
+
else:
|
150
|
+
self.endpoint_id = endpoint
|
144
151
|
self.endpoint = settings.get_endpoint(self.endpoint_id)
|
145
152
|
|
146
153
|
if self.endpoint.is_vertex:
|
@@ -265,7 +272,13 @@ class AnthropicChatClient(BaseChatClient):
|
|
265
272
|
|
266
273
|
if self.random_endpoint:
|
267
274
|
self.random_endpoint = True
|
268
|
-
|
275
|
+
endpoint = random.choice(self.backend_settings.models[self.model].endpoints)
|
276
|
+
self.model_id = None
|
277
|
+
if isinstance(endpoint, dict):
|
278
|
+
self.endpoint_id = endpoint["endpoint_id"]
|
279
|
+
self.model_id = endpoint["model_id"]
|
280
|
+
else:
|
281
|
+
self.endpoint_id = endpoint
|
269
282
|
self.endpoint = settings.get_endpoint(self.endpoint_id)
|
270
283
|
|
271
284
|
if self.endpoint.api_schema_type == "openai":
|
@@ -304,7 +317,10 @@ class AnthropicChatClient(BaseChatClient):
|
|
304
317
|
|
305
318
|
assert isinstance(self.raw_client, Anthropic | AnthropicVertex)
|
306
319
|
|
320
|
+
raw_client = self.raw_client # 调用完 self.raw_client 后,self.model_id 会被赋值
|
307
321
|
self.model_setting = self.backend_settings.models[self.model]
|
322
|
+
if self.model_id is None:
|
323
|
+
self.model_id = self.model_setting.id
|
308
324
|
|
309
325
|
if messages[0].get("role") == "system":
|
310
326
|
system_prompt: str = messages[0]["content"]
|
@@ -317,7 +333,7 @@ class AnthropicChatClient(BaseChatClient):
|
|
317
333
|
messages,
|
318
334
|
max_count=self.model_setting.context_length,
|
319
335
|
backend=self.BACKEND_NAME,
|
320
|
-
model=self.
|
336
|
+
model=self.model,
|
321
337
|
)
|
322
338
|
|
323
339
|
messages = format_messages_alternate(messages)
|
@@ -329,7 +345,7 @@ class AnthropicChatClient(BaseChatClient):
|
|
329
345
|
|
330
346
|
if max_tokens is None:
|
331
347
|
max_output_tokens = self.model_setting.max_output_tokens
|
332
|
-
token_counts = get_message_token_counts(messages=messages, tools=tools_params, model=self.
|
348
|
+
token_counts = get_message_token_counts(messages=messages, tools=tools_params, model=self.model)
|
333
349
|
if max_output_tokens is not None:
|
334
350
|
max_tokens = self.model_setting.context_length - token_counts
|
335
351
|
max_tokens = min(max(max_tokens, 1), max_output_tokens)
|
@@ -337,8 +353,8 @@ class AnthropicChatClient(BaseChatClient):
|
|
337
353
|
max_tokens = self.model_setting.context_length - token_counts
|
338
354
|
|
339
355
|
if self.stream:
|
340
|
-
stream_response =
|
341
|
-
model=self.
|
356
|
+
stream_response = raw_client.messages.create(
|
357
|
+
model=self.model_id,
|
342
358
|
messages=messages,
|
343
359
|
system=system_prompt,
|
344
360
|
stream=True,
|
@@ -399,8 +415,8 @@ class AnthropicChatClient(BaseChatClient):
|
|
399
415
|
|
400
416
|
return generator()
|
401
417
|
else:
|
402
|
-
response =
|
403
|
-
model=self.
|
418
|
+
response = raw_client.messages.create(
|
419
|
+
model=self.model_id,
|
404
420
|
messages=messages,
|
405
421
|
system=system_prompt,
|
406
422
|
stream=False,
|
@@ -457,12 +473,19 @@ class AsyncAnthropicChatClient(BaseAsyncChatClient):
|
|
457
473
|
http_client,
|
458
474
|
backend_name,
|
459
475
|
)
|
476
|
+
self.model_id = None
|
460
477
|
|
461
478
|
@cached_property
|
462
479
|
def raw_client(self):
|
463
480
|
if self.random_endpoint:
|
464
481
|
self.random_endpoint = True
|
465
|
-
|
482
|
+
endpoint = random.choice(self.backend_settings.models[self.model].endpoints)
|
483
|
+
self.model_id = None
|
484
|
+
if isinstance(endpoint, dict):
|
485
|
+
self.endpoint_id = endpoint["endpoint_id"]
|
486
|
+
self.model_id = endpoint["model_id"]
|
487
|
+
else:
|
488
|
+
self.endpoint_id = endpoint
|
466
489
|
self.endpoint = settings.get_endpoint(self.endpoint_id)
|
467
490
|
|
468
491
|
if self.endpoint.is_vertex:
|
@@ -587,7 +610,13 @@ class AsyncAnthropicChatClient(BaseAsyncChatClient):
|
|
587
610
|
|
588
611
|
if self.random_endpoint:
|
589
612
|
self.random_endpoint = True
|
590
|
-
|
613
|
+
endpoint = random.choice(self.backend_settings.models[self.model].endpoints)
|
614
|
+
self.model_id = None
|
615
|
+
if isinstance(endpoint, dict):
|
616
|
+
self.endpoint_id = endpoint["endpoint_id"]
|
617
|
+
self.model_id = endpoint["model_id"]
|
618
|
+
else:
|
619
|
+
self.endpoint_id = endpoint
|
591
620
|
self.endpoint = settings.get_endpoint(self.endpoint_id)
|
592
621
|
|
593
622
|
if self.endpoint.api_schema_type == "openai":
|
@@ -628,7 +657,10 @@ class AsyncAnthropicChatClient(BaseAsyncChatClient):
|
|
628
657
|
|
629
658
|
assert isinstance(self.raw_client, AsyncAnthropic | AsyncAnthropicVertex)
|
630
659
|
|
660
|
+
raw_client = self.raw_client # 调用完 self.raw_client 后,self.model_id 会被赋值
|
631
661
|
self.model_setting = self.backend_settings.models[self.model]
|
662
|
+
if self.model_id is None:
|
663
|
+
self.model_id = self.model_setting.id
|
632
664
|
|
633
665
|
if messages[0].get("role") == "system":
|
634
666
|
system_prompt = messages[0]["content"]
|
@@ -641,7 +673,7 @@ class AsyncAnthropicChatClient(BaseAsyncChatClient):
|
|
641
673
|
messages,
|
642
674
|
max_count=self.model_setting.context_length,
|
643
675
|
backend=self.BACKEND_NAME,
|
644
|
-
model=self.
|
676
|
+
model=self.model,
|
645
677
|
)
|
646
678
|
|
647
679
|
messages = format_messages_alternate(messages)
|
@@ -653,7 +685,7 @@ class AsyncAnthropicChatClient(BaseAsyncChatClient):
|
|
653
685
|
|
654
686
|
if max_tokens is None:
|
655
687
|
max_output_tokens = self.model_setting.max_output_tokens
|
656
|
-
token_counts = get_message_token_counts(messages=messages, tools=tools_params, model=self.
|
688
|
+
token_counts = get_message_token_counts(messages=messages, tools=tools_params, model=self.model)
|
657
689
|
if max_output_tokens is not None:
|
658
690
|
max_tokens = self.model_setting.context_length - token_counts
|
659
691
|
max_tokens = min(max(max_tokens, 1), max_output_tokens)
|
@@ -661,8 +693,8 @@ class AsyncAnthropicChatClient(BaseAsyncChatClient):
|
|
661
693
|
max_tokens = self.model_setting.context_length - token_counts
|
662
694
|
|
663
695
|
if self.stream:
|
664
|
-
stream_response = await
|
665
|
-
model=self.
|
696
|
+
stream_response = await raw_client.messages.create(
|
697
|
+
model=self.model_id,
|
666
698
|
messages=messages,
|
667
699
|
system=system_prompt,
|
668
700
|
stream=True,
|
@@ -723,8 +755,8 @@ class AsyncAnthropicChatClient(BaseAsyncChatClient):
|
|
723
755
|
|
724
756
|
return generator()
|
725
757
|
else:
|
726
|
-
response = await
|
727
|
-
model=self.
|
758
|
+
response = await raw_client.messages.create(
|
759
|
+
model=self.model_id,
|
728
760
|
messages=messages,
|
729
761
|
system=system_prompt,
|
730
762
|
stream=False,
|
{vectorvein-0.1.37 → vectorvein-0.1.38}/src/vectorvein/chat_clients/openai_compatible_client.py
RENAMED
@@ -55,12 +55,19 @@ class OpenAICompatibleChatClient(BaseChatClient):
|
|
55
55
|
http_client,
|
56
56
|
backend_name,
|
57
57
|
)
|
58
|
+
self.model_id = None
|
58
59
|
|
59
60
|
@cached_property
|
60
61
|
def raw_client(self) -> OpenAI | AzureOpenAI:
|
61
62
|
if self.random_endpoint:
|
62
63
|
self.random_endpoint = True
|
63
|
-
|
64
|
+
endpoint = random.choice(self.backend_settings.models[self.model].endpoints)
|
65
|
+
self.model_id = None
|
66
|
+
if isinstance(endpoint, dict):
|
67
|
+
self.endpoint_id = endpoint["endpoint_id"]
|
68
|
+
self.model_id = endpoint["model_id"]
|
69
|
+
else:
|
70
|
+
self.endpoint_id = endpoint
|
64
71
|
self.endpoint = settings.get_endpoint(self.endpoint_id)
|
65
72
|
|
66
73
|
if self.endpoint.is_azure:
|
@@ -141,14 +148,17 @@ class OpenAICompatibleChatClient(BaseChatClient):
|
|
141
148
|
if temperature is not None:
|
142
149
|
self.temperature = temperature
|
143
150
|
|
151
|
+
raw_client = self.raw_client # 调用完 self.raw_client 后,self.model_id 会被赋值
|
144
152
|
self.model_setting = self.backend_settings.models[self.model]
|
153
|
+
if self.model_id is None:
|
154
|
+
self.model_id = self.model_setting.id
|
145
155
|
|
146
156
|
if self.context_length_control == ContextLengthControlType.Latest:
|
147
157
|
messages = cutoff_messages(
|
148
158
|
messages,
|
149
159
|
max_count=self.model_setting.context_length,
|
150
160
|
backend=self.BACKEND_NAME,
|
151
|
-
model=self.
|
161
|
+
model=self.model,
|
152
162
|
)
|
153
163
|
|
154
164
|
if tools:
|
@@ -167,7 +177,7 @@ class OpenAICompatibleChatClient(BaseChatClient):
|
|
167
177
|
|
168
178
|
if max_tokens is None:
|
169
179
|
max_output_tokens = self.model_setting.max_output_tokens
|
170
|
-
token_counts = get_message_token_counts(messages=messages, tools=tools, model=self.
|
180
|
+
token_counts = get_message_token_counts(messages=messages, tools=tools, model=self.model)
|
171
181
|
if max_output_tokens is not None:
|
172
182
|
max_tokens = self.model_setting.context_length - token_counts - 64
|
173
183
|
max_tokens = min(max(max_tokens, 1), max_output_tokens)
|
@@ -180,8 +190,8 @@ class OpenAICompatibleChatClient(BaseChatClient):
|
|
180
190
|
self.response_format = {}
|
181
191
|
|
182
192
|
if self.stream:
|
183
|
-
stream_response: Stream[ChatCompletionChunk] =
|
184
|
-
model=self.
|
193
|
+
stream_response: Stream[ChatCompletionChunk] = raw_client.chat.completions.create(
|
194
|
+
model=self.model_id,
|
185
195
|
messages=messages,
|
186
196
|
stream=True,
|
187
197
|
temperature=self.temperature,
|
@@ -221,8 +231,8 @@ class OpenAICompatibleChatClient(BaseChatClient):
|
|
221
231
|
|
222
232
|
return generator()
|
223
233
|
else:
|
224
|
-
response: ChatCompletion =
|
225
|
-
model=self.
|
234
|
+
response: ChatCompletion = raw_client.chat.completions.create(
|
235
|
+
model=self.model_id,
|
226
236
|
messages=messages,
|
227
237
|
stream=False,
|
228
238
|
temperature=self.temperature,
|
@@ -277,12 +287,19 @@ class AsyncOpenAICompatibleChatClient(BaseAsyncChatClient):
|
|
277
287
|
http_client,
|
278
288
|
backend_name,
|
279
289
|
)
|
290
|
+
self.model_id = None
|
280
291
|
|
281
292
|
@cached_property
|
282
293
|
def raw_client(self):
|
283
294
|
if self.random_endpoint:
|
284
295
|
self.random_endpoint = True
|
285
|
-
|
296
|
+
endpoint = random.choice(self.backend_settings.models[self.model].endpoints)
|
297
|
+
self.model_id = None
|
298
|
+
if isinstance(endpoint, dict):
|
299
|
+
self.endpoint_id = endpoint["endpoint_id"]
|
300
|
+
self.model_id = endpoint["model_id"]
|
301
|
+
else:
|
302
|
+
self.endpoint_id = endpoint
|
286
303
|
self.endpoint = settings.get_endpoint(self.endpoint_id)
|
287
304
|
|
288
305
|
if self.endpoint.is_azure:
|
@@ -363,14 +380,17 @@ class AsyncOpenAICompatibleChatClient(BaseAsyncChatClient):
|
|
363
380
|
if temperature is not None:
|
364
381
|
self.temperature = temperature
|
365
382
|
|
383
|
+
raw_client = self.raw_client # 调用完 self.raw_client 后,self.model_id 会被赋值
|
366
384
|
self.model_setting = self.backend_settings.models[self.model]
|
385
|
+
if self.model_id is None:
|
386
|
+
self.model_id = self.model_setting.id
|
367
387
|
|
368
388
|
if self.context_length_control == ContextLengthControlType.Latest:
|
369
389
|
messages = cutoff_messages(
|
370
390
|
messages,
|
371
391
|
max_count=self.model_setting.context_length,
|
372
392
|
backend=self.BACKEND_NAME,
|
373
|
-
model=self.
|
393
|
+
model=self.model,
|
374
394
|
)
|
375
395
|
|
376
396
|
if tools:
|
@@ -394,7 +414,7 @@ class AsyncOpenAICompatibleChatClient(BaseAsyncChatClient):
|
|
394
414
|
|
395
415
|
if max_tokens is None:
|
396
416
|
max_output_tokens = self.model_setting.max_output_tokens
|
397
|
-
token_counts = get_message_token_counts(messages=messages, tools=tools, model=self.
|
417
|
+
token_counts = get_message_token_counts(messages=messages, tools=tools, model=self.model)
|
398
418
|
if max_output_tokens is not None:
|
399
419
|
max_tokens = self.model_setting.context_length - token_counts - 64
|
400
420
|
max_tokens = min(max(max_tokens, 1), max_output_tokens)
|
@@ -402,8 +422,8 @@ class AsyncOpenAICompatibleChatClient(BaseAsyncChatClient):
|
|
402
422
|
max_tokens = self.model_setting.context_length - token_counts - 64
|
403
423
|
|
404
424
|
if self.stream:
|
405
|
-
stream_response: AsyncStream[ChatCompletionChunk] = await
|
406
|
-
model=self.
|
425
|
+
stream_response: AsyncStream[ChatCompletionChunk] = await raw_client.chat.completions.create(
|
426
|
+
model=self.model_id,
|
407
427
|
messages=messages,
|
408
428
|
stream=self.stream,
|
409
429
|
temperature=self.temperature,
|
@@ -443,8 +463,8 @@ class AsyncOpenAICompatibleChatClient(BaseAsyncChatClient):
|
|
443
463
|
|
444
464
|
return generator()
|
445
465
|
else:
|
446
|
-
response: ChatCompletion = await
|
447
|
-
model=self.
|
466
|
+
response: ChatCompletion = await raw_client.chat.completions.create(
|
467
|
+
model=self.model_id,
|
448
468
|
messages=messages,
|
449
469
|
stream=self.stream,
|
450
470
|
temperature=self.temperature,
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# @Author: Bi Ying
|
2
2
|
# @Date: 2024-07-26 23:48:04
|
3
|
-
from typing import List, Dict, Optional, Union, Iterable
|
3
|
+
from typing import List, Dict, Optional, Union, Iterable, TypedDict
|
4
4
|
|
5
5
|
from pydantic import BaseModel, Field
|
6
6
|
|
@@ -18,6 +18,11 @@ from openai.types.chat.chat_completion_tool_choice_option_param import ChatCompl
|
|
18
18
|
from . import defaults as defs
|
19
19
|
|
20
20
|
|
21
|
+
class EndpointOptionDict(TypedDict):
|
22
|
+
endpoint_id: str
|
23
|
+
model_id: str
|
24
|
+
|
25
|
+
|
21
26
|
class EndpointSetting(BaseModel):
|
22
27
|
id: str = Field(..., description="The id of the endpoint.")
|
23
28
|
region: Optional[str] = Field(None, description="The region for the endpoint.")
|
@@ -40,7 +45,9 @@ class EndpointSetting(BaseModel):
|
|
40
45
|
|
41
46
|
class ModelSetting(BaseModel):
|
42
47
|
id: str = Field(..., description="The id of the model.")
|
43
|
-
endpoints: List[str] = Field(
|
48
|
+
endpoints: List[Union[str, EndpointOptionDict]] = Field(
|
49
|
+
default_factory=list, description="Available endpoints for the model."
|
50
|
+
)
|
44
51
|
function_call_available: bool = Field(False, description="Indicates if function call is available.")
|
45
52
|
response_format_available: bool = Field(False, description="Indicates if response format is available.")
|
46
53
|
native_multimodal: bool = Field(False, description="Indicates if the model is a native multimodal model.")
|
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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|