tamar-model-client 0.1.1__tar.gz → 0.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. {tamar_model_client-0.1.1 → tamar_model_client-0.1.3}/PKG-INFO +61 -90
  2. {tamar_model_client-0.1.1 → tamar_model_client-0.1.3}/README.md +60 -89
  3. {tamar_model_client-0.1.1 → tamar_model_client-0.1.3}/setup.py +2 -2
  4. {tamar_model_client-0.1.1/model_manager_client → tamar_model_client-0.1.3/tamar_model_client}/__init__.py +4 -4
  5. {tamar_model_client-0.1.1/model_manager_client → tamar_model_client-0.1.3/tamar_model_client}/async_client.py +82 -87
  6. {tamar_model_client-0.1.1/model_manager_client → tamar_model_client-0.1.3/tamar_model_client}/generated/model_service_pb2_grpc.py +1 -1
  7. {tamar_model_client-0.1.1/model_manager_client → tamar_model_client-0.1.3/tamar_model_client}/schemas/inputs.py +2 -2
  8. {tamar_model_client-0.1.1/model_manager_client → tamar_model_client-0.1.3/tamar_model_client}/sync_client.py +9 -9
  9. {tamar_model_client-0.1.1 → tamar_model_client-0.1.3}/tamar_model_client.egg-info/PKG-INFO +61 -90
  10. tamar_model_client-0.1.3/tamar_model_client.egg-info/SOURCES.txt +22 -0
  11. tamar_model_client-0.1.3/tamar_model_client.egg-info/top_level.txt +1 -0
  12. tamar_model_client-0.1.1/tamar_model_client.egg-info/SOURCES.txt +0 -22
  13. tamar_model_client-0.1.1/tamar_model_client.egg-info/top_level.txt +0 -1
  14. {tamar_model_client-0.1.1 → tamar_model_client-0.1.3}/setup.cfg +0 -0
  15. {tamar_model_client-0.1.1/model_manager_client → tamar_model_client-0.1.3/tamar_model_client}/auth.py +0 -0
  16. {tamar_model_client-0.1.1/model_manager_client → tamar_model_client-0.1.3/tamar_model_client}/enums/__init__.py +0 -0
  17. {tamar_model_client-0.1.1/model_manager_client → tamar_model_client-0.1.3/tamar_model_client}/enums/channel.py +0 -0
  18. {tamar_model_client-0.1.1/model_manager_client → tamar_model_client-0.1.3/tamar_model_client}/enums/invoke.py +0 -0
  19. {tamar_model_client-0.1.1/model_manager_client → tamar_model_client-0.1.3/tamar_model_client}/enums/providers.py +0 -0
  20. {tamar_model_client-0.1.1/model_manager_client → tamar_model_client-0.1.3/tamar_model_client}/exceptions.py +0 -0
  21. {tamar_model_client-0.1.1/model_manager_client → tamar_model_client-0.1.3/tamar_model_client}/generated/__init__.py +0 -0
  22. {tamar_model_client-0.1.1/model_manager_client → tamar_model_client-0.1.3/tamar_model_client}/generated/model_service_pb2.py +0 -0
  23. {tamar_model_client-0.1.1/model_manager_client → tamar_model_client-0.1.3/tamar_model_client}/schemas/__init__.py +0 -0
  24. {tamar_model_client-0.1.1/model_manager_client → tamar_model_client-0.1.3/tamar_model_client}/schemas/outputs.py +0 -0
  25. {tamar_model_client-0.1.1 → tamar_model_client-0.1.3}/tamar_model_client.egg-info/dependency_links.txt +0 -0
  26. {tamar_model_client-0.1.1 → tamar_model_client-0.1.3}/tamar_model_client.egg-info/requires.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tamar-model-client
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: A Python SDK for interacting with the Model Manager gRPC service
5
5
  Home-page: http://gitlab.tamaredge.top/project-tap/AgentOS/model-manager-client
6
6
  Author: Oscar Ou
@@ -31,9 +31,9 @@ Dynamic: requires-dist
31
31
  Dynamic: requires-python
32
32
  Dynamic: summary
33
33
 
34
- # Model Manager Client
34
+ # Tamar Model Client
35
35
 
36
- **Model Manager Client** 是一款高性能的 Python SDK,用于连接 Model Manager gRPC 服务,统一调用多家第三方 AI
36
+ **Tamar Model Client** 是一款高性能的 Python SDK,用于连接 Model Manager gRPC 服务,统一调用多家第三方 AI
37
37
  模型服务商(如OpenAI、Google、Azure OpenAI)。
38
38
 
39
39
  ## ✨ 特性亮点
@@ -58,7 +58,7 @@ pip install tamar-model-client
58
58
  ## 🏗️ 项目结构概览
59
59
 
60
60
  ```
61
- model_manager_client/
61
+ tamar_model_client/
62
62
  ├── generated/ # gRPC 生成的代码
63
63
  │ ├── model_service.proto # 协议定义文件
64
64
  │ ├── model_service_pb2.py # 生成的 protobuf 代码
@@ -82,16 +82,16 @@ model_manager_client/
82
82
  ### 客户端初始化
83
83
 
84
84
  ```python
85
- from model_manager_client import ModelManagerClient, AsyncModelManagerClient
85
+ from tamar_model_client import TamarModelClient, AsyncTamarModelClient
86
86
 
87
87
  # 同步客户端
88
- client = ModelManagerClient(
88
+ client = TamarModelClient(
89
89
  server_address="localhost:50051",
90
90
  jwt_token="your-jwt-token"
91
91
  )
92
92
 
93
93
  # 异步客户端
94
- async_client = AsyncModelManagerClient(
94
+ async_client = AsyncTamarModelClient(
95
95
  server_address="localhost:50051",
96
96
  jwt_secret_key="your-jwt-secret-key" # 使用固定密钥自动生成 JWT
97
97
  )
@@ -105,12 +105,12 @@ async_client = AsyncModelManagerClient(
105
105
  #### OpenAI 调用示例
106
106
 
107
107
  ```python
108
- from model_manager_client import ModelManagerClient
109
- from model_manager_client.schemas import ModelRequest, UserContext
110
- from model_manager_client.enums import ProviderType, InvokeType, Channel
108
+ from tamar_model_client import TamarModelClient
109
+ from tamar_model_client.schemas import ModelRequest, UserContext
110
+ from tamar_model_client.enums import ProviderType, InvokeType, Channel
111
111
 
112
112
  # 创建同步客户端
113
- client = ModelManagerClient()
113
+ client = TamarModelClient()
114
114
 
115
115
  # OpenAI 调用示例
116
116
  request_data = ModelRequest(
@@ -144,12 +144,12 @@ else:
144
144
  #### Google 调用示例 (AI Studio / Vertex AI)
145
145
 
146
146
  ```python
147
- from model_manager_client import ModelManagerClient
148
- from model_manager_client.schemas import ModelRequest, UserContext
149
- from model_manager_client.enums import ProviderType, InvokeType, Channel
147
+ from tamar_model_client import TamarModelClient
148
+ from tamar_model_client.schemas import ModelRequest, UserContext
149
+ from tamar_model_client.enums import ProviderType, InvokeType, Channel
150
150
 
151
151
  # 创建同步客户端
152
- client = ModelManagerClient()
152
+ client = TamarModelClient()
153
153
 
154
154
  # Google AI Studio 调用示例
155
155
  request_data = ModelRequest(
@@ -207,12 +207,12 @@ else:
207
207
  #### Azure OpenAI 调用示例
208
208
 
209
209
  ```python
210
- from model_manager_client import ModelManagerClient
211
- from model_manager_client.schemas import ModelRequest, UserContext
212
- from model_manager_client.enums import ProviderType, InvokeType, Channel
210
+ from tamar_model_client import TamarModelClient
211
+ from tamar_model_client.schemas import ModelRequest, UserContext
212
+ from tamar_model_client.enums import ProviderType, InvokeType, Channel
213
213
 
214
214
  # 创建同步客户端
215
- client = ModelManagerClient()
215
+ client = TamarModelClient()
216
216
 
217
217
  # Azure OpenAI 调用示例
218
218
  request_data = ModelRequest(
@@ -247,14 +247,14 @@ else:
247
247
 
248
248
  ```python
249
249
  import asyncio
250
- from model_manager_client import AsyncModelManagerClient
251
- from model_manager_client.schemas import ModelRequest, UserContext
252
- from model_manager_client.enums import ProviderType, InvokeType, Channel
250
+ from tamar_model_client import AsyncTamarModelClient
251
+ from tamar_model_client.schemas import ModelRequest, UserContext
252
+ from tamar_model_client.enums import ProviderType, InvokeType, Channel
253
253
 
254
254
 
255
255
  async def main():
256
256
  # 创建异步客户端
257
- client = AsyncModelManagerClient()
257
+ client = AsyncTamarModelClient()
258
258
 
259
259
  # 组装请求参数
260
260
  request_data = ModelRequest(
@@ -293,14 +293,14 @@ asyncio.run(main())
293
293
 
294
294
  ```python
295
295
  import asyncio
296
- from model_manager_client import AsyncModelManagerClient
297
- from model_manager_client.schemas import ModelRequest, UserContext
298
- from model_manager_client.enums import ProviderType, InvokeType, Channel
296
+ from tamar_model_client import AsyncTamarModelClient
297
+ from tamar_model_client.schemas import ModelRequest, UserContext
298
+ from tamar_model_client.enums import ProviderType, InvokeType, Channel
299
299
 
300
300
 
301
301
  async def stream_example():
302
302
  # 创建异步客户端
303
- client = AsyncModelManagerClient()
303
+ client = AsyncTamarModelClient()
304
304
 
305
305
  # 组装请求参数
306
306
  request_data = ModelRequest(
@@ -340,17 +340,17 @@ asyncio.run(stream_example())
340
340
 
341
341
  ```python
342
342
  import asyncio
343
- from model_manager_client import AsyncModelManagerClient
344
- from model_manager_client.schemas import (
343
+ from tamar_model_client import AsyncTamarModelClient
344
+ from tamar_model_client.schemas import (
345
345
  BatchModelRequest, BatchModelRequestItem,
346
346
  UserContext
347
347
  )
348
- from model_manager_client.enums import ProviderType, InvokeType, Channel
348
+ from tamar_model_client.enums import ProviderType, InvokeType, Channel
349
349
 
350
350
 
351
351
  async def batch_example():
352
352
  # 创建异步客户端
353
- client = AsyncModelManagerClient()
353
+ client = AsyncTamarModelClient()
354
354
 
355
355
  # 组装批量请求参数
356
356
  batch_request = BatchModelRequest(
@@ -404,77 +404,48 @@ asyncio.run(batch_example())
404
404
 
405
405
  ### 文件输入示例
406
406
 
407
- 支持处理图像等文件输入(需使用支持多模态的模型,如 gpt-4-vision-preview):
407
+ 支持处理图像等文件输入(需使用支持多模态的模型,如 gemini-2.0-flash):
408
408
 
409
409
  ```python
410
- import asyncio
411
- from model_manager_client import AsyncModelManagerClient
412
- from model_manager_client.schemas import ModelRequest, UserContext
413
- from model_manager_client.enums import ProviderType, InvokeType, Channel
414
-
415
-
416
- async def file_input_example():
417
- # 创建异步客户端
418
- client = AsyncModelManagerClient()
419
-
420
- # 组装请求参数(包含文件输入)
421
- request_data = ModelRequest(
422
- provider=ProviderType.OPENAI,
423
- channel=Channel.OPENAI,
424
- invoke_type=InvokeType.CHAT_COMPLETIONS,
425
- model="gpt-4-vision-preview", # 使用支持图像的模型
426
- messages=[
427
- {
428
- "role": "user",
429
- "content": [
430
- {
431
- "type": "image_url",
432
- "image_url": {
433
- "url": "https://example.com/image.jpg"
434
- }
435
- },
436
- {
437
- "type": "text",
438
- "text": "请描述这张图片。"
439
- }
440
- ]
441
- }
442
- ],
443
- user_context=UserContext(
444
- user_id="test_user",
445
- org_id="test_org",
446
- client_type="python-sdk"
410
+ from tamar_model_client import TamarModelClient
411
+ from tamar_model_client.schemas import ModelRequest, UserContext
412
+ from tamar_model_client.enums import ProviderType
413
+ from google.genai.types import Part
414
+ model_request = ModelRequest(
415
+ provider=ProviderType.GOOGLE, # 选择 Google作为提供商
416
+ model="gemini-2.0-flash",
417
+ contents=[
418
+ "What is shown in this image?",
419
+ Part.from_uri( # 这个是Google那边的参数支持
420
+ file_uri="https://images.pexels.com/photos/248797/pexels-photo-248797.jpeg",
421
+ mime_type="image/jpeg",
447
422
  ),
448
- stream=False
449
- )
450
-
451
- # 发送请求并获取响应
452
- response = await client.invoke(request_data)
453
- if response.error:
454
- print(f"错误: {response.error}")
455
- else:
456
- print(f"响应: {response.content}")
457
- if response.usage:
458
- print(f"Token 使用情况: {response.usage}")
459
-
460
-
461
- # 运行文件输入示例
462
- asyncio.run(file_input_example())
423
+ ],
424
+ user_context=UserContext(
425
+ org_id="testllm",
426
+ user_id="testllm",
427
+ client_type="conversation-service"
428
+ ),
429
+ )
430
+ client = TamarModelClient("localhost:50051")
431
+ response = client.invoke(
432
+ model_request=model_request
433
+ )
463
434
  ```
464
435
 
465
436
  ### ⚠️ 注意事项
466
437
 
467
- 以下是使用 Model Manager Client 时的重要提示:
438
+ 以下是使用 Tamar Model Client 时的重要提示:
468
439
 
469
440
  - **参数处理**
470
- - 公共参数包括:**服务商 (provider)**、**渠道 (channel)** **调用方法 (invoke_type)**
441
+ - 公共参数包括:**服务商 (provider)**、**渠道 (channel)** **调用方法 (invoke_type)** 以及 **用户信息(user_context)**
471
442
  - 其中 **channel** 和 **invoke_type** 为可选参数,**建议默认使用系统自动推断**,除非有特殊需求再显式指定
472
443
  - 是否流式输出由公共参数 **stream** 控制,其他参数遵循对应服务商官方 SDK 的标准定义
473
444
  - **客户端连接管理**
474
445
  - gRPC 使用 HTTP/2 长连接,**建议将客户端实例作为单例使用**
475
- - 若需创建多个实例,**请务必调用** `client.close()` **方法手动关闭连接**,以防止连接堆积或资源泄露。
446
+ - 若需创建多个实例,**请务必调用** `client.close()` **方法手动关闭连接**,以防止连接堆积或资源泄露
476
447
  - **异常处理**:
477
- - 所有接口均提供详细的**错误信息** 以及 **请求ID(request_id)**,业务调用时建议纳入对应日志便于后期排错。
448
+ - 所有接口均提供详细的**错误信息** 以及 **请求ID(request_id)**,业务调用时建议纳入对应日志便于后期排错
478
449
 
479
450
  ## ⚙️ 环境变量配置(推荐)
480
451
 
@@ -528,9 +499,9 @@ MODEL_MANAGER_SERVER_GRPC_RETRY_DELAY=1.0
528
499
  加载后,初始化时无需传参:
529
500
 
530
501
  ```python
531
- from model_manager_client import ModelManagerClient
502
+ from tamar_model_client import TamarModelClient
532
503
 
533
- client = ModelManagerClient() # 将使用环境变量中的配置
504
+ client = TamarModelClient() # 将使用环境变量中的配置
534
505
  ```
535
506
 
536
507
  ## 开发
@@ -1,6 +1,6 @@
1
- # Model Manager Client
1
+ # Tamar Model Client
2
2
 
3
- **Model Manager Client** 是一款高性能的 Python SDK,用于连接 Model Manager gRPC 服务,统一调用多家第三方 AI
3
+ **Tamar Model Client** 是一款高性能的 Python SDK,用于连接 Model Manager gRPC 服务,统一调用多家第三方 AI
4
4
  模型服务商(如OpenAI、Google、Azure OpenAI)。
5
5
 
6
6
  ## ✨ 特性亮点
@@ -25,7 +25,7 @@ pip install tamar-model-client
25
25
  ## 🏗️ 项目结构概览
26
26
 
27
27
  ```
28
- model_manager_client/
28
+ tamar_model_client/
29
29
  ├── generated/ # gRPC 生成的代码
30
30
  │ ├── model_service.proto # 协议定义文件
31
31
  │ ├── model_service_pb2.py # 生成的 protobuf 代码
@@ -49,16 +49,16 @@ model_manager_client/
49
49
  ### 客户端初始化
50
50
 
51
51
  ```python
52
- from model_manager_client import ModelManagerClient, AsyncModelManagerClient
52
+ from tamar_model_client import TamarModelClient, AsyncTamarModelClient
53
53
 
54
54
  # 同步客户端
55
- client = ModelManagerClient(
55
+ client = TamarModelClient(
56
56
  server_address="localhost:50051",
57
57
  jwt_token="your-jwt-token"
58
58
  )
59
59
 
60
60
  # 异步客户端
61
- async_client = AsyncModelManagerClient(
61
+ async_client = AsyncTamarModelClient(
62
62
  server_address="localhost:50051",
63
63
  jwt_secret_key="your-jwt-secret-key" # 使用固定密钥自动生成 JWT
64
64
  )
@@ -72,12 +72,12 @@ async_client = AsyncModelManagerClient(
72
72
  #### OpenAI 调用示例
73
73
 
74
74
  ```python
75
- from model_manager_client import ModelManagerClient
76
- from model_manager_client.schemas import ModelRequest, UserContext
77
- from model_manager_client.enums import ProviderType, InvokeType, Channel
75
+ from tamar_model_client import TamarModelClient
76
+ from tamar_model_client.schemas import ModelRequest, UserContext
77
+ from tamar_model_client.enums import ProviderType, InvokeType, Channel
78
78
 
79
79
  # 创建同步客户端
80
- client = ModelManagerClient()
80
+ client = TamarModelClient()
81
81
 
82
82
  # OpenAI 调用示例
83
83
  request_data = ModelRequest(
@@ -111,12 +111,12 @@ else:
111
111
  #### Google 调用示例 (AI Studio / Vertex AI)
112
112
 
113
113
  ```python
114
- from model_manager_client import ModelManagerClient
115
- from model_manager_client.schemas import ModelRequest, UserContext
116
- from model_manager_client.enums import ProviderType, InvokeType, Channel
114
+ from tamar_model_client import TamarModelClient
115
+ from tamar_model_client.schemas import ModelRequest, UserContext
116
+ from tamar_model_client.enums import ProviderType, InvokeType, Channel
117
117
 
118
118
  # 创建同步客户端
119
- client = ModelManagerClient()
119
+ client = TamarModelClient()
120
120
 
121
121
  # Google AI Studio 调用示例
122
122
  request_data = ModelRequest(
@@ -174,12 +174,12 @@ else:
174
174
  #### Azure OpenAI 调用示例
175
175
 
176
176
  ```python
177
- from model_manager_client import ModelManagerClient
178
- from model_manager_client.schemas import ModelRequest, UserContext
179
- from model_manager_client.enums import ProviderType, InvokeType, Channel
177
+ from tamar_model_client import TamarModelClient
178
+ from tamar_model_client.schemas import ModelRequest, UserContext
179
+ from tamar_model_client.enums import ProviderType, InvokeType, Channel
180
180
 
181
181
  # 创建同步客户端
182
- client = ModelManagerClient()
182
+ client = TamarModelClient()
183
183
 
184
184
  # Azure OpenAI 调用示例
185
185
  request_data = ModelRequest(
@@ -214,14 +214,14 @@ else:
214
214
 
215
215
  ```python
216
216
  import asyncio
217
- from model_manager_client import AsyncModelManagerClient
218
- from model_manager_client.schemas import ModelRequest, UserContext
219
- from model_manager_client.enums import ProviderType, InvokeType, Channel
217
+ from tamar_model_client import AsyncTamarModelClient
218
+ from tamar_model_client.schemas import ModelRequest, UserContext
219
+ from tamar_model_client.enums import ProviderType, InvokeType, Channel
220
220
 
221
221
 
222
222
  async def main():
223
223
  # 创建异步客户端
224
- client = AsyncModelManagerClient()
224
+ client = AsyncTamarModelClient()
225
225
 
226
226
  # 组装请求参数
227
227
  request_data = ModelRequest(
@@ -260,14 +260,14 @@ asyncio.run(main())
260
260
 
261
261
  ```python
262
262
  import asyncio
263
- from model_manager_client import AsyncModelManagerClient
264
- from model_manager_client.schemas import ModelRequest, UserContext
265
- from model_manager_client.enums import ProviderType, InvokeType, Channel
263
+ from tamar_model_client import AsyncTamarModelClient
264
+ from tamar_model_client.schemas import ModelRequest, UserContext
265
+ from tamar_model_client.enums import ProviderType, InvokeType, Channel
266
266
 
267
267
 
268
268
  async def stream_example():
269
269
  # 创建异步客户端
270
- client = AsyncModelManagerClient()
270
+ client = AsyncTamarModelClient()
271
271
 
272
272
  # 组装请求参数
273
273
  request_data = ModelRequest(
@@ -307,17 +307,17 @@ asyncio.run(stream_example())
307
307
 
308
308
  ```python
309
309
  import asyncio
310
- from model_manager_client import AsyncModelManagerClient
311
- from model_manager_client.schemas import (
310
+ from tamar_model_client import AsyncTamarModelClient
311
+ from tamar_model_client.schemas import (
312
312
  BatchModelRequest, BatchModelRequestItem,
313
313
  UserContext
314
314
  )
315
- from model_manager_client.enums import ProviderType, InvokeType, Channel
315
+ from tamar_model_client.enums import ProviderType, InvokeType, Channel
316
316
 
317
317
 
318
318
  async def batch_example():
319
319
  # 创建异步客户端
320
- client = AsyncModelManagerClient()
320
+ client = AsyncTamarModelClient()
321
321
 
322
322
  # 组装批量请求参数
323
323
  batch_request = BatchModelRequest(
@@ -371,77 +371,48 @@ asyncio.run(batch_example())
371
371
 
372
372
  ### 文件输入示例
373
373
 
374
- 支持处理图像等文件输入(需使用支持多模态的模型,如 gpt-4-vision-preview):
374
+ 支持处理图像等文件输入(需使用支持多模态的模型,如 gemini-2.0-flash):
375
375
 
376
376
  ```python
377
- import asyncio
378
- from model_manager_client import AsyncModelManagerClient
379
- from model_manager_client.schemas import ModelRequest, UserContext
380
- from model_manager_client.enums import ProviderType, InvokeType, Channel
381
-
382
-
383
- async def file_input_example():
384
- # 创建异步客户端
385
- client = AsyncModelManagerClient()
386
-
387
- # 组装请求参数(包含文件输入)
388
- request_data = ModelRequest(
389
- provider=ProviderType.OPENAI,
390
- channel=Channel.OPENAI,
391
- invoke_type=InvokeType.CHAT_COMPLETIONS,
392
- model="gpt-4-vision-preview", # 使用支持图像的模型
393
- messages=[
394
- {
395
- "role": "user",
396
- "content": [
397
- {
398
- "type": "image_url",
399
- "image_url": {
400
- "url": "https://example.com/image.jpg"
401
- }
402
- },
403
- {
404
- "type": "text",
405
- "text": "请描述这张图片。"
406
- }
407
- ]
408
- }
409
- ],
410
- user_context=UserContext(
411
- user_id="test_user",
412
- org_id="test_org",
413
- client_type="python-sdk"
377
+ from tamar_model_client import TamarModelClient
378
+ from tamar_model_client.schemas import ModelRequest, UserContext
379
+ from tamar_model_client.enums import ProviderType
380
+ from google.genai.types import Part
381
+ model_request = ModelRequest(
382
+ provider=ProviderType.GOOGLE, # 选择 Google作为提供商
383
+ model="gemini-2.0-flash",
384
+ contents=[
385
+ "What is shown in this image?",
386
+ Part.from_uri( # 这个是Google那边的参数支持
387
+ file_uri="https://images.pexels.com/photos/248797/pexels-photo-248797.jpeg",
388
+ mime_type="image/jpeg",
414
389
  ),
415
- stream=False
416
- )
417
-
418
- # 发送请求并获取响应
419
- response = await client.invoke(request_data)
420
- if response.error:
421
- print(f"错误: {response.error}")
422
- else:
423
- print(f"响应: {response.content}")
424
- if response.usage:
425
- print(f"Token 使用情况: {response.usage}")
426
-
427
-
428
- # 运行文件输入示例
429
- asyncio.run(file_input_example())
390
+ ],
391
+ user_context=UserContext(
392
+ org_id="testllm",
393
+ user_id="testllm",
394
+ client_type="conversation-service"
395
+ ),
396
+ )
397
+ client = TamarModelClient("localhost:50051")
398
+ response = client.invoke(
399
+ model_request=model_request
400
+ )
430
401
  ```
431
402
 
432
403
  ### ⚠️ 注意事项
433
404
 
434
- 以下是使用 Model Manager Client 时的重要提示:
405
+ 以下是使用 Tamar Model Client 时的重要提示:
435
406
 
436
407
  - **参数处理**
437
- - 公共参数包括:**服务商 (provider)**、**渠道 (channel)** **调用方法 (invoke_type)**
408
+ - 公共参数包括:**服务商 (provider)**、**渠道 (channel)** **调用方法 (invoke_type)** 以及 **用户信息(user_context)**
438
409
  - 其中 **channel** 和 **invoke_type** 为可选参数,**建议默认使用系统自动推断**,除非有特殊需求再显式指定
439
410
  - 是否流式输出由公共参数 **stream** 控制,其他参数遵循对应服务商官方 SDK 的标准定义
440
411
  - **客户端连接管理**
441
412
  - gRPC 使用 HTTP/2 长连接,**建议将客户端实例作为单例使用**
442
- - 若需创建多个实例,**请务必调用** `client.close()` **方法手动关闭连接**,以防止连接堆积或资源泄露。
413
+ - 若需创建多个实例,**请务必调用** `client.close()` **方法手动关闭连接**,以防止连接堆积或资源泄露
443
414
  - **异常处理**:
444
- - 所有接口均提供详细的**错误信息** 以及 **请求ID(request_id)**,业务调用时建议纳入对应日志便于后期排错。
415
+ - 所有接口均提供详细的**错误信息** 以及 **请求ID(request_id)**,业务调用时建议纳入对应日志便于后期排错
445
416
 
446
417
  ## ⚙️ 环境变量配置(推荐)
447
418
 
@@ -495,9 +466,9 @@ MODEL_MANAGER_SERVER_GRPC_RETRY_DELAY=1.0
495
466
  加载后,初始化时无需传参:
496
467
 
497
468
  ```python
498
- from model_manager_client import ModelManagerClient
469
+ from tamar_model_client import TamarModelClient
499
470
 
500
- client = ModelManagerClient() # 将使用环境变量中的配置
471
+ client = TamarModelClient() # 将使用环境变量中的配置
501
472
  ```
502
473
 
503
474
  ## 开发
@@ -2,14 +2,14 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="tamar-model-client",
5
- version="0.1.1",
5
+ version="0.1.3",
6
6
  description="A Python SDK for interacting with the Model Manager gRPC service",
7
7
  author="Oscar Ou",
8
8
  author_email="oscar.ou@tamaredge.ai",
9
9
  packages=find_packages(),
10
10
  include_package_data=True, # 包含非 .py 文件
11
11
  package_data={
12
- "model_manager_client": ["generated/*.py"], # 包含 gRPC 生成文件
12
+ "tamar_model_client": ["generated/*.py"], # 包含 gRPC 生成文件
13
13
  },
14
14
  install_requires=[
15
15
  "grpcio",
@@ -1,10 +1,10 @@
1
- from .sync_client import ModelManagerClient
2
- from .async_client import AsyncModelManagerClient
1
+ from .sync_client import TamarModelClient
2
+ from .async_client import AsyncTamarModelClient
3
3
  from .exceptions import ModelManagerClientError, ConnectionError, ValidationError
4
4
 
5
5
  __all__ = [
6
- "ModelManagerClient",
7
- "AsyncModelManagerClient",
6
+ "TamarModelClient",
7
+ "AsyncTamarModelClient",
8
8
  "ModelManagerClientError",
9
9
  "ConnectionError",
10
10
  "ValidationError",
@@ -1,5 +1,6 @@
1
1
  import asyncio
2
2
  import atexit
3
+ import base64
3
4
  import json
4
5
  import logging
5
6
  import os
@@ -27,7 +28,73 @@ if not logging.getLogger().hasHandlers():
27
28
  logger = logging.getLogger(__name__)
28
29
 
29
30
 
30
- class AsyncModelManagerClient:
31
+ def is_effective_value(value) -> bool:
32
+ """
33
+ 递归判断value是否是有意义的有效值
34
+ """
35
+ if value is None or value is NOT_GIVEN:
36
+ return False
37
+
38
+ if isinstance(value, str):
39
+ return value.strip() != ""
40
+
41
+ if isinstance(value, bytes):
42
+ return len(value) > 0
43
+
44
+ if isinstance(value, dict):
45
+ for v in value.values():
46
+ if is_effective_value(v):
47
+ return True
48
+ return False
49
+
50
+ if isinstance(value, list):
51
+ for item in value:
52
+ if is_effective_value(item):
53
+ return True
54
+ return False
55
+
56
+ return True # 其他类型(int/float/bool)只要不是None就算有效
57
+
58
+
59
+ def serialize_value(value):
60
+ """递归处理单个值,处理BaseModel, dict, list, bytes"""
61
+ if not is_effective_value(value):
62
+ return None
63
+ if isinstance(value, BaseModel):
64
+ return serialize_value(value.model_dump())
65
+ if hasattr(value, "dict") and callable(value.dict):
66
+ return serialize_value(value.dict())
67
+ if isinstance(value, dict):
68
+ return {k: serialize_value(v) for k, v in value.items()}
69
+ if isinstance(value, list) or (isinstance(value, Iterable) and not isinstance(value, (str, bytes))):
70
+ return [serialize_value(v) for v in value]
71
+ if isinstance(value, bytes):
72
+ return f"bytes:{base64.b64encode(value).decode('utf-8')}"
73
+ return value
74
+
75
+
76
+ from typing import Any
77
+
78
+
79
+ def remove_none_from_dict(data: Any) -> Any:
80
+ """
81
+ 遍历 dict/list,递归删除 value 为 None 的字段
82
+ """
83
+ if isinstance(data, dict):
84
+ new_dict = {}
85
+ for key, value in data.items():
86
+ if value is None:
87
+ continue
88
+ cleaned_value = remove_none_from_dict(value)
89
+ new_dict[key] = cleaned_value
90
+ return new_dict
91
+ elif isinstance(data, list):
92
+ return [remove_none_from_dict(item) for item in data]
93
+ else:
94
+ return data
95
+
96
+
97
+ class AsyncTamarModelClient:
31
98
  def __init__(
32
99
  self,
33
100
  server_address: Optional[str] = None,
@@ -177,51 +244,15 @@ class AsyncModelManagerClient:
177
244
  if field in model_request_dict:
178
245
  value = model_request_dict[field]
179
246
 
180
- # Skip fields with NotGiven or None (unless explicitly allowed)
181
- if value is NOT_GIVEN or value is None:
247
+ # 跳过无效的值
248
+ if not is_effective_value(value):
182
249
  continue
183
250
 
184
- # 特别处理:如果是自定义的 BaseModel 或特定类型
185
- if isinstance(value, BaseModel):
186
- grpc_request_kwargs[field] = value.model_dump()
187
- # 如果是 OpenAI / Google 里的自定义对象,通常有 dict() 方法
188
- elif hasattr(value, "dict") and callable(value.dict):
189
- grpc_request_kwargs[field] = value.dict()
190
- # 如果是 list,需要处理里面元素也是自定义对象的情况
191
- elif isinstance(value, Iterable) and not isinstance(value, (str, bytes, dict)):
192
- new_list = []
193
- for item in value:
194
- if isinstance(item, BaseModel):
195
- new_list.append(item.model_dump())
196
- elif hasattr(item, "dict") and callable(item.dict):
197
- new_list.append(item.dict())
198
- elif isinstance(item, dict):
199
- # Handle nested dictionaries
200
- nested_dict = {}
201
- for k, v in item.items():
202
- if isinstance(v, BaseModel):
203
- nested_dict[k] = v.model_dump()
204
- elif hasattr(v, "dict") and callable(v.dict):
205
- nested_dict[k] = v.dict()
206
- else:
207
- nested_dict[k] = v
208
- new_list.append(nested_dict)
209
- else:
210
- new_list.append(item)
211
- grpc_request_kwargs[field] = new_list
212
- # 如果是 dict,同理处理内部元素
213
- elif isinstance(value, dict):
214
- new_dict = {}
215
- for k, v in value.items():
216
- if isinstance(v, BaseModel):
217
- new_dict[k] = v.model_dump()
218
- elif hasattr(v, "dict") and callable(v.dict):
219
- new_dict[k] = v.dict()
220
- else:
221
- new_dict[k] = v
222
- grpc_request_kwargs[field] = new_dict
223
- else:
224
- grpc_request_kwargs[field] = value
251
+ # 序列化grpc不支持的类型
252
+ grpc_request_kwargs[field] = serialize_value(value)
253
+
254
+ # 清理 serialize后的 grpc_request_kwargs
255
+ grpc_request_kwargs = remove_none_from_dict(grpc_request_kwargs)
225
256
 
226
257
  request = model_service_pb2.ModelRequestItem(
227
258
  provider=model_request.provider.value,
@@ -300,51 +331,15 @@ class AsyncModelManagerClient:
300
331
  if field in model_request_dict:
301
332
  value = model_request_dict[field]
302
333
 
303
- # Skip fields with NotGiven or None (unless explicitly allowed)
304
- if value is NOT_GIVEN or value is None:
334
+ # 跳过无效的值
335
+ if not is_effective_value(value):
305
336
  continue
306
337
 
307
- # 特别处理:如果是自定义的 BaseModel 或特定类型
308
- if isinstance(value, BaseModel):
309
- grpc_request_kwargs[field] = value.model_dump()
310
- # 如果是 OpenAI / Google 里的自定义对象,通常有 dict() 方法
311
- elif hasattr(value, "dict") and callable(value.dict):
312
- grpc_request_kwargs[field] = value.dict()
313
- # 如果是 list,需要处理里面元素也是自定义对象的情况
314
- elif isinstance(value, Iterable) and not isinstance(value, (str, bytes, dict)):
315
- new_list = []
316
- for item in value:
317
- if isinstance(item, BaseModel):
318
- new_list.append(item.model_dump())
319
- elif hasattr(item, "dict") and callable(item.dict):
320
- new_list.append(item.dict())
321
- elif isinstance(item, dict):
322
- # Handle nested dictionaries
323
- nested_dict = {}
324
- for k, v in item.items():
325
- if isinstance(v, BaseModel):
326
- nested_dict[k] = v.model_dump()
327
- elif hasattr(v, "dict") and callable(v.dict):
328
- nested_dict[k] = v.dict()
329
- else:
330
- nested_dict[k] = v
331
- new_list.append(nested_dict)
332
- else:
333
- new_list.append(item)
334
- grpc_request_kwargs[field] = new_list
335
- # 如果是 dict,同理处理内部元素
336
- elif isinstance(value, dict):
337
- new_dict = {}
338
- for k, v in value.items():
339
- if isinstance(v, BaseModel):
340
- new_dict[k] = v.model_dump()
341
- elif hasattr(v, "dict") and callable(v.dict):
342
- new_dict[k] = v.dict()
343
- else:
344
- new_dict[k] = v
345
- grpc_request_kwargs[field] = new_dict
346
- else:
347
- grpc_request_kwargs[field] = value
338
+ # 序列化grpc不支持的类型
339
+ grpc_request_kwargs[field] = serialize_value(value)
340
+
341
+ # 清理 serialize后的 grpc_request_kwargs
342
+ grpc_request_kwargs = remove_none_from_dict(grpc_request_kwargs)
348
343
 
349
344
  items.append(model_service_pb2.ModelRequestItem(
350
345
  provider=model_request_item.provider.value,
@@ -3,7 +3,7 @@
3
3
  import grpc
4
4
  import warnings
5
5
 
6
- import model_manager_client.generated.model_service_pb2 as model__service__pb2
6
+ import tamar_model_client.generated.model_service_pb2 as model__service__pb2
7
7
 
8
8
  GRPC_GENERATED_VERSION = '1.71.0'
9
9
  GRPC_VERSION = grpc.__version__
@@ -11,8 +11,8 @@ from openai.types.responses import ResponseInputParam, ResponseIncludable, Respo
11
11
  from pydantic import BaseModel, model_validator
12
12
  from typing import List, Optional, Union, Iterable, Dict, Literal
13
13
 
14
- from model_manager_client.enums import ProviderType, InvokeType
15
- from model_manager_client.enums.channel import Channel
14
+ from tamar_model_client.enums import ProviderType, InvokeType
15
+ from tamar_model_client.enums.channel import Channel
16
16
 
17
17
 
18
18
  class UserContext(BaseModel):
@@ -3,16 +3,16 @@ import atexit
3
3
  import logging
4
4
  from typing import Optional, Union, Iterator
5
5
 
6
- from .async_client import AsyncModelManagerClient
6
+ from .async_client import AsyncTamarModelClient
7
7
  from .schemas import ModelRequest, BatchModelRequest, ModelResponse, BatchModelResponse
8
8
 
9
9
  logger = logging.getLogger(__name__)
10
10
 
11
11
 
12
- class ModelManagerClient:
12
+ class TamarModelClient:
13
13
  """
14
14
  同步版本的模型管理客户端,用于非异步环境(如 Flask、Django、脚本)。
15
- 内部封装 AsyncModelManagerClient 并处理事件循环兼容性。
15
+ 内部封装 AsyncTamarModelClient 并处理事件循环兼容性。
16
16
  """
17
17
  _loop: Optional[asyncio.AbstractEventLoop] = None
18
18
 
@@ -27,16 +27,16 @@ class ModelManagerClient:
27
27
  retry_delay: float = 1.0,
28
28
  ):
29
29
  # 初始化全局事件循环,仅创建一次
30
- if not ModelManagerClient._loop:
30
+ if not TamarModelClient._loop:
31
31
  try:
32
- ModelManagerClient._loop = asyncio.get_running_loop()
32
+ TamarModelClient._loop = asyncio.get_running_loop()
33
33
  except RuntimeError:
34
- ModelManagerClient._loop = asyncio.new_event_loop()
35
- asyncio.set_event_loop(ModelManagerClient._loop)
34
+ TamarModelClient._loop = asyncio.new_event_loop()
35
+ asyncio.set_event_loop(TamarModelClient._loop)
36
36
 
37
- self._loop = ModelManagerClient._loop
37
+ self._loop = TamarModelClient._loop
38
38
 
39
- self._async_client = AsyncModelManagerClient(
39
+ self._async_client = AsyncTamarModelClient(
40
40
  server_address=server_address,
41
41
  jwt_secret_key=jwt_secret_key,
42
42
  jwt_token=jwt_token,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tamar-model-client
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: A Python SDK for interacting with the Model Manager gRPC service
5
5
  Home-page: http://gitlab.tamaredge.top/project-tap/AgentOS/model-manager-client
6
6
  Author: Oscar Ou
@@ -31,9 +31,9 @@ Dynamic: requires-dist
31
31
  Dynamic: requires-python
32
32
  Dynamic: summary
33
33
 
34
- # Model Manager Client
34
+ # Tamar Model Client
35
35
 
36
- **Model Manager Client** 是一款高性能的 Python SDK,用于连接 Model Manager gRPC 服务,统一调用多家第三方 AI
36
+ **Tamar Model Client** 是一款高性能的 Python SDK,用于连接 Model Manager gRPC 服务,统一调用多家第三方 AI
37
37
  模型服务商(如OpenAI、Google、Azure OpenAI)。
38
38
 
39
39
  ## ✨ 特性亮点
@@ -58,7 +58,7 @@ pip install tamar-model-client
58
58
  ## 🏗️ 项目结构概览
59
59
 
60
60
  ```
61
- model_manager_client/
61
+ tamar_model_client/
62
62
  ├── generated/ # gRPC 生成的代码
63
63
  │ ├── model_service.proto # 协议定义文件
64
64
  │ ├── model_service_pb2.py # 生成的 protobuf 代码
@@ -82,16 +82,16 @@ model_manager_client/
82
82
  ### 客户端初始化
83
83
 
84
84
  ```python
85
- from model_manager_client import ModelManagerClient, AsyncModelManagerClient
85
+ from tamar_model_client import TamarModelClient, AsyncTamarModelClient
86
86
 
87
87
  # 同步客户端
88
- client = ModelManagerClient(
88
+ client = TamarModelClient(
89
89
  server_address="localhost:50051",
90
90
  jwt_token="your-jwt-token"
91
91
  )
92
92
 
93
93
  # 异步客户端
94
- async_client = AsyncModelManagerClient(
94
+ async_client = AsyncTamarModelClient(
95
95
  server_address="localhost:50051",
96
96
  jwt_secret_key="your-jwt-secret-key" # 使用固定密钥自动生成 JWT
97
97
  )
@@ -105,12 +105,12 @@ async_client = AsyncModelManagerClient(
105
105
  #### OpenAI 调用示例
106
106
 
107
107
  ```python
108
- from model_manager_client import ModelManagerClient
109
- from model_manager_client.schemas import ModelRequest, UserContext
110
- from model_manager_client.enums import ProviderType, InvokeType, Channel
108
+ from tamar_model_client import TamarModelClient
109
+ from tamar_model_client.schemas import ModelRequest, UserContext
110
+ from tamar_model_client.enums import ProviderType, InvokeType, Channel
111
111
 
112
112
  # 创建同步客户端
113
- client = ModelManagerClient()
113
+ client = TamarModelClient()
114
114
 
115
115
  # OpenAI 调用示例
116
116
  request_data = ModelRequest(
@@ -144,12 +144,12 @@ else:
144
144
  #### Google 调用示例 (AI Studio / Vertex AI)
145
145
 
146
146
  ```python
147
- from model_manager_client import ModelManagerClient
148
- from model_manager_client.schemas import ModelRequest, UserContext
149
- from model_manager_client.enums import ProviderType, InvokeType, Channel
147
+ from tamar_model_client import TamarModelClient
148
+ from tamar_model_client.schemas import ModelRequest, UserContext
149
+ from tamar_model_client.enums import ProviderType, InvokeType, Channel
150
150
 
151
151
  # 创建同步客户端
152
- client = ModelManagerClient()
152
+ client = TamarModelClient()
153
153
 
154
154
  # Google AI Studio 调用示例
155
155
  request_data = ModelRequest(
@@ -207,12 +207,12 @@ else:
207
207
  #### Azure OpenAI 调用示例
208
208
 
209
209
  ```python
210
- from model_manager_client import ModelManagerClient
211
- from model_manager_client.schemas import ModelRequest, UserContext
212
- from model_manager_client.enums import ProviderType, InvokeType, Channel
210
+ from tamar_model_client import TamarModelClient
211
+ from tamar_model_client.schemas import ModelRequest, UserContext
212
+ from tamar_model_client.enums import ProviderType, InvokeType, Channel
213
213
 
214
214
  # 创建同步客户端
215
- client = ModelManagerClient()
215
+ client = TamarModelClient()
216
216
 
217
217
  # Azure OpenAI 调用示例
218
218
  request_data = ModelRequest(
@@ -247,14 +247,14 @@ else:
247
247
 
248
248
  ```python
249
249
  import asyncio
250
- from model_manager_client import AsyncModelManagerClient
251
- from model_manager_client.schemas import ModelRequest, UserContext
252
- from model_manager_client.enums import ProviderType, InvokeType, Channel
250
+ from tamar_model_client import AsyncTamarModelClient
251
+ from tamar_model_client.schemas import ModelRequest, UserContext
252
+ from tamar_model_client.enums import ProviderType, InvokeType, Channel
253
253
 
254
254
 
255
255
  async def main():
256
256
  # 创建异步客户端
257
- client = AsyncModelManagerClient()
257
+ client = AsyncTamarModelClient()
258
258
 
259
259
  # 组装请求参数
260
260
  request_data = ModelRequest(
@@ -293,14 +293,14 @@ asyncio.run(main())
293
293
 
294
294
  ```python
295
295
  import asyncio
296
- from model_manager_client import AsyncModelManagerClient
297
- from model_manager_client.schemas import ModelRequest, UserContext
298
- from model_manager_client.enums import ProviderType, InvokeType, Channel
296
+ from tamar_model_client import AsyncTamarModelClient
297
+ from tamar_model_client.schemas import ModelRequest, UserContext
298
+ from tamar_model_client.enums import ProviderType, InvokeType, Channel
299
299
 
300
300
 
301
301
  async def stream_example():
302
302
  # 创建异步客户端
303
- client = AsyncModelManagerClient()
303
+ client = AsyncTamarModelClient()
304
304
 
305
305
  # 组装请求参数
306
306
  request_data = ModelRequest(
@@ -340,17 +340,17 @@ asyncio.run(stream_example())
340
340
 
341
341
  ```python
342
342
  import asyncio
343
- from model_manager_client import AsyncModelManagerClient
344
- from model_manager_client.schemas import (
343
+ from tamar_model_client import AsyncTamarModelClient
344
+ from tamar_model_client.schemas import (
345
345
  BatchModelRequest, BatchModelRequestItem,
346
346
  UserContext
347
347
  )
348
- from model_manager_client.enums import ProviderType, InvokeType, Channel
348
+ from tamar_model_client.enums import ProviderType, InvokeType, Channel
349
349
 
350
350
 
351
351
  async def batch_example():
352
352
  # 创建异步客户端
353
- client = AsyncModelManagerClient()
353
+ client = AsyncTamarModelClient()
354
354
 
355
355
  # 组装批量请求参数
356
356
  batch_request = BatchModelRequest(
@@ -404,77 +404,48 @@ asyncio.run(batch_example())
404
404
 
405
405
  ### 文件输入示例
406
406
 
407
- 支持处理图像等文件输入(需使用支持多模态的模型,如 gpt-4-vision-preview):
407
+ 支持处理图像等文件输入(需使用支持多模态的模型,如 gemini-2.0-flash):
408
408
 
409
409
  ```python
410
- import asyncio
411
- from model_manager_client import AsyncModelManagerClient
412
- from model_manager_client.schemas import ModelRequest, UserContext
413
- from model_manager_client.enums import ProviderType, InvokeType, Channel
414
-
415
-
416
- async def file_input_example():
417
- # 创建异步客户端
418
- client = AsyncModelManagerClient()
419
-
420
- # 组装请求参数(包含文件输入)
421
- request_data = ModelRequest(
422
- provider=ProviderType.OPENAI,
423
- channel=Channel.OPENAI,
424
- invoke_type=InvokeType.CHAT_COMPLETIONS,
425
- model="gpt-4-vision-preview", # 使用支持图像的模型
426
- messages=[
427
- {
428
- "role": "user",
429
- "content": [
430
- {
431
- "type": "image_url",
432
- "image_url": {
433
- "url": "https://example.com/image.jpg"
434
- }
435
- },
436
- {
437
- "type": "text",
438
- "text": "请描述这张图片。"
439
- }
440
- ]
441
- }
442
- ],
443
- user_context=UserContext(
444
- user_id="test_user",
445
- org_id="test_org",
446
- client_type="python-sdk"
410
+ from tamar_model_client import TamarModelClient
411
+ from tamar_model_client.schemas import ModelRequest, UserContext
412
+ from tamar_model_client.enums import ProviderType
413
+ from google.genai.types import Part
414
+ model_request = ModelRequest(
415
+ provider=ProviderType.GOOGLE, # 选择 Google作为提供商
416
+ model="gemini-2.0-flash",
417
+ contents=[
418
+ "What is shown in this image?",
419
+ Part.from_uri( # 这个是Google那边的参数支持
420
+ file_uri="https://images.pexels.com/photos/248797/pexels-photo-248797.jpeg",
421
+ mime_type="image/jpeg",
447
422
  ),
448
- stream=False
449
- )
450
-
451
- # 发送请求并获取响应
452
- response = await client.invoke(request_data)
453
- if response.error:
454
- print(f"错误: {response.error}")
455
- else:
456
- print(f"响应: {response.content}")
457
- if response.usage:
458
- print(f"Token 使用情况: {response.usage}")
459
-
460
-
461
- # 运行文件输入示例
462
- asyncio.run(file_input_example())
423
+ ],
424
+ user_context=UserContext(
425
+ org_id="testllm",
426
+ user_id="testllm",
427
+ client_type="conversation-service"
428
+ ),
429
+ )
430
+ client = TamarModelClient("localhost:50051")
431
+ response = client.invoke(
432
+ model_request=model_request
433
+ )
463
434
  ```
464
435
 
465
436
  ### ⚠️ 注意事项
466
437
 
467
- 以下是使用 Model Manager Client 时的重要提示:
438
+ 以下是使用 Tamar Model Client 时的重要提示:
468
439
 
469
440
  - **参数处理**
470
- - 公共参数包括:**服务商 (provider)**、**渠道 (channel)** **调用方法 (invoke_type)**
441
+ - 公共参数包括:**服务商 (provider)**、**渠道 (channel)** **调用方法 (invoke_type)** 以及 **用户信息(user_context)**
471
442
  - 其中 **channel** 和 **invoke_type** 为可选参数,**建议默认使用系统自动推断**,除非有特殊需求再显式指定
472
443
  - 是否流式输出由公共参数 **stream** 控制,其他参数遵循对应服务商官方 SDK 的标准定义
473
444
  - **客户端连接管理**
474
445
  - gRPC 使用 HTTP/2 长连接,**建议将客户端实例作为单例使用**
475
- - 若需创建多个实例,**请务必调用** `client.close()` **方法手动关闭连接**,以防止连接堆积或资源泄露。
446
+ - 若需创建多个实例,**请务必调用** `client.close()` **方法手动关闭连接**,以防止连接堆积或资源泄露
476
447
  - **异常处理**:
477
- - 所有接口均提供详细的**错误信息** 以及 **请求ID(request_id)**,业务调用时建议纳入对应日志便于后期排错。
448
+ - 所有接口均提供详细的**错误信息** 以及 **请求ID(request_id)**,业务调用时建议纳入对应日志便于后期排错
478
449
 
479
450
  ## ⚙️ 环境变量配置(推荐)
480
451
 
@@ -528,9 +499,9 @@ MODEL_MANAGER_SERVER_GRPC_RETRY_DELAY=1.0
528
499
  加载后,初始化时无需传参:
529
500
 
530
501
  ```python
531
- from model_manager_client import ModelManagerClient
502
+ from tamar_model_client import TamarModelClient
532
503
 
533
- client = ModelManagerClient() # 将使用环境变量中的配置
504
+ client = TamarModelClient() # 将使用环境变量中的配置
534
505
  ```
535
506
 
536
507
  ## 开发
@@ -0,0 +1,22 @@
1
+ README.md
2
+ setup.py
3
+ tamar_model_client/__init__.py
4
+ tamar_model_client/async_client.py
5
+ tamar_model_client/auth.py
6
+ tamar_model_client/exceptions.py
7
+ tamar_model_client/sync_client.py
8
+ tamar_model_client.egg-info/PKG-INFO
9
+ tamar_model_client.egg-info/SOURCES.txt
10
+ tamar_model_client.egg-info/dependency_links.txt
11
+ tamar_model_client.egg-info/requires.txt
12
+ tamar_model_client.egg-info/top_level.txt
13
+ tamar_model_client/enums/__init__.py
14
+ tamar_model_client/enums/channel.py
15
+ tamar_model_client/enums/invoke.py
16
+ tamar_model_client/enums/providers.py
17
+ tamar_model_client/generated/__init__.py
18
+ tamar_model_client/generated/model_service_pb2.py
19
+ tamar_model_client/generated/model_service_pb2_grpc.py
20
+ tamar_model_client/schemas/__init__.py
21
+ tamar_model_client/schemas/inputs.py
22
+ tamar_model_client/schemas/outputs.py
@@ -0,0 +1 @@
1
+ tamar_model_client
@@ -1,22 +0,0 @@
1
- README.md
2
- setup.py
3
- model_manager_client/__init__.py
4
- model_manager_client/async_client.py
5
- model_manager_client/auth.py
6
- model_manager_client/exceptions.py
7
- model_manager_client/sync_client.py
8
- model_manager_client/enums/__init__.py
9
- model_manager_client/enums/channel.py
10
- model_manager_client/enums/invoke.py
11
- model_manager_client/enums/providers.py
12
- model_manager_client/generated/__init__.py
13
- model_manager_client/generated/model_service_pb2.py
14
- model_manager_client/generated/model_service_pb2_grpc.py
15
- model_manager_client/schemas/__init__.py
16
- model_manager_client/schemas/inputs.py
17
- model_manager_client/schemas/outputs.py
18
- tamar_model_client.egg-info/PKG-INFO
19
- tamar_model_client.egg-info/SOURCES.txt
20
- tamar_model_client.egg-info/dependency_links.txt
21
- tamar_model_client.egg-info/requires.txt
22
- tamar_model_client.egg-info/top_level.txt
@@ -1 +0,0 @@
1
- model_manager_client