vectorvein 0.1.27__py3-none-any.whl → 0.1.29__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/__init__.py +403 -11
- vectorvein/chat_clients/openai_compatible_client.py +4 -4
- vectorvein/chat_clients/stepfun_client.py +15 -0
- vectorvein/chat_clients/utils.py +25 -0
- vectorvein/settings/__init__.py +3 -1
- vectorvein/types/defaults.py +95 -0
- vectorvein/types/enums.py +3 -0
- {vectorvein-0.1.27.dist-info → vectorvein-0.1.29.dist-info}/METADATA +1 -1
- {vectorvein-0.1.27.dist-info → vectorvein-0.1.29.dist-info}/RECORD +11 -10
- {vectorvein-0.1.27.dist-info → vectorvein-0.1.29.dist-info}/WHEEL +0 -0
- {vectorvein-0.1.27.dist-info → vectorvein-0.1.29.dist-info}/entry_points.txt +0 -0
@@ -1,6 +1,7 @@
|
|
1
1
|
# @Author: Bi Ying
|
2
2
|
# @Date: 2024-07-26 14:48:55
|
3
3
|
import httpx
|
4
|
+
from typing import overload, Literal
|
4
5
|
|
5
6
|
from .base_client import BaseChatClient, BaseAsyncChatClient
|
6
7
|
|
@@ -13,6 +14,7 @@ from .openai_client import OpenAIChatClient, AsyncOpenAIChatClient
|
|
13
14
|
from .zhipuai_client import ZhiPuAIChatClient, AsyncZhiPuAIChatClient
|
14
15
|
from .minimax_client import MiniMaxChatClient, AsyncMiniMaxChatClient
|
15
16
|
from .mistral_client import MistralChatClient, AsyncMistralChatClient
|
17
|
+
from .stepfun_client import StepFunChatClient, AsyncStepFunChatClient
|
16
18
|
from .baichuan_client import BaichuanChatClient, AsyncBaichuanChatClient
|
17
19
|
from .moonshot_client import MoonshotChatClient, AsyncMoonshotChatClient
|
18
20
|
from .deepseek_client import DeepSeekChatClient, AsyncDeepSeekChatClient
|
@@ -22,7 +24,7 @@ from ..types.enums import BackendType, ContextLengthControlType
|
|
22
24
|
from .anthropic_client import AnthropicChatClient, AsyncAnthropicChatClient
|
23
25
|
from .utils import format_messages, get_token_counts, get_message_token_counts, ToolCallContentProcessor
|
24
26
|
|
25
|
-
|
27
|
+
# 后端映射
|
26
28
|
BackendMap = {
|
27
29
|
"sync": {
|
28
30
|
BackendType.Anthropic: AnthropicChatClient,
|
@@ -38,6 +40,7 @@ BackendMap = {
|
|
38
40
|
BackendType.Yi: YiChatClient,
|
39
41
|
BackendType.ZhiPuAI: ZhiPuAIChatClient,
|
40
42
|
BackendType.Baichuan: BaichuanChatClient,
|
43
|
+
BackendType.StepFun: StepFunChatClient,
|
41
44
|
},
|
42
45
|
"async": {
|
43
46
|
BackendType.Anthropic: AsyncAnthropicChatClient,
|
@@ -53,10 +56,207 @@ BackendMap = {
|
|
53
56
|
BackendType.Yi: AsyncYiChatClient,
|
54
57
|
BackendType.ZhiPuAI: AsyncZhiPuAIChatClient,
|
55
58
|
BackendType.Baichuan: AsyncBaichuanChatClient,
|
59
|
+
BackendType.StepFun: AsyncStepFunChatClient,
|
56
60
|
},
|
57
61
|
}
|
58
62
|
|
59
63
|
|
64
|
+
@overload
|
65
|
+
def create_chat_client(
|
66
|
+
backend: Literal[BackendType.Anthropic],
|
67
|
+
model: str | None = None,
|
68
|
+
stream: bool = False,
|
69
|
+
temperature: float = 0.7,
|
70
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
71
|
+
random_endpoint: bool = True,
|
72
|
+
endpoint_id: str = "",
|
73
|
+
http_client: httpx.Client | None = None,
|
74
|
+
**kwargs,
|
75
|
+
) -> AnthropicChatClient: ...
|
76
|
+
|
77
|
+
|
78
|
+
@overload
|
79
|
+
def create_chat_client(
|
80
|
+
backend: Literal[BackendType.DeepSeek],
|
81
|
+
model: str | None = None,
|
82
|
+
stream: bool = False,
|
83
|
+
temperature: float = 0.7,
|
84
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
85
|
+
random_endpoint: bool = True,
|
86
|
+
endpoint_id: str = "",
|
87
|
+
http_client: httpx.Client | None = None,
|
88
|
+
**kwargs,
|
89
|
+
) -> DeepSeekChatClient: ...
|
90
|
+
|
91
|
+
|
92
|
+
@overload
|
93
|
+
def create_chat_client(
|
94
|
+
backend: Literal[BackendType.Gemini],
|
95
|
+
model: str | None = None,
|
96
|
+
stream: bool = False,
|
97
|
+
temperature: float = 0.7,
|
98
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
99
|
+
random_endpoint: bool = True,
|
100
|
+
endpoint_id: str = "",
|
101
|
+
http_client: httpx.Client | None = None,
|
102
|
+
**kwargs,
|
103
|
+
) -> GeminiChatClient: ...
|
104
|
+
|
105
|
+
|
106
|
+
@overload
|
107
|
+
def create_chat_client(
|
108
|
+
backend: Literal[BackendType.Groq],
|
109
|
+
model: str | None = None,
|
110
|
+
stream: bool = False,
|
111
|
+
temperature: float = 0.7,
|
112
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
113
|
+
random_endpoint: bool = True,
|
114
|
+
endpoint_id: str = "",
|
115
|
+
http_client: httpx.Client | None = None,
|
116
|
+
**kwargs,
|
117
|
+
) -> GroqChatClient: ...
|
118
|
+
|
119
|
+
|
120
|
+
@overload
|
121
|
+
def create_chat_client(
|
122
|
+
backend: Literal[BackendType.Local],
|
123
|
+
model: str | None = None,
|
124
|
+
stream: bool = False,
|
125
|
+
temperature: float = 0.7,
|
126
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
127
|
+
random_endpoint: bool = True,
|
128
|
+
endpoint_id: str = "",
|
129
|
+
http_client: httpx.Client | None = None,
|
130
|
+
**kwargs,
|
131
|
+
) -> LocalChatClient: ...
|
132
|
+
|
133
|
+
|
134
|
+
@overload
|
135
|
+
def create_chat_client(
|
136
|
+
backend: Literal[BackendType.MiniMax],
|
137
|
+
model: str | None = None,
|
138
|
+
stream: bool = False,
|
139
|
+
temperature: float = 0.7,
|
140
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
141
|
+
random_endpoint: bool = True,
|
142
|
+
endpoint_id: str = "",
|
143
|
+
http_client: httpx.Client | None = None,
|
144
|
+
**kwargs,
|
145
|
+
) -> MiniMaxChatClient: ...
|
146
|
+
|
147
|
+
|
148
|
+
@overload
|
149
|
+
def create_chat_client(
|
150
|
+
backend: Literal[BackendType.Mistral],
|
151
|
+
model: str | None = None,
|
152
|
+
stream: bool = False,
|
153
|
+
temperature: float = 0.7,
|
154
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
155
|
+
random_endpoint: bool = True,
|
156
|
+
endpoint_id: str = "",
|
157
|
+
http_client: httpx.Client | None = None,
|
158
|
+
**kwargs,
|
159
|
+
) -> MistralChatClient: ...
|
160
|
+
|
161
|
+
|
162
|
+
@overload
|
163
|
+
def create_chat_client(
|
164
|
+
backend: Literal[BackendType.Moonshot],
|
165
|
+
model: str | None = None,
|
166
|
+
stream: bool = False,
|
167
|
+
temperature: float = 0.7,
|
168
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
169
|
+
random_endpoint: bool = True,
|
170
|
+
endpoint_id: str = "",
|
171
|
+
http_client: httpx.Client | None = None,
|
172
|
+
**kwargs,
|
173
|
+
) -> MoonshotChatClient: ...
|
174
|
+
|
175
|
+
|
176
|
+
@overload
|
177
|
+
def create_chat_client(
|
178
|
+
backend: Literal[BackendType.OpenAI],
|
179
|
+
model: str | None = None,
|
180
|
+
stream: bool = False,
|
181
|
+
temperature: float = 0.7,
|
182
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
183
|
+
random_endpoint: bool = True,
|
184
|
+
endpoint_id: str = "",
|
185
|
+
http_client: httpx.Client | None = None,
|
186
|
+
**kwargs,
|
187
|
+
) -> OpenAIChatClient: ...
|
188
|
+
|
189
|
+
|
190
|
+
@overload
|
191
|
+
def create_chat_client(
|
192
|
+
backend: Literal[BackendType.Qwen],
|
193
|
+
model: str | None = None,
|
194
|
+
stream: bool = False,
|
195
|
+
temperature: float = 0.7,
|
196
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
197
|
+
random_endpoint: bool = True,
|
198
|
+
endpoint_id: str = "",
|
199
|
+
http_client: httpx.Client | None = None,
|
200
|
+
**kwargs,
|
201
|
+
) -> QwenChatClient: ...
|
202
|
+
|
203
|
+
|
204
|
+
@overload
|
205
|
+
def create_chat_client(
|
206
|
+
backend: Literal[BackendType.Yi],
|
207
|
+
model: str | None = None,
|
208
|
+
stream: bool = False,
|
209
|
+
temperature: float = 0.7,
|
210
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
211
|
+
random_endpoint: bool = True,
|
212
|
+
endpoint_id: str = "",
|
213
|
+
http_client: httpx.Client | None = None,
|
214
|
+
**kwargs,
|
215
|
+
) -> YiChatClient: ...
|
216
|
+
|
217
|
+
|
218
|
+
@overload
|
219
|
+
def create_chat_client(
|
220
|
+
backend: Literal[BackendType.ZhiPuAI],
|
221
|
+
model: str | None = None,
|
222
|
+
stream: bool = False,
|
223
|
+
temperature: float = 0.7,
|
224
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
225
|
+
random_endpoint: bool = True,
|
226
|
+
endpoint_id: str = "",
|
227
|
+
http_client: httpx.Client | None = None,
|
228
|
+
**kwargs,
|
229
|
+
) -> ZhiPuAIChatClient: ...
|
230
|
+
|
231
|
+
|
232
|
+
@overload
|
233
|
+
def create_chat_client(
|
234
|
+
backend: Literal[BackendType.Baichuan],
|
235
|
+
model: str | None = None,
|
236
|
+
stream: bool = False,
|
237
|
+
temperature: float = 0.7,
|
238
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
239
|
+
random_endpoint: bool = True,
|
240
|
+
endpoint_id: str = "",
|
241
|
+
http_client: httpx.Client | None = None,
|
242
|
+
**kwargs,
|
243
|
+
) -> BaichuanChatClient: ...
|
244
|
+
|
245
|
+
|
246
|
+
@overload
|
247
|
+
def create_chat_client(
|
248
|
+
backend: Literal[BackendType.StepFun],
|
249
|
+
model: str | None = None,
|
250
|
+
stream: bool = False,
|
251
|
+
temperature: float = 0.7,
|
252
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
253
|
+
random_endpoint: bool = True,
|
254
|
+
endpoint_id: str = "",
|
255
|
+
http_client: httpx.Client | None = None,
|
256
|
+
**kwargs,
|
257
|
+
) -> StepFunChatClient: ...
|
258
|
+
|
259
|
+
|
60
260
|
def create_chat_client(
|
61
261
|
backend: BackendType,
|
62
262
|
model: str | None = None,
|
@@ -68,15 +268,13 @@ def create_chat_client(
|
|
68
268
|
http_client: httpx.Client | None = None,
|
69
269
|
**kwargs,
|
70
270
|
) -> BaseChatClient:
|
71
|
-
if backend
|
271
|
+
if backend not in BackendMap["sync"]:
|
72
272
|
raise ValueError(f"Unsupported backend: {backend}")
|
73
|
-
else:
|
74
|
-
backend_key = backend.lower()
|
75
273
|
|
76
|
-
ClientClass = BackendMap["sync"][
|
274
|
+
ClientClass = BackendMap["sync"][backend]
|
77
275
|
if model is None:
|
78
276
|
model = ClientClass.DEFAULT_MODEL
|
79
|
-
return
|
277
|
+
return ClientClass(
|
80
278
|
model=model,
|
81
279
|
stream=stream,
|
82
280
|
temperature=temperature,
|
@@ -88,6 +286,202 @@ def create_chat_client(
|
|
88
286
|
)
|
89
287
|
|
90
288
|
|
289
|
+
@overload
|
290
|
+
def create_async_chat_client(
|
291
|
+
backend: Literal[BackendType.Anthropic],
|
292
|
+
model: str | None = None,
|
293
|
+
stream: bool = False,
|
294
|
+
temperature: float = 0.7,
|
295
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
296
|
+
random_endpoint: bool = True,
|
297
|
+
endpoint_id: str = "",
|
298
|
+
http_client: httpx.AsyncClient | None = None,
|
299
|
+
**kwargs,
|
300
|
+
) -> AsyncAnthropicChatClient: ...
|
301
|
+
|
302
|
+
|
303
|
+
@overload
|
304
|
+
def create_async_chat_client(
|
305
|
+
backend: Literal[BackendType.DeepSeek],
|
306
|
+
model: str | None = None,
|
307
|
+
stream: bool = False,
|
308
|
+
temperature: float = 0.7,
|
309
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
310
|
+
random_endpoint: bool = True,
|
311
|
+
endpoint_id: str = "",
|
312
|
+
http_client: httpx.AsyncClient | None = None,
|
313
|
+
**kwargs,
|
314
|
+
) -> AsyncDeepSeekChatClient: ...
|
315
|
+
|
316
|
+
|
317
|
+
@overload
|
318
|
+
def create_async_chat_client(
|
319
|
+
backend: Literal[BackendType.Gemini],
|
320
|
+
model: str | None = None,
|
321
|
+
stream: bool = False,
|
322
|
+
temperature: float = 0.7,
|
323
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
324
|
+
random_endpoint: bool = True,
|
325
|
+
endpoint_id: str = "",
|
326
|
+
http_client: httpx.AsyncClient | None = None,
|
327
|
+
**kwargs,
|
328
|
+
) -> AsyncGeminiChatClient: ...
|
329
|
+
|
330
|
+
|
331
|
+
@overload
|
332
|
+
def create_async_chat_client(
|
333
|
+
backend: Literal[BackendType.Groq],
|
334
|
+
model: str | None = None,
|
335
|
+
stream: bool = False,
|
336
|
+
temperature: float = 0.7,
|
337
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
338
|
+
random_endpoint: bool = True,
|
339
|
+
endpoint_id: str = "",
|
340
|
+
http_client: httpx.AsyncClient | None = None,
|
341
|
+
**kwargs,
|
342
|
+
) -> AsyncGroqChatClient: ...
|
343
|
+
|
344
|
+
|
345
|
+
@overload
|
346
|
+
def create_async_chat_client(
|
347
|
+
backend: Literal[BackendType.Local],
|
348
|
+
model: str | None = None,
|
349
|
+
stream: bool = False,
|
350
|
+
temperature: float = 0.7,
|
351
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
352
|
+
random_endpoint: bool = True,
|
353
|
+
endpoint_id: str = "",
|
354
|
+
http_client: httpx.AsyncClient | None = None,
|
355
|
+
**kwargs,
|
356
|
+
) -> AsyncLocalChatClient: ...
|
357
|
+
|
358
|
+
|
359
|
+
@overload
|
360
|
+
def create_async_chat_client(
|
361
|
+
backend: Literal[BackendType.MiniMax],
|
362
|
+
model: str | None = None,
|
363
|
+
stream: bool = False,
|
364
|
+
temperature: float = 0.7,
|
365
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
366
|
+
random_endpoint: bool = True,
|
367
|
+
endpoint_id: str = "",
|
368
|
+
http_client: httpx.AsyncClient | None = None,
|
369
|
+
**kwargs,
|
370
|
+
) -> AsyncMiniMaxChatClient: ...
|
371
|
+
|
372
|
+
|
373
|
+
@overload
|
374
|
+
def create_async_chat_client(
|
375
|
+
backend: Literal[BackendType.Mistral],
|
376
|
+
model: str | None = None,
|
377
|
+
stream: bool = False,
|
378
|
+
temperature: float = 0.7,
|
379
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
380
|
+
random_endpoint: bool = True,
|
381
|
+
endpoint_id: str = "",
|
382
|
+
http_client: httpx.AsyncClient | None = None,
|
383
|
+
**kwargs,
|
384
|
+
) -> AsyncMistralChatClient: ...
|
385
|
+
|
386
|
+
|
387
|
+
@overload
|
388
|
+
def create_async_chat_client(
|
389
|
+
backend: Literal[BackendType.Moonshot],
|
390
|
+
model: str | None = None,
|
391
|
+
stream: bool = False,
|
392
|
+
temperature: float = 0.7,
|
393
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
394
|
+
random_endpoint: bool = True,
|
395
|
+
endpoint_id: str = "",
|
396
|
+
http_client: httpx.AsyncClient | None = None,
|
397
|
+
**kwargs,
|
398
|
+
) -> AsyncMoonshotChatClient: ...
|
399
|
+
|
400
|
+
|
401
|
+
@overload
|
402
|
+
def create_async_chat_client(
|
403
|
+
backend: Literal[BackendType.OpenAI],
|
404
|
+
model: str | None = None,
|
405
|
+
stream: bool = False,
|
406
|
+
temperature: float = 0.7,
|
407
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
408
|
+
random_endpoint: bool = True,
|
409
|
+
endpoint_id: str = "",
|
410
|
+
http_client: httpx.AsyncClient | None = None,
|
411
|
+
**kwargs,
|
412
|
+
) -> AsyncOpenAIChatClient: ...
|
413
|
+
|
414
|
+
|
415
|
+
@overload
|
416
|
+
def create_async_chat_client(
|
417
|
+
backend: Literal[BackendType.Qwen],
|
418
|
+
model: str | None = None,
|
419
|
+
stream: bool = False,
|
420
|
+
temperature: float = 0.7,
|
421
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
422
|
+
random_endpoint: bool = True,
|
423
|
+
endpoint_id: str = "",
|
424
|
+
http_client: httpx.AsyncClient | None = None,
|
425
|
+
**kwargs,
|
426
|
+
) -> AsyncQwenChatClient: ...
|
427
|
+
|
428
|
+
|
429
|
+
@overload
|
430
|
+
def create_async_chat_client(
|
431
|
+
backend: Literal[BackendType.Yi],
|
432
|
+
model: str | None = None,
|
433
|
+
stream: bool = False,
|
434
|
+
temperature: float = 0.7,
|
435
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
436
|
+
random_endpoint: bool = True,
|
437
|
+
endpoint_id: str = "",
|
438
|
+
http_client: httpx.AsyncClient | None = None,
|
439
|
+
**kwargs,
|
440
|
+
) -> AsyncYiChatClient: ...
|
441
|
+
|
442
|
+
|
443
|
+
@overload
|
444
|
+
def create_async_chat_client(
|
445
|
+
backend: Literal[BackendType.ZhiPuAI],
|
446
|
+
model: str | None = None,
|
447
|
+
stream: bool = False,
|
448
|
+
temperature: float = 0.7,
|
449
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
450
|
+
random_endpoint: bool = True,
|
451
|
+
endpoint_id: str = "",
|
452
|
+
http_client: httpx.AsyncClient | None = None,
|
453
|
+
**kwargs,
|
454
|
+
) -> AsyncZhiPuAIChatClient: ...
|
455
|
+
|
456
|
+
|
457
|
+
@overload
|
458
|
+
def create_async_chat_client(
|
459
|
+
backend: Literal[BackendType.Baichuan],
|
460
|
+
model: str | None = None,
|
461
|
+
stream: bool = False,
|
462
|
+
temperature: float = 0.7,
|
463
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
464
|
+
random_endpoint: bool = True,
|
465
|
+
endpoint_id: str = "",
|
466
|
+
http_client: httpx.AsyncClient | None = None,
|
467
|
+
**kwargs,
|
468
|
+
) -> AsyncBaichuanChatClient: ...
|
469
|
+
|
470
|
+
|
471
|
+
@overload
|
472
|
+
def create_async_chat_client(
|
473
|
+
backend: Literal[BackendType.StepFun],
|
474
|
+
model: str | None = None,
|
475
|
+
stream: bool = False,
|
476
|
+
temperature: float = 0.7,
|
477
|
+
context_length_control: ContextLengthControlType = defs.CONTEXT_LENGTH_CONTROL,
|
478
|
+
random_endpoint: bool = True,
|
479
|
+
endpoint_id: str = "",
|
480
|
+
http_client: httpx.AsyncClient | None = None,
|
481
|
+
**kwargs,
|
482
|
+
) -> AsyncStepFunChatClient: ...
|
483
|
+
|
484
|
+
|
91
485
|
def create_async_chat_client(
|
92
486
|
backend: BackendType,
|
93
487
|
model: str | None = None,
|
@@ -99,15 +493,13 @@ def create_async_chat_client(
|
|
99
493
|
http_client: httpx.AsyncClient | None = None,
|
100
494
|
**kwargs,
|
101
495
|
) -> BaseAsyncChatClient:
|
102
|
-
if backend
|
496
|
+
if backend not in BackendMap["async"]:
|
103
497
|
raise ValueError(f"Unsupported backend: {backend}")
|
104
|
-
else:
|
105
|
-
backend_key = backend.lower()
|
106
498
|
|
107
|
-
ClientClass = BackendMap["async"][
|
499
|
+
ClientClass = BackendMap["async"][backend]
|
108
500
|
if model is None:
|
109
501
|
model = ClientClass.DEFAULT_MODEL
|
110
|
-
return
|
502
|
+
return ClientClass(
|
111
503
|
model=model,
|
112
504
|
stream=stream,
|
113
505
|
temperature=temperature,
|
@@ -169,10 +169,10 @@ class OpenAICompatibleChatClient(BaseChatClient):
|
|
169
169
|
max_output_tokens = self.model_setting.max_output_tokens
|
170
170
|
token_counts = get_message_token_counts(messages=messages, tools=tools, model=self.model_setting.id)
|
171
171
|
if max_output_tokens is not None:
|
172
|
-
max_tokens = self.model_setting.context_length - token_counts
|
172
|
+
max_tokens = self.model_setting.context_length - token_counts - 64
|
173
173
|
max_tokens = min(max(max_tokens, 1), max_output_tokens)
|
174
174
|
else:
|
175
|
-
max_tokens = self.model_setting.context_length - token_counts
|
175
|
+
max_tokens = self.model_setting.context_length - token_counts - 64
|
176
176
|
|
177
177
|
if response_format and self.model_setting.response_format_available:
|
178
178
|
self.response_format = {"response_format": response_format}
|
@@ -396,10 +396,10 @@ class AsyncOpenAICompatibleChatClient(BaseAsyncChatClient):
|
|
396
396
|
max_output_tokens = self.model_setting.max_output_tokens
|
397
397
|
token_counts = get_message_token_counts(messages=messages, tools=tools, model=self.model_setting.id)
|
398
398
|
if max_output_tokens is not None:
|
399
|
-
max_tokens = self.model_setting.context_length - token_counts
|
399
|
+
max_tokens = self.model_setting.context_length - token_counts - 64
|
400
400
|
max_tokens = min(max(max_tokens, 1), max_output_tokens)
|
401
401
|
else:
|
402
|
-
max_tokens = self.model_setting.context_length - token_counts
|
402
|
+
max_tokens = self.model_setting.context_length - token_counts - 64
|
403
403
|
|
404
404
|
if self.stream:
|
405
405
|
stream_response: AsyncStream[ChatCompletionChunk] = await self.raw_client.chat.completions.create(
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# @Author: Bi Ying
|
2
|
+
# @Date: 2024-07-26 14:48:55
|
3
|
+
from ..types.enums import BackendType
|
4
|
+
from ..types.defaults import STEPFUN_DEFAULT_MODEL
|
5
|
+
from .openai_compatible_client import OpenAICompatibleChatClient, AsyncOpenAICompatibleChatClient
|
6
|
+
|
7
|
+
|
8
|
+
class StepFunChatClient(OpenAICompatibleChatClient):
|
9
|
+
DEFAULT_MODEL = STEPFUN_DEFAULT_MODEL
|
10
|
+
BACKEND_NAME = BackendType.StepFun
|
11
|
+
|
12
|
+
|
13
|
+
class AsyncStepFunChatClient(AsyncOpenAICompatibleChatClient):
|
14
|
+
DEFAULT_MODEL = STEPFUN_DEFAULT_MODEL
|
15
|
+
BACKEND_NAME = BackendType.StepFun
|
vectorvein/chat_clients/utils.py
CHANGED
@@ -195,6 +195,31 @@ def get_token_counts(text: str | dict, model: str = "") -> int:
|
|
195
195
|
return len(deepseek_tokenizer.encode(text))
|
196
196
|
elif model.startswith("qwen"):
|
197
197
|
return len(qwen_tokenizer.encode(text))
|
198
|
+
elif model.startswith("stepfun"):
|
199
|
+
model_setting = settings.moonshot.models[model]
|
200
|
+
if len(model_setting.endpoints) == 0:
|
201
|
+
return len(chatgpt_encoding.encode(text))
|
202
|
+
endpoint_id = model_setting.endpoints[0]
|
203
|
+
endpoint = settings.get_endpoint(endpoint_id)
|
204
|
+
tokenize_url = "https://api.stepfun.com/v1/token/count"
|
205
|
+
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {endpoint.api_key}"}
|
206
|
+
request_body = {
|
207
|
+
"model": model,
|
208
|
+
"messages": [
|
209
|
+
{"role": "user", "content": text},
|
210
|
+
],
|
211
|
+
}
|
212
|
+
_, response = (
|
213
|
+
Retry(httpx.post)
|
214
|
+
.args(url=tokenize_url, headers=headers, json=request_body, timeout=None)
|
215
|
+
.retry_times(5)
|
216
|
+
.sleep_time(10)
|
217
|
+
.run()
|
218
|
+
)
|
219
|
+
if response is None:
|
220
|
+
return 1000
|
221
|
+
result = response.json()
|
222
|
+
return result["data"]["total_tokens"]
|
198
223
|
else:
|
199
224
|
return len(chatgpt_encoding.encode(text))
|
200
225
|
|
vectorvein/settings/__init__.py
CHANGED
@@ -27,6 +27,7 @@ class Settings(BaseModel):
|
|
27
27
|
yi: BackendSettings = Field(default_factory=BackendSettings, description="Yi models settings.")
|
28
28
|
zhipuai: BackendSettings = Field(default_factory=BackendSettings, description="Zhipuai models settings.")
|
29
29
|
baichuan: BackendSettings = Field(default_factory=BackendSettings, description="Baichuan models settings.")
|
30
|
+
stepfun: BackendSettings = Field(default_factory=BackendSettings, description="StepFun models settings.")
|
30
31
|
|
31
32
|
def __init__(self, **data):
|
32
33
|
model_types = {
|
@@ -43,6 +44,7 @@ class Settings(BaseModel):
|
|
43
44
|
"yi": defs.YI_MODELS,
|
44
45
|
"zhipuai": defs.ZHIPUAI_MODELS,
|
45
46
|
"baichuan": defs.BAICHUAN_MODELS,
|
47
|
+
"stepfun": defs.STEPFUN_MODELS,
|
46
48
|
}
|
47
49
|
|
48
50
|
for model_type, default_models in model_types.items():
|
@@ -62,7 +64,7 @@ class Settings(BaseModel):
|
|
62
64
|
for endpoint in self.endpoints:
|
63
65
|
if endpoint.id == endpoint_id:
|
64
66
|
return endpoint
|
65
|
-
|
67
|
+
raise ValueError(f"Endpoint {endpoint_id} not found.")
|
66
68
|
|
67
69
|
def get_backend(self, backend: BackendType) -> BackendSettings:
|
68
70
|
return getattr(self, backend.value.lower())
|
vectorvein/types/defaults.py
CHANGED
@@ -588,3 +588,98 @@ GEMINI_MODELS = {
|
|
588
588
|
"native_multimodal": True,
|
589
589
|
},
|
590
590
|
}
|
591
|
+
|
592
|
+
# 百度文心一言 ERNIE 模型
|
593
|
+
ERNIE_DEFAULT_MODEL = "ernie-lite"
|
594
|
+
ERNIE_MODELS = {
|
595
|
+
"ernie-lite": {
|
596
|
+
"id": "ernie-lite",
|
597
|
+
"context_length": 6144,
|
598
|
+
"max_output_tokens": 2048,
|
599
|
+
"function_call_available": False,
|
600
|
+
"response_format_available": False,
|
601
|
+
},
|
602
|
+
"ernie-speed": {
|
603
|
+
"id": "ernie-speed",
|
604
|
+
"context_length": 126976,
|
605
|
+
"max_output_tokens": 4096,
|
606
|
+
"function_call_available": False,
|
607
|
+
"response_format_available": False,
|
608
|
+
},
|
609
|
+
"ernie-speed-pro-128k": {
|
610
|
+
"id": "ernie-speed-pro-128k",
|
611
|
+
"context_length": 126976,
|
612
|
+
"max_output_tokens": 4096,
|
613
|
+
"function_call_available": False,
|
614
|
+
"response_format_available": False,
|
615
|
+
},
|
616
|
+
"ernie-4.0-8k-latest": {
|
617
|
+
"id": "ernie-4.0-8k-latest",
|
618
|
+
"context_length": 5120,
|
619
|
+
"max_output_tokens": 2048,
|
620
|
+
"function_call_available": False,
|
621
|
+
"response_format_available": True,
|
622
|
+
},
|
623
|
+
"ernie-4.0-turbo-8k": {
|
624
|
+
"id": "ernie-4.0-turbo-8k",
|
625
|
+
"context_length": 5120,
|
626
|
+
"max_output_tokens": 2048,
|
627
|
+
"function_call_available": False,
|
628
|
+
"response_format_available": True,
|
629
|
+
},
|
630
|
+
}
|
631
|
+
|
632
|
+
|
633
|
+
STEPFUN_DEFAULT_MODEL = "step-1-8k"
|
634
|
+
STEPFUN_MODELS = {
|
635
|
+
"step-1-8k": {
|
636
|
+
"id": "step-1-8k",
|
637
|
+
"context_length": 8192,
|
638
|
+
"function_call_available": True,
|
639
|
+
"response_format_available": True,
|
640
|
+
},
|
641
|
+
"step-1-32k": {
|
642
|
+
"id": "step-1-32k",
|
643
|
+
"context_length": 32000,
|
644
|
+
"function_call_available": True,
|
645
|
+
"response_format_available": True,
|
646
|
+
},
|
647
|
+
"step-1-128k": {
|
648
|
+
"id": "step-1-128k",
|
649
|
+
"context_length": 128000,
|
650
|
+
"function_call_available": True,
|
651
|
+
"response_format_available": True,
|
652
|
+
},
|
653
|
+
"step-1-256k": {
|
654
|
+
"id": "step-1-256k",
|
655
|
+
"context_length": 256000,
|
656
|
+
"function_call_available": True,
|
657
|
+
"response_format_available": True,
|
658
|
+
},
|
659
|
+
"step-2-16k": {
|
660
|
+
"id": "step-2-16k",
|
661
|
+
"context_length": 16384,
|
662
|
+
"function_call_available": True,
|
663
|
+
"response_format_available": True,
|
664
|
+
},
|
665
|
+
"step-1-flash": {
|
666
|
+
"id": "step-1-flash",
|
667
|
+
"context_length": 8192,
|
668
|
+
"function_call_available": True,
|
669
|
+
"response_format_available": True,
|
670
|
+
},
|
671
|
+
"step-1v-8k": {
|
672
|
+
"id": "step-1v-8k",
|
673
|
+
"context_length": 8192,
|
674
|
+
"function_call_available": False,
|
675
|
+
"response_format_available": False,
|
676
|
+
"native_multimodal": True,
|
677
|
+
},
|
678
|
+
"step-1v-32k": {
|
679
|
+
"id": "step-1v-32k",
|
680
|
+
"context_length": 32768,
|
681
|
+
"function_call_available": False,
|
682
|
+
"response_format_available": False,
|
683
|
+
"native_multimodal": True,
|
684
|
+
},
|
685
|
+
}
|
vectorvein/types/enums.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
vectorvein-0.1.
|
2
|
-
vectorvein-0.1.
|
3
|
-
vectorvein-0.1.
|
1
|
+
vectorvein-0.1.29.dist-info/METADATA,sha256=Azvf3VhV-V6iJzO4lsm_85TFVZfvQirxRiSXQSUXVeY,502
|
2
|
+
vectorvein-0.1.29.dist-info/WHEEL,sha256=Vza3XR51HW1KmFP0iIMUVYIvz0uQuKJpIXKYOBGQyFQ,90
|
3
|
+
vectorvein-0.1.29.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
|
4
4
|
vectorvein/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
-
vectorvein/chat_clients/__init__.py,sha256=
|
5
|
+
vectorvein/chat_clients/__init__.py,sha256=4AfQql41X0705EstkbV783vT6N4bBrJhZ5DgMwRrt5s,16018
|
6
6
|
vectorvein/chat_clients/anthropic_client.py,sha256=h82GxBi7h22B7leBuPofwBstxH_c12tEgGjpnKg6UDc,25007
|
7
7
|
vectorvein/chat_clients/baichuan_client.py,sha256=CVMvpgjdrZGv0BWnTOBD-f2ufZ3wq3496wqukumsAr4,526
|
8
8
|
vectorvein/chat_clients/base_client.py,sha256=wxh7WkzFG4cD4I4t4e6RGe1KiFZc8Z5llh2iVblXEZE,8415
|
@@ -14,16 +14,17 @@ vectorvein/chat_clients/minimax_client.py,sha256=ljnT9QtVUiySSQSECEv9g2vRfv88K2p
|
|
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=gfCTXji8pgFUiultiNDKcmPIGu7lFfQ9VmA8o2_Mm6c,18823
|
18
18
|
vectorvein/chat_clients/qwen_client.py,sha256=-ryh-m9PgsO0fc4ulcCmPTy1155J8YUy15uPoJQOHA0,513
|
19
|
-
vectorvein/chat_clients/
|
19
|
+
vectorvein/chat_clients/stepfun_client.py,sha256=zsD2W5ahmR4DD9cqQTXmJr3txrGuvxbRWhFlRdwNijI,519
|
20
|
+
vectorvein/chat_clients/utils.py,sha256=zwuXY7Bs14xXFdhBlnTmCTOezMeYr2cf5DeF0_5_WNE,24016
|
20
21
|
vectorvein/chat_clients/yi_client.py,sha256=RNf4CRuPJfixrwLZ3-DEc3t25QDe1mvZeb9sku2f8Bc,484
|
21
22
|
vectorvein/chat_clients/zhipuai_client.py,sha256=Ys5DSeLCuedaDXr3PfG1EW2zKXopt-awO2IylWSwY0s,519
|
22
|
-
vectorvein/settings/__init__.py,sha256=
|
23
|
-
vectorvein/types/defaults.py,sha256=
|
24
|
-
vectorvein/types/enums.py,sha256=
|
23
|
+
vectorvein/settings/__init__.py,sha256=0L-2WicBq9ctaJRoSwx8ZhVtX4slS5tHrIlSGf-tJxg,3564
|
24
|
+
vectorvein/types/defaults.py,sha256=gq0R_9QMsxJXE8cHrJPog9U81-XDWGZ4mbeQNLS1kOU,20609
|
25
|
+
vectorvein/types/enums.py,sha256=x_S0IJiEWijOAEiMNdiGDGEWGtmt7TwMriJVDqrDmTo,1637
|
25
26
|
vectorvein/types/exception.py,sha256=gnW4GnJ76jND6UGnodk9xmqkcbeS7Cz2rvncA2HpD5E,69
|
26
27
|
vectorvein/types/llm_parameters.py,sha256=N6RQ8tqO1RCywMFRWPooffeAEPd9x3JW6Bl4UgQtF5I,4379
|
27
28
|
vectorvein/utilities/media_processing.py,sha256=BujciRmw1GMmc3ELRvafL8STcy6r5b2rVnh27-uA7so,2256
|
28
29
|
vectorvein/utilities/retry.py,sha256=9ePuJdeUUGx-qMWfaFxmlOvG_lQPwCQ4UB1z3Edlo34,993
|
29
|
-
vectorvein-0.1.
|
30
|
+
vectorvein-0.1.29.dist-info/RECORD,,
|
File without changes
|
File without changes
|