tamar-model-client 0.1.9__py3-none-any.whl → 0.1.11__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.
- tamar_model_client/async_client.py +41 -29
- {tamar_model_client-0.1.9.dist-info → tamar_model_client-0.1.11.dist-info}/METADATA +8 -1
- {tamar_model_client-0.1.9.dist-info → tamar_model_client-0.1.11.dist-info}/RECORD +5 -5
- {tamar_model_client-0.1.9.dist-info → tamar_model_client-0.1.11.dist-info}/WHEEL +0 -0
- {tamar_model_client-0.1.9.dist-info → tamar_model_client-0.1.11.dist-info}/top_level.txt +0 -0
@@ -153,6 +153,7 @@ class AsyncTamarModelClient:
|
|
153
153
|
options = [
|
154
154
|
('grpc.max_send_message_length', MAX_MESSAGE_LENGTH),
|
155
155
|
('grpc.max_receive_message_length', MAX_MESSAGE_LENGTH),
|
156
|
+
('grpc.keepalive_permit_without_calls', True) # 即使没有活跃请求也保持连接
|
156
157
|
]
|
157
158
|
if self.default_authority:
|
158
159
|
options.append(("grpc.default_authority", self.default_authority))
|
@@ -178,14 +179,15 @@ class AsyncTamarModelClient:
|
|
178
179
|
logger.info(f"✅ gRPC channel initialized to {self.server_address}")
|
179
180
|
return
|
180
181
|
except grpc.FutureTimeoutError as e:
|
181
|
-
logger.
|
182
|
+
logger.error(f"❌ gRPC channel initialization timed out: {str(e)}", exc_info=True)
|
182
183
|
except grpc.RpcError as e:
|
183
|
-
logger.
|
184
|
+
logger.error(f"❌ gRPC channel initialization failed: {str(e)}", exc_info=True)
|
184
185
|
except Exception as e:
|
185
|
-
logger.
|
186
|
+
logger.error(f"❌ Unexpected error during channel initialization: {str(e)}", exc_info=True)
|
186
187
|
|
187
188
|
retry_count += 1
|
188
189
|
if retry_count > self.max_retries:
|
190
|
+
logger.error(f"❌ Failed to initialize gRPC channel after {self.max_retries} retries.", exc_info=True)
|
189
191
|
raise ConnectionError(f"❌ Failed to initialize gRPC channel after {self.max_retries} retries.")
|
190
192
|
|
191
193
|
# 指数退避:延迟时间 = retry_delay * (2 ^ (retry_count - 1))
|
@@ -194,18 +196,13 @@ class AsyncTamarModelClient:
|
|
194
196
|
await asyncio.sleep(delay)
|
195
197
|
|
196
198
|
async def _stream(self, model_request, metadata, invoke_timeout) -> AsyncIterator[ModelResponse]:
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
)
|
205
|
-
except grpc.RpcError as e:
|
206
|
-
raise ConnectionError(f"gRPC call failed: {str(e)}")
|
207
|
-
except Exception as e:
|
208
|
-
raise ValidationError(f"Invalid input: {str(e)}")
|
199
|
+
async for response in self.stub.Invoke(model_request, metadata=metadata, timeout=invoke_timeout):
|
200
|
+
yield ModelResponse(
|
201
|
+
content=response.content,
|
202
|
+
usage=json.loads(response.usage) if response.usage else None,
|
203
|
+
raw_response=json.loads(response.raw_response) if response.raw_response else None,
|
204
|
+
error=response.error or None,
|
205
|
+
)
|
209
206
|
|
210
207
|
async def invoke(self, model_request: ModelRequest, timeout: Optional[float] = None) -> Union[
|
211
208
|
ModelResponse, AsyncIterator[ModelResponse]]:
|
@@ -283,19 +280,28 @@ class AsyncTamarModelClient:
|
|
283
280
|
|
284
281
|
metadata = self._build_auth_metadata()
|
285
282
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
283
|
+
try:
|
284
|
+
invoke_timeout = timeout or self.default_invoke_timeout
|
285
|
+
if model_request.stream:
|
286
|
+
return self._stream(request, metadata, invoke_timeout)
|
287
|
+
else:
|
288
|
+
async for response in self.stub.Invoke(request, metadata=metadata, timeout=invoke_timeout):
|
289
|
+
return ModelResponse(
|
290
|
+
content=response.content,
|
291
|
+
usage=json.loads(response.usage) if response.usage else None,
|
292
|
+
raw_response=json.loads(response.raw_response) if response.raw_response else None,
|
293
|
+
error=response.error or None,
|
294
|
+
custom_id=None,
|
295
|
+
request_id=response.request_id if response.request_id else None,
|
296
|
+
)
|
297
|
+
except grpc.RpcError as e:
|
298
|
+
error_message = f"❌ Invoke gRPC failed: {str(e)}"
|
299
|
+
logger.error(error_message, exc_info=True)
|
300
|
+
raise e
|
301
|
+
except Exception as e:
|
302
|
+
error_message = f"❌ Invoke other error: {str(e)}"
|
303
|
+
logger.error(error_message, exc_info=True)
|
304
|
+
raise e
|
299
305
|
|
300
306
|
async def invoke_batch(self, batch_request_model: BatchModelRequest, timeout: Optional[float] = None) -> \
|
301
307
|
BatchModelResponse:
|
@@ -398,7 +404,13 @@ class AsyncTamarModelClient:
|
|
398
404
|
responses=result
|
399
405
|
)
|
400
406
|
except grpc.RpcError as e:
|
401
|
-
|
407
|
+
error_message = f"❌ BatchInvoke gRPC failed: {str(e)}"
|
408
|
+
logger.error(error_message, exc_info=True)
|
409
|
+
raise e
|
410
|
+
except Exception as e:
|
411
|
+
error_message = f"❌ BatchInvoke other error: {str(e)}"
|
412
|
+
logger.error(error_message, exc_info=True)
|
413
|
+
raise e
|
402
414
|
|
403
415
|
async def close(self):
|
404
416
|
"""关闭 gRPC 通道"""
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: tamar-model-client
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.11
|
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
|
@@ -528,6 +528,13 @@ pip install -e .
|
|
528
528
|
python make_grpc.py
|
529
529
|
```
|
530
530
|
|
531
|
+
### 部署到 pip
|
532
|
+
```bash
|
533
|
+
python setup.py sdist bdist_wheel
|
534
|
+
twine check dist/*
|
535
|
+
|
536
|
+
```
|
537
|
+
|
531
538
|
## 许可证
|
532
539
|
|
533
540
|
MIT License
|
@@ -14,7 +14,7 @@ model_manager_client/schemas/__init__.py,sha256=AxuI-TcvA4OMTj2FtK4wAItvz9LrK_29
|
|
14
14
|
model_manager_client/schemas/inputs.py,sha256=3HUxnbuyQbuvMz1C46zydFYz-iEvLAUWVzOx7-eKS_I,14338
|
15
15
|
model_manager_client/schemas/outputs.py,sha256=M_fcqUtXPJnfiLabHlyA8BorlC5pYkf5KLjXO1ysKIQ,1031
|
16
16
|
tamar_model_client/__init__.py,sha256=LMECAuDARWHV1XzH3msoDXcyurS2eihRQmBy26_PUE0,328
|
17
|
-
tamar_model_client/async_client.py,sha256=
|
17
|
+
tamar_model_client/async_client.py,sha256=gmZ2xMHO_F-Vtg3OK7B_yf-gtI-WH2NU2LzC6YO_t7k,19649
|
18
18
|
tamar_model_client/auth.py,sha256=gbwW5Aakeb49PMbmYvrYlVx1mfyn1LEDJ4qQVs-9DA4,438
|
19
19
|
tamar_model_client/exceptions.py,sha256=jYU494OU_NeIa4X393V-Y73mTNm0JZ9yZApnlOM9CJQ,332
|
20
20
|
tamar_model_client/sync_client.py,sha256=o8b20fQUvtMq1gWax3_dfOpputYT4l9pRTz6cHdB0lg,4006
|
@@ -28,7 +28,7 @@ tamar_model_client/generated/model_service_pb2_grpc.py,sha256=k4tIbp3XBxdyuOVR18
|
|
28
28
|
tamar_model_client/schemas/__init__.py,sha256=AxuI-TcvA4OMTj2FtK4wAItvz9LrK_293pu3cmMLE7k,394
|
29
29
|
tamar_model_client/schemas/inputs.py,sha256=Y9zzt-RoRklkxxe_3VJbZvPghJ00KUjHtFUmD0pCdHs,18721
|
30
30
|
tamar_model_client/schemas/outputs.py,sha256=M_fcqUtXPJnfiLabHlyA8BorlC5pYkf5KLjXO1ysKIQ,1031
|
31
|
-
tamar_model_client-0.1.
|
32
|
-
tamar_model_client-0.1.
|
33
|
-
tamar_model_client-0.1.
|
34
|
-
tamar_model_client-0.1.
|
31
|
+
tamar_model_client-0.1.11.dist-info/METADATA,sha256=Ia4eGAZVs3vebAQxIENipL-XfJ7_CXWag4OwFU3V5GA,16566
|
32
|
+
tamar_model_client-0.1.11.dist-info/WHEEL,sha256=ck4Vq1_RXyvS4Jt6SI0Vz6fyVs4GWg7AINwpsaGEgPE,91
|
33
|
+
tamar_model_client-0.1.11.dist-info/top_level.txt,sha256=_LfDhPv_fvON0PoZgQuo4M7EjoWtxPRoQOBJziJmip8,19
|
34
|
+
tamar_model_client-0.1.11.dist-info/RECORD,,
|
File without changes
|
File without changes
|