tamar-model-client 0.1.10__py3-none-any.whl → 0.1.12__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 +40 -29
- tamar_model_client/schemas/inputs.py +1 -1
- {tamar_model_client-0.1.10.dist-info → tamar_model_client-0.1.12.dist-info}/METADATA +1 -1
- {tamar_model_client-0.1.10.dist-info → tamar_model_client-0.1.12.dist-info}/RECORD +6 -6
- {tamar_model_client-0.1.10.dist-info → tamar_model_client-0.1.12.dist-info}/WHEEL +0 -0
- {tamar_model_client-0.1.10.dist-info → tamar_model_client-0.1.12.dist-info}/top_level.txt +0 -0
@@ -179,14 +179,15 @@ class AsyncTamarModelClient:
|
|
179
179
|
logger.info(f"✅ gRPC channel initialized to {self.server_address}")
|
180
180
|
return
|
181
181
|
except grpc.FutureTimeoutError as e:
|
182
|
-
logger.
|
182
|
+
logger.error(f"❌ gRPC channel initialization timed out: {str(e)}", exc_info=True)
|
183
183
|
except grpc.RpcError as e:
|
184
|
-
logger.
|
184
|
+
logger.error(f"❌ gRPC channel initialization failed: {str(e)}", exc_info=True)
|
185
185
|
except Exception as e:
|
186
|
-
logger.
|
186
|
+
logger.error(f"❌ Unexpected error during channel initialization: {str(e)}", exc_info=True)
|
187
187
|
|
188
188
|
retry_count += 1
|
189
189
|
if retry_count > self.max_retries:
|
190
|
+
logger.error(f"❌ Failed to initialize gRPC channel after {self.max_retries} retries.", exc_info=True)
|
190
191
|
raise ConnectionError(f"❌ Failed to initialize gRPC channel after {self.max_retries} retries.")
|
191
192
|
|
192
193
|
# 指数退避:延迟时间 = retry_delay * (2 ^ (retry_count - 1))
|
@@ -195,18 +196,13 @@ class AsyncTamarModelClient:
|
|
195
196
|
await asyncio.sleep(delay)
|
196
197
|
|
197
198
|
async def _stream(self, model_request, metadata, invoke_timeout) -> AsyncIterator[ModelResponse]:
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
)
|
206
|
-
except grpc.RpcError as e:
|
207
|
-
raise ConnectionError(f"gRPC call failed: {str(e)}")
|
208
|
-
except Exception as e:
|
209
|
-
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
|
+
)
|
210
206
|
|
211
207
|
async def invoke(self, model_request: ModelRequest, timeout: Optional[float] = None) -> Union[
|
212
208
|
ModelResponse, AsyncIterator[ModelResponse]]:
|
@@ -284,19 +280,28 @@ class AsyncTamarModelClient:
|
|
284
280
|
|
285
281
|
metadata = self._build_auth_metadata()
|
286
282
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
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
|
300
305
|
|
301
306
|
async def invoke_batch(self, batch_request_model: BatchModelRequest, timeout: Optional[float] = None) -> \
|
302
307
|
BatchModelResponse:
|
@@ -399,7 +404,13 @@ class AsyncTamarModelClient:
|
|
399
404
|
responses=result
|
400
405
|
)
|
401
406
|
except grpc.RpcError as e:
|
402
|
-
|
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
|
403
414
|
|
404
415
|
async def close(self):
|
405
416
|
"""关闭 gRPC 通道"""
|
@@ -301,7 +301,7 @@ class BatchModelRequestItem(ModelRequestInput):
|
|
301
301
|
def validate_by_provider_and_invoke_type(self) -> "BatchModelRequestItem":
|
302
302
|
"""根据 provider 和 invoke_type 动态校验具体输入模型字段。"""
|
303
303
|
# 动态获取 allowed fields
|
304
|
-
base_allowed = {"provider", "channel", "invoke_type", "user_context"}
|
304
|
+
base_allowed = {"provider", "channel", "invoke_type", "user_context", "custom_id"}
|
305
305
|
google_allowed = base_allowed | set(GoogleGenAiInput.model_fields.keys())
|
306
306
|
openai_responses_allowed = base_allowed | set(OpenAIResponsesInput.model_fields.keys())
|
307
307
|
openai_chat_allowed = base_allowed | set(OpenAIChatCompletionsInput.model_fields.keys())
|
@@ -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
|
@@ -26,9 +26,9 @@ tamar_model_client/generated/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NM
|
|
26
26
|
tamar_model_client/generated/model_service_pb2.py,sha256=RI6wNSmgmylzWPedFfPxx938UzS7kcPR58YTzYshcL8,3066
|
27
27
|
tamar_model_client/generated/model_service_pb2_grpc.py,sha256=k4tIbp3XBxdyuOVR18Ung_4SUryONB51UYf_uUEl6V4,5145
|
28
28
|
tamar_model_client/schemas/__init__.py,sha256=AxuI-TcvA4OMTj2FtK4wAItvz9LrK_293pu3cmMLE7k,394
|
29
|
-
tamar_model_client/schemas/inputs.py,sha256=
|
29
|
+
tamar_model_client/schemas/inputs.py,sha256=ZqaBek2nluRhDqdXmetEvJRc2wKNxZZDCxPeng5KiIw,18734
|
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.12.dist-info/METADATA,sha256=_1A8XLUsZuPbCeuuQukzMOE7IeizM6jX3s2N4-viwJM,16566
|
32
|
+
tamar_model_client-0.1.12.dist-info/WHEEL,sha256=ck4Vq1_RXyvS4Jt6SI0Vz6fyVs4GWg7AINwpsaGEgPE,91
|
33
|
+
tamar_model_client-0.1.12.dist-info/top_level.txt,sha256=_LfDhPv_fvON0PoZgQuo4M7EjoWtxPRoQOBJziJmip8,19
|
34
|
+
tamar_model_client-0.1.12.dist-info/RECORD,,
|
File without changes
|
File without changes
|