vectorvein 0.2.9__tar.gz → 0.2.11__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.2.9 → vectorvein-0.2.11}/PKG-INFO +1 -1
- {vectorvein-0.2.9 → vectorvein-0.2.11}/pyproject.toml +1 -1
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/chat_clients/__init__.py +42 -1
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/chat_clients/anthropic_client.py +12 -3
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/chat_clients/base_client.py +79 -39
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/chat_clients/openai_compatible_client.py +21 -1
- vectorvein-0.2.11/src/vectorvein/types/__init__.py +129 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/types/llm_parameters.py +1 -9
- vectorvein-0.2.11/src/vectorvein/types/settings.py +105 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/README.md +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/__init__.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/api/__init__.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/api/client.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/api/exceptions.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/api/models.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/chat_clients/baichuan_client.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/chat_clients/deepseek_client.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/chat_clients/gemini_client.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/chat_clients/groq_client.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/chat_clients/local_client.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/chat_clients/minimax_client.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/chat_clients/mistral_client.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/chat_clients/moonshot_client.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/chat_clients/openai_client.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/chat_clients/py.typed +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/chat_clients/qwen_client.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/chat_clients/stepfun_client.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/chat_clients/utils.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/chat_clients/xai_client.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/chat_clients/yi_client.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/chat_clients/zhipuai_client.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/py.typed +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/server/token_server.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/settings/__init__.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/settings/py.typed +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/types/defaults.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/types/enums.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/types/exception.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/types/py.typed +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/utilities/media_processing.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/utilities/rate_limiter.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/utilities/retry.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/workflow/graph/edge.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/workflow/graph/node.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/workflow/graph/port.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/workflow/graph/workflow.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/workflow/nodes/__init__.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/workflow/nodes/audio_generation.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/workflow/nodes/control_flows.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/workflow/nodes/file_processing.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/workflow/nodes/image_generation.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/workflow/nodes/llms.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/workflow/nodes/media_editing.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/workflow/nodes/media_processing.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/workflow/nodes/output.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/workflow/nodes/relational_db.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/workflow/nodes/text_processing.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/workflow/nodes/tools.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/workflow/nodes/triggers.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/workflow/nodes/vector_db.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/workflow/nodes/video_generation.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/workflow/nodes/web_crawlers.py +0 -0
- {vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/workflow/utils/json_to_code.py +0 -0
@@ -1,7 +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
|
+
from typing import overload, Literal, TYPE_CHECKING
|
5
5
|
|
6
6
|
from .base_client import BaseChatClient, BaseAsyncChatClient
|
7
7
|
|
@@ -26,6 +26,11 @@ from ..types.enums import BackendType, ContextLengthControlType
|
|
26
26
|
from .anthropic_client import AnthropicChatClient, AsyncAnthropicChatClient
|
27
27
|
from .utils import format_messages, get_token_counts, get_message_token_counts, ToolCallContentProcessor
|
28
28
|
|
29
|
+
|
30
|
+
if TYPE_CHECKING:
|
31
|
+
from ..settings import Settings
|
32
|
+
from ..types.settings import SettingsDict
|
33
|
+
|
29
34
|
# 后端映射
|
30
35
|
BackendMap = {
|
31
36
|
"sync": {
|
@@ -75,6 +80,7 @@ def create_chat_client(
|
|
75
80
|
random_endpoint: bool = True,
|
76
81
|
endpoint_id: str = "",
|
77
82
|
http_client: httpx.Client | None = None,
|
83
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
78
84
|
**kwargs,
|
79
85
|
) -> AnthropicChatClient: ...
|
80
86
|
|
@@ -89,6 +95,7 @@ def create_chat_client(
|
|
89
95
|
random_endpoint: bool = True,
|
90
96
|
endpoint_id: str = "",
|
91
97
|
http_client: httpx.Client | None = None,
|
98
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
92
99
|
**kwargs,
|
93
100
|
) -> DeepSeekChatClient: ...
|
94
101
|
|
@@ -103,6 +110,7 @@ def create_chat_client(
|
|
103
110
|
random_endpoint: bool = True,
|
104
111
|
endpoint_id: str = "",
|
105
112
|
http_client: httpx.Client | None = None,
|
113
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
106
114
|
**kwargs,
|
107
115
|
) -> GeminiChatClient: ...
|
108
116
|
|
@@ -117,6 +125,7 @@ def create_chat_client(
|
|
117
125
|
random_endpoint: bool = True,
|
118
126
|
endpoint_id: str = "",
|
119
127
|
http_client: httpx.Client | None = None,
|
128
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
120
129
|
**kwargs,
|
121
130
|
) -> GroqChatClient: ...
|
122
131
|
|
@@ -131,6 +140,7 @@ def create_chat_client(
|
|
131
140
|
random_endpoint: bool = True,
|
132
141
|
endpoint_id: str = "",
|
133
142
|
http_client: httpx.Client | None = None,
|
143
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
134
144
|
**kwargs,
|
135
145
|
) -> LocalChatClient: ...
|
136
146
|
|
@@ -145,6 +155,7 @@ def create_chat_client(
|
|
145
155
|
random_endpoint: bool = True,
|
146
156
|
endpoint_id: str = "",
|
147
157
|
http_client: httpx.Client | None = None,
|
158
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
148
159
|
**kwargs,
|
149
160
|
) -> MiniMaxChatClient: ...
|
150
161
|
|
@@ -159,6 +170,7 @@ def create_chat_client(
|
|
159
170
|
random_endpoint: bool = True,
|
160
171
|
endpoint_id: str = "",
|
161
172
|
http_client: httpx.Client | None = None,
|
173
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
162
174
|
**kwargs,
|
163
175
|
) -> MistralChatClient: ...
|
164
176
|
|
@@ -173,6 +185,7 @@ def create_chat_client(
|
|
173
185
|
random_endpoint: bool = True,
|
174
186
|
endpoint_id: str = "",
|
175
187
|
http_client: httpx.Client | None = None,
|
188
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
176
189
|
**kwargs,
|
177
190
|
) -> MoonshotChatClient: ...
|
178
191
|
|
@@ -187,6 +200,7 @@ def create_chat_client(
|
|
187
200
|
random_endpoint: bool = True,
|
188
201
|
endpoint_id: str = "",
|
189
202
|
http_client: httpx.Client | None = None,
|
203
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
190
204
|
**kwargs,
|
191
205
|
) -> OpenAIChatClient: ...
|
192
206
|
|
@@ -201,6 +215,7 @@ def create_chat_client(
|
|
201
215
|
random_endpoint: bool = True,
|
202
216
|
endpoint_id: str = "",
|
203
217
|
http_client: httpx.Client | None = None,
|
218
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
204
219
|
**kwargs,
|
205
220
|
) -> QwenChatClient: ...
|
206
221
|
|
@@ -215,6 +230,7 @@ def create_chat_client(
|
|
215
230
|
random_endpoint: bool = True,
|
216
231
|
endpoint_id: str = "",
|
217
232
|
http_client: httpx.Client | None = None,
|
233
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
218
234
|
**kwargs,
|
219
235
|
) -> YiChatClient: ...
|
220
236
|
|
@@ -229,6 +245,7 @@ def create_chat_client(
|
|
229
245
|
random_endpoint: bool = True,
|
230
246
|
endpoint_id: str = "",
|
231
247
|
http_client: httpx.Client | None = None,
|
248
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
232
249
|
**kwargs,
|
233
250
|
) -> ZhiPuAIChatClient: ...
|
234
251
|
|
@@ -243,6 +260,7 @@ def create_chat_client(
|
|
243
260
|
random_endpoint: bool = True,
|
244
261
|
endpoint_id: str = "",
|
245
262
|
http_client: httpx.Client | None = None,
|
263
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
246
264
|
**kwargs,
|
247
265
|
) -> BaichuanChatClient: ...
|
248
266
|
|
@@ -257,6 +275,7 @@ def create_chat_client(
|
|
257
275
|
random_endpoint: bool = True,
|
258
276
|
endpoint_id: str = "",
|
259
277
|
http_client: httpx.Client | None = None,
|
278
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
260
279
|
**kwargs,
|
261
280
|
) -> StepFunChatClient: ...
|
262
281
|
|
@@ -271,6 +290,7 @@ def create_chat_client(
|
|
271
290
|
random_endpoint: bool = True,
|
272
291
|
endpoint_id: str = "",
|
273
292
|
http_client: httpx.Client | None = None,
|
293
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
274
294
|
**kwargs,
|
275
295
|
) -> XAIChatClient: ...
|
276
296
|
|
@@ -285,6 +305,7 @@ def create_chat_client(
|
|
285
305
|
random_endpoint: bool = True,
|
286
306
|
endpoint_id: str = "",
|
287
307
|
http_client: httpx.Client | None = None,
|
308
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
288
309
|
**kwargs,
|
289
310
|
) -> BaseChatClient: ...
|
290
311
|
|
@@ -298,6 +319,7 @@ def create_chat_client(
|
|
298
319
|
random_endpoint: bool = True,
|
299
320
|
endpoint_id: str = "",
|
300
321
|
http_client: httpx.Client | None = None,
|
322
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
301
323
|
**kwargs,
|
302
324
|
) -> BaseChatClient:
|
303
325
|
if backend not in BackendMap["sync"]:
|
@@ -314,6 +336,7 @@ def create_chat_client(
|
|
314
336
|
random_endpoint=random_endpoint,
|
315
337
|
endpoint_id=endpoint_id,
|
316
338
|
http_client=http_client,
|
339
|
+
settings=settings,
|
317
340
|
**kwargs,
|
318
341
|
)
|
319
342
|
|
@@ -328,6 +351,7 @@ def create_async_chat_client(
|
|
328
351
|
random_endpoint: bool = True,
|
329
352
|
endpoint_id: str = "",
|
330
353
|
http_client: httpx.AsyncClient | None = None,
|
354
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
331
355
|
**kwargs,
|
332
356
|
) -> AsyncAnthropicChatClient: ...
|
333
357
|
|
@@ -342,6 +366,7 @@ def create_async_chat_client(
|
|
342
366
|
random_endpoint: bool = True,
|
343
367
|
endpoint_id: str = "",
|
344
368
|
http_client: httpx.AsyncClient | None = None,
|
369
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
345
370
|
**kwargs,
|
346
371
|
) -> AsyncDeepSeekChatClient: ...
|
347
372
|
|
@@ -356,6 +381,7 @@ def create_async_chat_client(
|
|
356
381
|
random_endpoint: bool = True,
|
357
382
|
endpoint_id: str = "",
|
358
383
|
http_client: httpx.AsyncClient | None = None,
|
384
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
359
385
|
**kwargs,
|
360
386
|
) -> AsyncGeminiChatClient: ...
|
361
387
|
|
@@ -370,6 +396,7 @@ def create_async_chat_client(
|
|
370
396
|
random_endpoint: bool = True,
|
371
397
|
endpoint_id: str = "",
|
372
398
|
http_client: httpx.AsyncClient | None = None,
|
399
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
373
400
|
**kwargs,
|
374
401
|
) -> AsyncGroqChatClient: ...
|
375
402
|
|
@@ -384,6 +411,7 @@ def create_async_chat_client(
|
|
384
411
|
random_endpoint: bool = True,
|
385
412
|
endpoint_id: str = "",
|
386
413
|
http_client: httpx.AsyncClient | None = None,
|
414
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
387
415
|
**kwargs,
|
388
416
|
) -> AsyncLocalChatClient: ...
|
389
417
|
|
@@ -398,6 +426,7 @@ def create_async_chat_client(
|
|
398
426
|
random_endpoint: bool = True,
|
399
427
|
endpoint_id: str = "",
|
400
428
|
http_client: httpx.AsyncClient | None = None,
|
429
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
401
430
|
**kwargs,
|
402
431
|
) -> AsyncMiniMaxChatClient: ...
|
403
432
|
|
@@ -412,6 +441,7 @@ def create_async_chat_client(
|
|
412
441
|
random_endpoint: bool = True,
|
413
442
|
endpoint_id: str = "",
|
414
443
|
http_client: httpx.AsyncClient | None = None,
|
444
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
415
445
|
**kwargs,
|
416
446
|
) -> AsyncMistralChatClient: ...
|
417
447
|
|
@@ -426,6 +456,7 @@ def create_async_chat_client(
|
|
426
456
|
random_endpoint: bool = True,
|
427
457
|
endpoint_id: str = "",
|
428
458
|
http_client: httpx.AsyncClient | None = None,
|
459
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
429
460
|
**kwargs,
|
430
461
|
) -> AsyncMoonshotChatClient: ...
|
431
462
|
|
@@ -440,6 +471,7 @@ def create_async_chat_client(
|
|
440
471
|
random_endpoint: bool = True,
|
441
472
|
endpoint_id: str = "",
|
442
473
|
http_client: httpx.AsyncClient | None = None,
|
474
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
443
475
|
**kwargs,
|
444
476
|
) -> AsyncOpenAIChatClient: ...
|
445
477
|
|
@@ -454,6 +486,7 @@ def create_async_chat_client(
|
|
454
486
|
random_endpoint: bool = True,
|
455
487
|
endpoint_id: str = "",
|
456
488
|
http_client: httpx.AsyncClient | None = None,
|
489
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
457
490
|
**kwargs,
|
458
491
|
) -> AsyncQwenChatClient: ...
|
459
492
|
|
@@ -468,6 +501,7 @@ def create_async_chat_client(
|
|
468
501
|
random_endpoint: bool = True,
|
469
502
|
endpoint_id: str = "",
|
470
503
|
http_client: httpx.AsyncClient | None = None,
|
504
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
471
505
|
**kwargs,
|
472
506
|
) -> AsyncYiChatClient: ...
|
473
507
|
|
@@ -482,6 +516,7 @@ def create_async_chat_client(
|
|
482
516
|
random_endpoint: bool = True,
|
483
517
|
endpoint_id: str = "",
|
484
518
|
http_client: httpx.AsyncClient | None = None,
|
519
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
485
520
|
**kwargs,
|
486
521
|
) -> AsyncZhiPuAIChatClient: ...
|
487
522
|
|
@@ -496,6 +531,7 @@ def create_async_chat_client(
|
|
496
531
|
random_endpoint: bool = True,
|
497
532
|
endpoint_id: str = "",
|
498
533
|
http_client: httpx.AsyncClient | None = None,
|
534
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
499
535
|
**kwargs,
|
500
536
|
) -> AsyncBaichuanChatClient: ...
|
501
537
|
|
@@ -510,6 +546,7 @@ def create_async_chat_client(
|
|
510
546
|
random_endpoint: bool = True,
|
511
547
|
endpoint_id: str = "",
|
512
548
|
http_client: httpx.AsyncClient | None = None,
|
549
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
513
550
|
**kwargs,
|
514
551
|
) -> AsyncStepFunChatClient: ...
|
515
552
|
|
@@ -524,6 +561,7 @@ def create_async_chat_client(
|
|
524
561
|
random_endpoint: bool = True,
|
525
562
|
endpoint_id: str = "",
|
526
563
|
http_client: httpx.AsyncClient | None = None,
|
564
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
527
565
|
**kwargs,
|
528
566
|
) -> AsyncXAIChatClient: ...
|
529
567
|
|
@@ -538,6 +576,7 @@ def create_async_chat_client(
|
|
538
576
|
random_endpoint: bool = True,
|
539
577
|
endpoint_id: str = "",
|
540
578
|
http_client: httpx.AsyncClient | None = None,
|
579
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
541
580
|
**kwargs,
|
542
581
|
) -> BaseAsyncChatClient: ...
|
543
582
|
|
@@ -551,6 +590,7 @@ def create_async_chat_client(
|
|
551
590
|
random_endpoint: bool = True,
|
552
591
|
endpoint_id: str = "",
|
553
592
|
http_client: httpx.AsyncClient | None = None,
|
593
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
554
594
|
**kwargs,
|
555
595
|
) -> BaseAsyncChatClient:
|
556
596
|
if backend not in BackendMap["async"]:
|
@@ -567,6 +607,7 @@ def create_async_chat_client(
|
|
567
607
|
random_endpoint=random_endpoint,
|
568
608
|
endpoint_id=endpoint_id,
|
569
609
|
http_client=http_client,
|
610
|
+
settings=settings,
|
570
611
|
**kwargs,
|
571
612
|
)
|
572
613
|
|
@@ -5,13 +5,14 @@ from typing import (
|
|
5
5
|
Any,
|
6
6
|
Dict,
|
7
7
|
List,
|
8
|
+
TYPE_CHECKING,
|
9
|
+
overload,
|
10
|
+
Generator,
|
11
|
+
AsyncGenerator,
|
8
12
|
Union,
|
9
13
|
Literal,
|
10
14
|
Iterable,
|
11
|
-
overload,
|
12
15
|
Optional,
|
13
|
-
Generator,
|
14
|
-
AsyncGenerator,
|
15
16
|
)
|
16
17
|
|
17
18
|
import httpx
|
@@ -67,6 +68,10 @@ from ..types.llm_parameters import (
|
|
67
68
|
ChatCompletionDeltaMessage,
|
68
69
|
)
|
69
70
|
|
71
|
+
if TYPE_CHECKING:
|
72
|
+
from ..settings import Settings
|
73
|
+
from ..types.settings import SettingsDict
|
74
|
+
|
70
75
|
|
71
76
|
def refactor_tool_use_params(tools: Iterable[ChatCompletionToolParam]) -> list[AnthropicToolParam]:
|
72
77
|
return [
|
@@ -186,6 +191,7 @@ class AnthropicChatClient(BaseChatClient):
|
|
186
191
|
endpoint_id: str = "",
|
187
192
|
http_client: httpx.Client | None = None,
|
188
193
|
backend_name: str | None = None,
|
194
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
189
195
|
):
|
190
196
|
super().__init__(
|
191
197
|
model,
|
@@ -196,6 +202,7 @@ class AnthropicChatClient(BaseChatClient):
|
|
196
202
|
endpoint_id,
|
197
203
|
http_client,
|
198
204
|
backend_name,
|
205
|
+
settings,
|
199
206
|
)
|
200
207
|
self.model_id = None
|
201
208
|
self.endpoint = None
|
@@ -717,6 +724,7 @@ class AsyncAnthropicChatClient(BaseAsyncChatClient):
|
|
717
724
|
endpoint_id: str = "",
|
718
725
|
http_client: httpx.AsyncClient | None = None,
|
719
726
|
backend_name: str | None = None,
|
727
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
720
728
|
):
|
721
729
|
super().__init__(
|
722
730
|
model,
|
@@ -727,6 +735,7 @@ class AsyncAnthropicChatClient(BaseAsyncChatClient):
|
|
727
735
|
endpoint_id,
|
728
736
|
http_client,
|
729
737
|
backend_name,
|
738
|
+
settings,
|
730
739
|
)
|
731
740
|
self.model_id = None
|
732
741
|
self.endpoint = None
|
@@ -27,8 +27,10 @@ from anthropic import (
|
|
27
27
|
)
|
28
28
|
from anthropic.types.thinking_config_param import ThinkingConfigParam
|
29
29
|
|
30
|
-
from ..settings import
|
30
|
+
from ..settings import Settings
|
31
|
+
from ..settings import settings as default_settings
|
31
32
|
from ..types import defaults as defs
|
33
|
+
from ..types.settings import SettingsDict
|
32
34
|
from ..types.enums import ContextLengthControlType, BackendType
|
33
35
|
from ..types.llm_parameters import (
|
34
36
|
NotGiven,
|
@@ -58,6 +60,7 @@ class BaseChatClient(ABC):
|
|
58
60
|
endpoint_id: str = "",
|
59
61
|
http_client: httpx.Client | None = None,
|
60
62
|
backend_name: str | None = None,
|
63
|
+
settings: Settings | SettingsDict | None = None, # Use default settings if not provided
|
61
64
|
):
|
62
65
|
self.model = model or self.DEFAULT_MODEL
|
63
66
|
self.stream = stream
|
@@ -70,7 +73,14 @@ class BaseChatClient(ABC):
|
|
70
73
|
if backend_name is not None:
|
71
74
|
self.BACKEND_NAME = BackendType(backend_name)
|
72
75
|
|
73
|
-
|
76
|
+
if settings is None:
|
77
|
+
self.settings = default_settings
|
78
|
+
elif isinstance(settings, dict):
|
79
|
+
self.settings = Settings(**settings)
|
80
|
+
else:
|
81
|
+
self.settings = settings
|
82
|
+
|
83
|
+
self.backend_settings = self.settings.get_backend(self.BACKEND_NAME)
|
74
84
|
|
75
85
|
self.rate_limiter = self._init_rate_limiter()
|
76
86
|
self.active_requests = defaultdict(int)
|
@@ -81,29 +91,29 @@ class BaseChatClient(ABC):
|
|
81
91
|
if endpoint_id:
|
82
92
|
self.endpoint_id = endpoint_id
|
83
93
|
self.random_endpoint = False
|
84
|
-
self.endpoint = settings.get_endpoint(self.endpoint_id)
|
94
|
+
self.endpoint = self.settings.get_endpoint(self.endpoint_id)
|
85
95
|
|
86
96
|
def _init_rate_limiter(self):
|
87
|
-
if not settings.rate_limit:
|
97
|
+
if not self.settings.rate_limit:
|
88
98
|
return None
|
89
|
-
if not settings.rate_limit.enabled:
|
99
|
+
if not self.settings.rate_limit.enabled:
|
90
100
|
return None
|
91
101
|
|
92
|
-
if settings.rate_limit.backend == "memory":
|
102
|
+
if self.settings.rate_limit.backend == "memory":
|
93
103
|
return SyncMemoryRateLimiter()
|
94
|
-
elif settings.rate_limit.backend == "redis":
|
95
|
-
if not settings.rate_limit.redis:
|
104
|
+
elif self.settings.rate_limit.backend == "redis":
|
105
|
+
if not self.settings.rate_limit.redis:
|
96
106
|
raise ValueError("Redis settings must be provided if Redis backend is selected.")
|
97
107
|
return SyncRedisRateLimiter(
|
98
|
-
host=settings.rate_limit.redis.host,
|
99
|
-
port=settings.rate_limit.redis.port,
|
100
|
-
db=settings.rate_limit.redis.db,
|
108
|
+
host=self.settings.rate_limit.redis.host,
|
109
|
+
port=self.settings.rate_limit.redis.port,
|
110
|
+
db=self.settings.rate_limit.redis.db,
|
101
111
|
)
|
102
|
-
elif settings.rate_limit.backend == "diskcache":
|
103
|
-
if not settings.rate_limit.diskcache:
|
112
|
+
elif self.settings.rate_limit.backend == "diskcache":
|
113
|
+
if not self.settings.rate_limit.diskcache:
|
104
114
|
raise ValueError("Diskcache settings must be provided if Diskcache backend is selected.")
|
105
115
|
return SyncDiskCacheRateLimiter(
|
106
|
-
cache_dir=settings.rate_limit.diskcache.cache_dir,
|
116
|
+
cache_dir=self.settings.rate_limit.diskcache.cache_dir,
|
107
117
|
)
|
108
118
|
return None
|
109
119
|
|
@@ -115,8 +125,10 @@ class BaseChatClient(ABC):
|
|
115
125
|
|
116
126
|
# Get rate limit parameters
|
117
127
|
# Priority: parameters in model.endpoints > parameters in endpoint > default parameters
|
118
|
-
rpm = self.rpm or endpoint.rpm or (settings.rate_limit.default_rpm if settings.rate_limit else 60)
|
119
|
-
tpm =
|
128
|
+
rpm = self.rpm or endpoint.rpm or (self.settings.rate_limit.default_rpm if self.settings.rate_limit else 60)
|
129
|
+
tpm = (
|
130
|
+
self.tpm or endpoint.tpm or (self.settings.rate_limit.default_tpm if self.settings.rate_limit else 1000000)
|
131
|
+
)
|
120
132
|
|
121
133
|
while self.rate_limiter:
|
122
134
|
allowed, wait_time = self.rate_limiter.check_limit(key, rpm, tpm, self._estimate_request_tokens(messages))
|
@@ -151,9 +163,9 @@ class BaseChatClient(ABC):
|
|
151
163
|
self.concurrent_requests = endpoint.get("concurrent_requests", None)
|
152
164
|
else:
|
153
165
|
self.endpoint_id = endpoint
|
154
|
-
self.endpoint = settings.get_endpoint(self.endpoint_id)
|
166
|
+
self.endpoint = self.settings.get_endpoint(self.endpoint_id)
|
155
167
|
else:
|
156
|
-
self.endpoint = settings.get_endpoint(self.endpoint_id)
|
168
|
+
self.endpoint = self.settings.get_endpoint(self.endpoint_id)
|
157
169
|
self.set_model_id_by_endpoint_id(self.endpoint_id)
|
158
170
|
elif isinstance(self.endpoint, EndpointSetting):
|
159
171
|
self.endpoint_id = self.endpoint.id
|
@@ -411,6 +423,15 @@ class BaseChatClient(ABC):
|
|
411
423
|
timeout=timeout,
|
412
424
|
)
|
413
425
|
|
426
|
+
def model_list(self):
|
427
|
+
_raw_client = self.raw_client
|
428
|
+
if isinstance(_raw_client, (OpenAI, AzureOpenAI)):
|
429
|
+
return _raw_client.models.list().model_dump()
|
430
|
+
elif isinstance(_raw_client, Anthropic):
|
431
|
+
return _raw_client.models.list(limit=1000).model_dump()
|
432
|
+
else:
|
433
|
+
raise ValueError(f"Unsupported client type: {type(_raw_client)}")
|
434
|
+
|
414
435
|
|
415
436
|
class BaseAsyncChatClient(ABC):
|
416
437
|
DEFAULT_MODEL: str
|
@@ -426,6 +447,7 @@ class BaseAsyncChatClient(ABC):
|
|
426
447
|
endpoint_id: str = "",
|
427
448
|
http_client: httpx.AsyncClient | None = None,
|
428
449
|
backend_name: str | None = None,
|
450
|
+
settings: Settings | SettingsDict | None = None, # Use default settings if not provided
|
429
451
|
):
|
430
452
|
self.model = model or self.DEFAULT_MODEL
|
431
453
|
self.stream = stream
|
@@ -438,7 +460,14 @@ class BaseAsyncChatClient(ABC):
|
|
438
460
|
if backend_name is not None:
|
439
461
|
self.BACKEND_NAME = BackendType(backend_name)
|
440
462
|
|
441
|
-
|
463
|
+
if settings is None:
|
464
|
+
self.settings = default_settings
|
465
|
+
elif isinstance(settings, dict):
|
466
|
+
self.settings = Settings(**settings)
|
467
|
+
else:
|
468
|
+
self.settings = settings
|
469
|
+
|
470
|
+
self.backend_settings = self.settings.get_backend(self.BACKEND_NAME)
|
442
471
|
|
443
472
|
self.rate_limiter = self._init_rate_limiter()
|
444
473
|
self.active_requests = defaultdict(int)
|
@@ -449,29 +478,29 @@ class BaseAsyncChatClient(ABC):
|
|
449
478
|
if endpoint_id:
|
450
479
|
self.endpoint_id = endpoint_id
|
451
480
|
self.random_endpoint = False
|
452
|
-
self.endpoint = settings.get_endpoint(self.endpoint_id)
|
481
|
+
self.endpoint = self.settings.get_endpoint(self.endpoint_id)
|
453
482
|
|
454
483
|
def _init_rate_limiter(self):
|
455
|
-
if not settings.rate_limit:
|
484
|
+
if not self.settings.rate_limit:
|
456
485
|
return None
|
457
|
-
if not settings.rate_limit.enabled:
|
486
|
+
if not self.settings.rate_limit.enabled:
|
458
487
|
return None
|
459
488
|
|
460
|
-
if settings.rate_limit.backend == "memory":
|
489
|
+
if self.settings.rate_limit.backend == "memory":
|
461
490
|
return AsyncMemoryRateLimiter()
|
462
|
-
elif settings.rate_limit.backend == "redis":
|
463
|
-
if not settings.rate_limit.redis:
|
491
|
+
elif self.settings.rate_limit.backend == "redis":
|
492
|
+
if not self.settings.rate_limit.redis:
|
464
493
|
raise ValueError("Redis settings must be provided if Redis backend is selected.")
|
465
494
|
return AsyncRedisRateLimiter(
|
466
|
-
host=settings.rate_limit.redis.host,
|
467
|
-
port=settings.rate_limit.redis.port,
|
468
|
-
db=settings.rate_limit.redis.db,
|
495
|
+
host=self.settings.rate_limit.redis.host,
|
496
|
+
port=self.settings.rate_limit.redis.port,
|
497
|
+
db=self.settings.rate_limit.redis.db,
|
469
498
|
)
|
470
|
-
elif settings.rate_limit.backend == "diskcache":
|
471
|
-
if not settings.rate_limit.diskcache:
|
499
|
+
elif self.settings.rate_limit.backend == "diskcache":
|
500
|
+
if not self.settings.rate_limit.diskcache:
|
472
501
|
raise ValueError("Diskcache settings must be provided if Diskcache backend is selected.")
|
473
502
|
return AsyncDiskCacheRateLimiter(
|
474
|
-
cache_dir=settings.rate_limit.diskcache.cache_dir,
|
503
|
+
cache_dir=self.settings.rate_limit.diskcache.cache_dir,
|
475
504
|
)
|
476
505
|
return None
|
477
506
|
|
@@ -483,8 +512,10 @@ class BaseAsyncChatClient(ABC):
|
|
483
512
|
|
484
513
|
# Get rate limit parameters
|
485
514
|
# Priority: parameters in model.endpoints > parameters in endpoint > default parameters
|
486
|
-
rpm = self.rpm or endpoint.rpm or (settings.rate_limit.default_rpm if settings.rate_limit else 60)
|
487
|
-
tpm =
|
515
|
+
rpm = self.rpm or endpoint.rpm or (self.settings.rate_limit.default_rpm if self.settings.rate_limit else 60)
|
516
|
+
tpm = (
|
517
|
+
self.tpm or endpoint.tpm or (self.settings.rate_limit.default_tpm if self.settings.rate_limit else 1000000)
|
518
|
+
)
|
488
519
|
|
489
520
|
while self.rate_limiter:
|
490
521
|
allowed, wait_time = await self.rate_limiter.check_limit(
|
@@ -521,9 +552,9 @@ class BaseAsyncChatClient(ABC):
|
|
521
552
|
self.concurrent_requests = endpoint.get("concurrent_requests", None)
|
522
553
|
else:
|
523
554
|
self.endpoint_id = endpoint
|
524
|
-
self.endpoint = settings.get_endpoint(self.endpoint_id)
|
555
|
+
self.endpoint = self.settings.get_endpoint(self.endpoint_id)
|
525
556
|
else:
|
526
|
-
self.endpoint = settings.get_endpoint(self.endpoint_id)
|
557
|
+
self.endpoint = self.settings.get_endpoint(self.endpoint_id)
|
527
558
|
self.set_model_id_by_endpoint_id(self.endpoint_id)
|
528
559
|
elif isinstance(self.endpoint, EndpointSetting):
|
529
560
|
self.endpoint_id = self.endpoint.id
|
@@ -629,7 +660,7 @@ class BaseAsyncChatClient(ABC):
|
|
629
660
|
extra_query: Query | None = None,
|
630
661
|
extra_body: Body | None = None,
|
631
662
|
timeout: float | httpx.Timeout | None | OpenAINotGiven = NOT_GIVEN,
|
632
|
-
) -> AsyncGenerator[ChatCompletionDeltaMessage,
|
663
|
+
) -> AsyncGenerator[ChatCompletionDeltaMessage, Any]:
|
633
664
|
pass
|
634
665
|
|
635
666
|
@overload
|
@@ -671,7 +702,7 @@ class BaseAsyncChatClient(ABC):
|
|
671
702
|
extra_query: Query | None = None,
|
672
703
|
extra_body: Body | None = None,
|
673
704
|
timeout: float | httpx.Timeout | None | OpenAINotGiven = NOT_GIVEN,
|
674
|
-
) -> ChatCompletionMessage | AsyncGenerator[ChatCompletionDeltaMessage,
|
705
|
+
) -> ChatCompletionMessage | AsyncGenerator[ChatCompletionDeltaMessage, Any]:
|
675
706
|
pass
|
676
707
|
|
677
708
|
@abstractmethod
|
@@ -712,7 +743,7 @@ class BaseAsyncChatClient(ABC):
|
|
712
743
|
extra_query: Query | None = None,
|
713
744
|
extra_body: Body | None = None,
|
714
745
|
timeout: float | httpx.Timeout | None | OpenAINotGiven = NOT_GIVEN,
|
715
|
-
) -> ChatCompletionMessage | AsyncGenerator[ChatCompletionDeltaMessage,
|
746
|
+
) -> ChatCompletionMessage | AsyncGenerator[ChatCompletionDeltaMessage, Any]:
|
716
747
|
pass
|
717
748
|
|
718
749
|
async def create_stream(
|
@@ -751,7 +782,7 @@ class BaseAsyncChatClient(ABC):
|
|
751
782
|
extra_query: Query | None = None,
|
752
783
|
extra_body: Body | None = None,
|
753
784
|
timeout: float | httpx.Timeout | None | OpenAINotGiven = NOT_GIVEN,
|
754
|
-
) -> AsyncGenerator[ChatCompletionDeltaMessage,
|
785
|
+
) -> AsyncGenerator[ChatCompletionDeltaMessage, Any]:
|
755
786
|
return await self.create_completion(
|
756
787
|
messages=messages,
|
757
788
|
model=model,
|
@@ -788,3 +819,12 @@ class BaseAsyncChatClient(ABC):
|
|
788
819
|
extra_body=extra_body,
|
789
820
|
timeout=timeout,
|
790
821
|
)
|
822
|
+
|
823
|
+
async def model_list(self):
|
824
|
+
_raw_client = self.raw_client
|
825
|
+
if isinstance(_raw_client, (AsyncOpenAI, AsyncAzureOpenAI)):
|
826
|
+
return (await _raw_client.models.list()).model_dump()
|
827
|
+
elif isinstance(_raw_client, AsyncAnthropic):
|
828
|
+
return (await _raw_client.models.list(limit=1000)).model_dump()
|
829
|
+
else:
|
830
|
+
raise ValueError(f"Unsupported client type: {type(_raw_client)}")
|
{vectorvein-0.2.9 → vectorvein-0.2.11}/src/vectorvein/chat_clients/openai_compatible_client.py
RENAMED
@@ -3,7 +3,19 @@
|
|
3
3
|
import re
|
4
4
|
import json
|
5
5
|
from functools import cached_property
|
6
|
-
from typing import
|
6
|
+
from typing import (
|
7
|
+
Any,
|
8
|
+
Dict,
|
9
|
+
List,
|
10
|
+
TYPE_CHECKING,
|
11
|
+
overload,
|
12
|
+
Generator,
|
13
|
+
AsyncGenerator,
|
14
|
+
Union,
|
15
|
+
Literal,
|
16
|
+
Iterable,
|
17
|
+
Optional,
|
18
|
+
)
|
7
19
|
|
8
20
|
import httpx
|
9
21
|
from openai import OpenAI, AsyncOpenAI, AzureOpenAI, AsyncAzureOpenAI
|
@@ -39,6 +51,10 @@ from ..types.llm_parameters import (
|
|
39
51
|
ChatCompletionDeltaMessage,
|
40
52
|
)
|
41
53
|
|
54
|
+
if TYPE_CHECKING:
|
55
|
+
from ..settings import Settings
|
56
|
+
from ..types.settings import SettingsDict
|
57
|
+
|
42
58
|
|
43
59
|
class OpenAICompatibleChatClient(BaseChatClient):
|
44
60
|
DEFAULT_MODEL: str = ""
|
@@ -54,6 +70,7 @@ class OpenAICompatibleChatClient(BaseChatClient):
|
|
54
70
|
endpoint_id: str = "",
|
55
71
|
http_client: httpx.Client | None = None,
|
56
72
|
backend_name: str | None = None,
|
73
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
57
74
|
):
|
58
75
|
super().__init__(
|
59
76
|
model,
|
@@ -64,6 +81,7 @@ class OpenAICompatibleChatClient(BaseChatClient):
|
|
64
81
|
endpoint_id,
|
65
82
|
http_client,
|
66
83
|
backend_name,
|
84
|
+
settings,
|
67
85
|
)
|
68
86
|
self.model_id = None
|
69
87
|
self.endpoint = None
|
@@ -527,6 +545,7 @@ class AsyncOpenAICompatibleChatClient(BaseAsyncChatClient):
|
|
527
545
|
endpoint_id: str = "",
|
528
546
|
http_client: httpx.AsyncClient | None = None,
|
529
547
|
backend_name: str | None = None,
|
548
|
+
settings: "Settings | SettingsDict | None" = None, # Use default settings if not provided
|
530
549
|
):
|
531
550
|
super().__init__(
|
532
551
|
model,
|
@@ -537,6 +556,7 @@ class AsyncOpenAICompatibleChatClient(BaseAsyncChatClient):
|
|
537
556
|
endpoint_id,
|
538
557
|
http_client,
|
539
558
|
backend_name,
|
559
|
+
settings,
|
540
560
|
)
|
541
561
|
self.model_id = None
|
542
562
|
self.endpoint = None
|
@@ -0,0 +1,129 @@
|
|
1
|
+
from .defaults import (
|
2
|
+
CONTEXT_LENGTH_CONTROL,
|
3
|
+
ENDPOINT_CONCURRENT_REQUESTS,
|
4
|
+
ENDPOINT_RPM,
|
5
|
+
ENDPOINT_TPM,
|
6
|
+
MODEL_CONTEXT_LENGTH,
|
7
|
+
MOONSHOT_DEFAULT_MODEL,
|
8
|
+
MOONSHOT_MODELS,
|
9
|
+
DEEPSEEK_DEFAULT_MODEL,
|
10
|
+
DEEPSEEK_MODELS,
|
11
|
+
BAICHUAN_DEFAULT_MODEL,
|
12
|
+
BAICHUAN_MODELS,
|
13
|
+
GROQ_DEFAULT_MODEL,
|
14
|
+
GROQ_MODELS,
|
15
|
+
QWEN_DEFAULT_MODEL,
|
16
|
+
QWEN_MODELS,
|
17
|
+
YI_DEFAULT_MODEL,
|
18
|
+
YI_MODELS,
|
19
|
+
ZHIPUAI_DEFAULT_MODEL,
|
20
|
+
ZHIPUAI_MODELS,
|
21
|
+
MISTRAL_DEFAULT_MODEL,
|
22
|
+
MISTRAL_MODELS,
|
23
|
+
OPENAI_DEFAULT_MODEL,
|
24
|
+
OPENAI_MODELS,
|
25
|
+
ANTHROPIC_DEFAULT_MODEL,
|
26
|
+
ANTHROPIC_MODELS,
|
27
|
+
MINIMAX_DEFAULT_MODEL,
|
28
|
+
MINIMAX_MODELS,
|
29
|
+
GEMINI_DEFAULT_MODEL,
|
30
|
+
GEMINI_MODELS,
|
31
|
+
ERNIE_DEFAULT_MODEL,
|
32
|
+
ERNIE_MODELS,
|
33
|
+
STEPFUN_DEFAULT_MODEL,
|
34
|
+
STEPFUN_MODELS,
|
35
|
+
XAI_DEFAULT_MODEL,
|
36
|
+
XAI_MODELS,
|
37
|
+
)
|
38
|
+
from .enums import BackendType, LLMType, ContextLengthControlType
|
39
|
+
from .exception import APIStatusError
|
40
|
+
from .llm_parameters import (
|
41
|
+
EndpointSetting,
|
42
|
+
ModelSetting,
|
43
|
+
BackendSettings,
|
44
|
+
Usage,
|
45
|
+
ChatCompletionMessage,
|
46
|
+
ChatCompletionDeltaMessage,
|
47
|
+
NotGiven,
|
48
|
+
NOT_GIVEN,
|
49
|
+
OpenAIToolParam,
|
50
|
+
ToolParam,
|
51
|
+
Tools,
|
52
|
+
ToolChoice,
|
53
|
+
)
|
54
|
+
from .settings import (
|
55
|
+
RedisConfigDict,
|
56
|
+
DiskCacheConfigDict,
|
57
|
+
RateLimitConfigDict,
|
58
|
+
ServerDict,
|
59
|
+
EndpointOptionDict,
|
60
|
+
ModelConfigDict,
|
61
|
+
BackendSettingsDict,
|
62
|
+
EndpointSettingDict,
|
63
|
+
SettingsDict,
|
64
|
+
)
|
65
|
+
|
66
|
+
|
67
|
+
__all__ = [
|
68
|
+
"CONTEXT_LENGTH_CONTROL",
|
69
|
+
"ENDPOINT_CONCURRENT_REQUESTS",
|
70
|
+
"ENDPOINT_RPM",
|
71
|
+
"ENDPOINT_TPM",
|
72
|
+
"MODEL_CONTEXT_LENGTH",
|
73
|
+
"MOONSHOT_DEFAULT_MODEL",
|
74
|
+
"MOONSHOT_MODELS",
|
75
|
+
"DEEPSEEK_DEFAULT_MODEL",
|
76
|
+
"DEEPSEEK_MODELS",
|
77
|
+
"BAICHUAN_DEFAULT_MODEL",
|
78
|
+
"BAICHUAN_MODELS",
|
79
|
+
"GROQ_DEFAULT_MODEL",
|
80
|
+
"GROQ_MODELS",
|
81
|
+
"QWEN_DEFAULT_MODEL",
|
82
|
+
"QWEN_MODELS",
|
83
|
+
"YI_DEFAULT_MODEL",
|
84
|
+
"YI_MODELS",
|
85
|
+
"ZHIPUAI_DEFAULT_MODEL",
|
86
|
+
"ZHIPUAI_MODELS",
|
87
|
+
"MISTRAL_DEFAULT_MODEL",
|
88
|
+
"MISTRAL_MODELS",
|
89
|
+
"OPENAI_DEFAULT_MODEL",
|
90
|
+
"OPENAI_MODELS",
|
91
|
+
"ANTHROPIC_DEFAULT_MODEL",
|
92
|
+
"ANTHROPIC_MODELS",
|
93
|
+
"MINIMAX_DEFAULT_MODEL",
|
94
|
+
"MINIMAX_MODELS",
|
95
|
+
"GEMINI_DEFAULT_MODEL",
|
96
|
+
"GEMINI_MODELS",
|
97
|
+
"ERNIE_DEFAULT_MODEL",
|
98
|
+
"ERNIE_MODELS",
|
99
|
+
"STEPFUN_DEFAULT_MODEL",
|
100
|
+
"STEPFUN_MODELS",
|
101
|
+
"XAI_DEFAULT_MODEL",
|
102
|
+
"XAI_MODELS",
|
103
|
+
"BackendType",
|
104
|
+
"LLMType",
|
105
|
+
"ContextLengthControlType",
|
106
|
+
"APIStatusError",
|
107
|
+
"EndpointOptionDict",
|
108
|
+
"EndpointSetting",
|
109
|
+
"ModelSetting",
|
110
|
+
"BackendSettings",
|
111
|
+
"Usage",
|
112
|
+
"ChatCompletionMessage",
|
113
|
+
"ChatCompletionDeltaMessage",
|
114
|
+
"NotGiven",
|
115
|
+
"NOT_GIVEN",
|
116
|
+
"OpenAIToolParam",
|
117
|
+
"ToolParam",
|
118
|
+
"Tools",
|
119
|
+
"ToolChoice",
|
120
|
+
"RedisConfigDict",
|
121
|
+
"DiskCacheConfigDict",
|
122
|
+
"RateLimitConfigDict",
|
123
|
+
"ServerDict",
|
124
|
+
"EndpointOptionDict",
|
125
|
+
"ModelConfigDict",
|
126
|
+
"BackendSettingsDict",
|
127
|
+
"EndpointSettingDict",
|
128
|
+
"SettingsDict",
|
129
|
+
]
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# @Author: Bi Ying
|
2
2
|
# @Date: 2024-07-26 23:48:04
|
3
3
|
from typing import List, Dict, Optional, Union, Iterable
|
4
|
-
from typing_extensions import TypedDict, NotRequired # Required by pydantic under Python < 3.12
|
5
4
|
|
6
5
|
from pydantic import BaseModel, Field
|
7
6
|
|
@@ -22,14 +21,7 @@ from openai.types.chat.chat_completion_stream_options_param import ChatCompletio
|
|
22
21
|
from openai.types.chat.chat_completion_tool_choice_option_param import ChatCompletionToolChoiceOptionParam
|
23
22
|
|
24
23
|
from . import defaults as defs
|
25
|
-
|
26
|
-
|
27
|
-
class EndpointOptionDict(TypedDict):
|
28
|
-
endpoint_id: str
|
29
|
-
model_id: str
|
30
|
-
rpm: NotRequired[int]
|
31
|
-
tpm: NotRequired[int]
|
32
|
-
concurrent_requests: NotRequired[int]
|
24
|
+
from .settings import EndpointOptionDict
|
33
25
|
|
34
26
|
|
35
27
|
class EndpointSetting(BaseModel):
|
@@ -0,0 +1,105 @@
|
|
1
|
+
from typing import Dict, List, Optional, Union, Literal
|
2
|
+
from typing_extensions import TypedDict, NotRequired # Required by pydantic under Python < 3.12
|
3
|
+
|
4
|
+
|
5
|
+
class RedisConfigDict(TypedDict):
|
6
|
+
"""TypedDict representing the RedisConfig structure."""
|
7
|
+
|
8
|
+
host: str
|
9
|
+
port: int
|
10
|
+
db: int
|
11
|
+
|
12
|
+
|
13
|
+
class DiskCacheConfigDict(TypedDict):
|
14
|
+
"""TypedDict representing the DiskCacheConfig structure."""
|
15
|
+
|
16
|
+
cache_dir: str
|
17
|
+
|
18
|
+
|
19
|
+
class RateLimitConfigDict(TypedDict):
|
20
|
+
"""TypedDict representing the RateLimitConfig structure."""
|
21
|
+
|
22
|
+
enabled: bool
|
23
|
+
backend: Literal["memory", "redis", "diskcache"]
|
24
|
+
redis: Optional[RedisConfigDict]
|
25
|
+
diskcache: Optional[DiskCacheConfigDict]
|
26
|
+
default_rpm: int
|
27
|
+
default_tpm: int
|
28
|
+
|
29
|
+
|
30
|
+
class ServerDict(TypedDict):
|
31
|
+
"""TypedDict representing the Server structure."""
|
32
|
+
|
33
|
+
host: str
|
34
|
+
port: int
|
35
|
+
url: Optional[str]
|
36
|
+
|
37
|
+
|
38
|
+
class EndpointOptionDict(TypedDict):
|
39
|
+
"""TypedDict representing the model endpoint option structure."""
|
40
|
+
|
41
|
+
endpoint_id: str
|
42
|
+
model_id: str
|
43
|
+
rpm: NotRequired[int]
|
44
|
+
tpm: NotRequired[int]
|
45
|
+
concurrent_requests: NotRequired[int]
|
46
|
+
|
47
|
+
|
48
|
+
class ModelConfigDict(TypedDict):
|
49
|
+
"""TypedDict representing the model configuration structure."""
|
50
|
+
|
51
|
+
id: str
|
52
|
+
endpoints: List[Union[str, EndpointOptionDict]]
|
53
|
+
function_call_available: bool
|
54
|
+
response_format_available: bool
|
55
|
+
native_multimodal: bool
|
56
|
+
context_length: int
|
57
|
+
max_output_tokens: Optional[int]
|
58
|
+
|
59
|
+
|
60
|
+
class BackendSettingsDict(TypedDict):
|
61
|
+
"""TypedDict representing the BackendSettings structure."""
|
62
|
+
|
63
|
+
models: Dict[str, ModelConfigDict]
|
64
|
+
|
65
|
+
|
66
|
+
class EndpointSettingDict(TypedDict):
|
67
|
+
"""TypedDict representing the EndpointSetting structure."""
|
68
|
+
|
69
|
+
id: str
|
70
|
+
api_base: Optional[str]
|
71
|
+
api_key: str
|
72
|
+
region: Optional[str]
|
73
|
+
api_schema_type: Optional[str]
|
74
|
+
credentials: Optional[dict]
|
75
|
+
is_azure: Optional[bool]
|
76
|
+
is_vertex: Optional[bool]
|
77
|
+
is_bedrock: Optional[bool]
|
78
|
+
rpm: Optional[int]
|
79
|
+
tpm: Optional[int]
|
80
|
+
concurrent_requests: Optional[int]
|
81
|
+
proxy: Optional[str]
|
82
|
+
|
83
|
+
|
84
|
+
class SettingsDict(TypedDict):
|
85
|
+
"""TypedDict representing the expected structure of the settings dictionary."""
|
86
|
+
|
87
|
+
endpoints: List[EndpointSettingDict]
|
88
|
+
token_server: Optional[ServerDict]
|
89
|
+
rate_limit: Optional[RateLimitConfigDict]
|
90
|
+
# 各模型后端配置
|
91
|
+
anthropic: BackendSettingsDict
|
92
|
+
deepseek: BackendSettingsDict
|
93
|
+
gemini: BackendSettingsDict
|
94
|
+
groq: BackendSettingsDict
|
95
|
+
local: BackendSettingsDict
|
96
|
+
minimax: BackendSettingsDict
|
97
|
+
mistral: BackendSettingsDict
|
98
|
+
moonshot: BackendSettingsDict
|
99
|
+
openai: BackendSettingsDict
|
100
|
+
qwen: BackendSettingsDict
|
101
|
+
yi: BackendSettingsDict
|
102
|
+
zhipuai: BackendSettingsDict
|
103
|
+
baichuan: BackendSettingsDict
|
104
|
+
stepfun: BackendSettingsDict
|
105
|
+
xai: BackendSettingsDict
|
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
|
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
|