sapiopycommons 2025.7.22a637__py3-none-any.whl → 2025.7.22a639__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.
Potentially problematic release.
This version of sapiopycommons might be problematic. Click here for more details.
- sapiopycommons/ai/test_client.py +1 -1
- sapiopycommons/ai/tool_service_base.py +22 -30
- {sapiopycommons-2025.7.22a637.dist-info → sapiopycommons-2025.7.22a639.dist-info}/METADATA +1 -1
- {sapiopycommons-2025.7.22a637.dist-info → sapiopycommons-2025.7.22a639.dist-info}/RECORD +6 -6
- {sapiopycommons-2025.7.22a637.dist-info → sapiopycommons-2025.7.22a639.dist-info}/WHEEL +0 -0
- {sapiopycommons-2025.7.22a637.dist-info → sapiopycommons-2025.7.22a639.dist-info}/licenses/LICENSE +0 -0
sapiopycommons/ai/test_client.py
CHANGED
|
@@ -110,7 +110,7 @@ class TestClient:
|
|
|
110
110
|
self.connection.secret_type = SapioUserSecretTypePbo.PASSWORD
|
|
111
111
|
self.connection.secret = "Basic " + base64.b64encode(f'{user.username}:{user.password}'.encode()).decode()
|
|
112
112
|
else:
|
|
113
|
-
self.connection.secret_type = SapioUserSecretTypePbo.
|
|
113
|
+
self.connection.secret_type = SapioUserSecretTypePbo.SESSION_TOKEN
|
|
114
114
|
self.connection.secret = user.api_token if user and user.api_token else "test_api_token"
|
|
115
115
|
|
|
116
116
|
def add_binary_input(self, input_data: list[bytes]) -> None:
|
|
@@ -200,8 +200,10 @@ class ToolServiceBase(ToolServiceServicer, ABC):
|
|
|
200
200
|
try:
|
|
201
201
|
# Get the tool details from the registered tools.
|
|
202
202
|
details: list[ToolDetailsPbo] = []
|
|
203
|
-
for tool in self.
|
|
204
|
-
details.append(tool.to_pbo())
|
|
203
|
+
for tool in self.register_tools():
|
|
204
|
+
details.append(tool().to_pbo())
|
|
205
|
+
if not details:
|
|
206
|
+
raise Exception("No tools registered with this service.")
|
|
205
207
|
return ToolDetailsResponsePbo(tool_framework_version=self.tool_version(), tool_details=details)
|
|
206
208
|
except Exception:
|
|
207
209
|
# Woe to you if you somehow cause an exception to be raised when just initializing your tools.
|
|
@@ -274,15 +276,6 @@ class ToolServiceBase(ToolServiceServicer, ABC):
|
|
|
274
276
|
"""
|
|
275
277
|
pass
|
|
276
278
|
|
|
277
|
-
def _initialize_tools(self) -> list[ToolBase]:
|
|
278
|
-
"""
|
|
279
|
-
return: Get instances of the tools registered with this service.
|
|
280
|
-
"""
|
|
281
|
-
tools: list[ToolBase] = [x() for x in self.register_tools()]
|
|
282
|
-
if not tools:
|
|
283
|
-
raise Exception("No tools registered with this service.")
|
|
284
|
-
return tools
|
|
285
|
-
|
|
286
279
|
def run(self, user: SapioUser, request: ProcessStepRequestPbo, context: ServicerContext) \
|
|
287
280
|
-> tuple[bool, str, list[SapioToolResult], list[str]]:
|
|
288
281
|
"""
|
|
@@ -297,9 +290,9 @@ class ToolServiceBase(ToolServiceServicer, ABC):
|
|
|
297
290
|
"""
|
|
298
291
|
# Locate the tool named in the request.
|
|
299
292
|
tool: ToolBase | None = None
|
|
300
|
-
for t in self.
|
|
301
|
-
if t.name == request.tool_name:
|
|
302
|
-
tool = t
|
|
293
|
+
for t in self.register_tools():
|
|
294
|
+
if t.name() == request.tool_name:
|
|
295
|
+
tool = t()
|
|
303
296
|
break
|
|
304
297
|
if not tool:
|
|
305
298
|
return False, f"Tool \"{request.tool_name}\" not found in the registered tools for this service.", [], []
|
|
@@ -319,7 +312,7 @@ class ToolServiceBase(ToolServiceServicer, ABC):
|
|
|
319
312
|
elif success:
|
|
320
313
|
results = tool.run(user)
|
|
321
314
|
# Update the status message to reflect the successful execution of the tool.
|
|
322
|
-
msg = f"{tool.name} successfully completed."
|
|
315
|
+
msg = f"{tool.name()} successfully completed."
|
|
323
316
|
return success, msg, results, tool.logs
|
|
324
317
|
except Exception as e:
|
|
325
318
|
tool.log_exception("Exception occurred during tool execution.", e)
|
|
@@ -330,9 +323,9 @@ class ToolBase(ABC):
|
|
|
330
323
|
"""
|
|
331
324
|
A base class for implementing a tool.
|
|
332
325
|
"""
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
326
|
+
_name: str
|
|
327
|
+
_description: str
|
|
328
|
+
_data_type_name: str | None
|
|
336
329
|
inputs: list[ToolInputDetailsPbo]
|
|
337
330
|
outputs: list[ToolOutputDetailsPbo]
|
|
338
331
|
configs: list[VeloxFieldDefPbo]
|
|
@@ -362,7 +355,6 @@ class ToolBase(ABC):
|
|
|
362
355
|
pass
|
|
363
356
|
|
|
364
357
|
@staticmethod
|
|
365
|
-
@abstractmethod
|
|
366
358
|
def data_type_name() -> str | None:
|
|
367
359
|
"""
|
|
368
360
|
:return: The name of the output data type of this tool, if applicable. When this tool returns
|
|
@@ -371,14 +363,14 @@ class ToolBase(ABC):
|
|
|
371
363
|
return None
|
|
372
364
|
|
|
373
365
|
def __init__(self):
|
|
374
|
-
self.
|
|
375
|
-
self.
|
|
376
|
-
self.
|
|
366
|
+
self._name = self.name()
|
|
367
|
+
self._description = self.description()
|
|
368
|
+
self._data_type_name = self.data_type_name()
|
|
377
369
|
self.inputs = []
|
|
378
370
|
self.outputs = []
|
|
379
371
|
self.configs = []
|
|
380
372
|
self.logs = []
|
|
381
|
-
self.logger = logging.getLogger(f"ToolBase.{self.
|
|
373
|
+
self.logger = logging.getLogger(f"ToolBase.{self._name}")
|
|
382
374
|
ensure_logger_initialized(self.logger)
|
|
383
375
|
|
|
384
376
|
def setup(self, user: SapioUser, request: ProcessStepRequestPbo, context: ServicerContext) -> None:
|
|
@@ -673,11 +665,11 @@ class ToolBase(ABC):
|
|
|
673
665
|
:return: The ToolDetailsPbo proto object representing this tool.
|
|
674
666
|
"""
|
|
675
667
|
return ToolDetailsPbo(
|
|
676
|
-
name=self.
|
|
677
|
-
description=self.
|
|
668
|
+
name=self._name,
|
|
669
|
+
description=self._description,
|
|
678
670
|
input_configs=self.inputs,
|
|
679
671
|
output_configs=self.outputs,
|
|
680
|
-
output_data_type_name=self.
|
|
672
|
+
output_data_type_name=self._data_type_name,
|
|
681
673
|
config_fields=self.configs
|
|
682
674
|
)
|
|
683
675
|
|
|
@@ -771,7 +763,7 @@ class ToolBase(ABC):
|
|
|
771
763
|
if not message:
|
|
772
764
|
return
|
|
773
765
|
if self.verbose_logging:
|
|
774
|
-
self.logs.append(f"INFO: {self.
|
|
766
|
+
self.logs.append(f"INFO: {self._name}: {message}")
|
|
775
767
|
self.logger.info(message)
|
|
776
768
|
|
|
777
769
|
def log_warning(self, message: str) -> None:
|
|
@@ -783,7 +775,7 @@ class ToolBase(ABC):
|
|
|
783
775
|
"""
|
|
784
776
|
if not message:
|
|
785
777
|
return
|
|
786
|
-
self.logs.append(f"WARNING: {self.
|
|
778
|
+
self.logs.append(f"WARNING: {self._name}: {message}")
|
|
787
779
|
self.logger.warning(message)
|
|
788
780
|
|
|
789
781
|
def log_error(self, message: str) -> None:
|
|
@@ -795,7 +787,7 @@ class ToolBase(ABC):
|
|
|
795
787
|
"""
|
|
796
788
|
if not message:
|
|
797
789
|
return
|
|
798
|
-
self.logs.append(f"ERROR: {self.
|
|
790
|
+
self.logs.append(f"ERROR: {self._name}: {message}")
|
|
799
791
|
self.logger.error(message)
|
|
800
792
|
|
|
801
793
|
def log_exception(self, message: str, e: Exception) -> None:
|
|
@@ -808,7 +800,7 @@ class ToolBase(ABC):
|
|
|
808
800
|
"""
|
|
809
801
|
if not message and not e:
|
|
810
802
|
return
|
|
811
|
-
self.logs.append(f"EXCEPTION: {self.
|
|
803
|
+
self.logs.append(f"EXCEPTION: {self._name}: {message} - {e}")
|
|
812
804
|
self.logger.error(f"{message}\n{traceback.format_exc()}")
|
|
813
805
|
|
|
814
806
|
def get_input_binary(self, index: int = 0) -> list[bytes]:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: sapiopycommons
|
|
3
|
-
Version: 2025.7.
|
|
3
|
+
Version: 2025.7.22a639
|
|
4
4
|
Summary: Official Sapio Python API Utilities Package
|
|
5
5
|
Project-URL: Homepage, https://github.com/sapiosciences
|
|
6
6
|
Author-email: Jonathan Steck <jsteck@sapiosciences.com>, Yechen Qiao <yqiao@sapiosciences.com>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
sapiopycommons/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
sapiopycommons/ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
3
|
sapiopycommons/ai/protobuf_utils.py,sha256=8VYGhAdD731Ojy5PTy61PlTcvfEdydkIdX-4rOFPtxM,24911
|
|
4
|
-
sapiopycommons/ai/test_client.py,sha256=
|
|
5
|
-
sapiopycommons/ai/tool_service_base.py,sha256=
|
|
4
|
+
sapiopycommons/ai/test_client.py,sha256=d5P01dUNRKpEgTENZQoIHUvPE0nEut5D9upT5txQWB8,11173
|
|
5
|
+
sapiopycommons/ai/tool_service_base.py,sha256=OtiTiv-n6EpSFxZYwe_OjdUucU0Pu0EfQ6BYJmShZfE,41651
|
|
6
6
|
sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2.py,sha256=YcZjb_YM-XeLErM8hEC_S7vGMVGvcXAMGs2b-u5zvOE,2377
|
|
7
7
|
sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2.pyi,sha256=FwtXmNAf7iYGEFm4kbqb04v77jNHbZg18ZmEDhle_bU,1444
|
|
8
8
|
sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2_grpc.py,sha256=wPImJPdCUZNVEVoUWzsba9kGIXjEKPdUkawP5SnVyiU,932
|
|
@@ -90,7 +90,7 @@ sapiopycommons/webhook/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3
|
|
|
90
90
|
sapiopycommons/webhook/webhook_context.py,sha256=D793uLsb1691SalaPnBUk3rOSxn_hYLhdvkaIxjNXss,1909
|
|
91
91
|
sapiopycommons/webhook/webhook_handlers.py,sha256=7o_wXOruhT9auNh8OfhJAh4WhhiPKij67FMBSpGPICc,39939
|
|
92
92
|
sapiopycommons/webhook/webservice_handlers.py,sha256=tyaYGG1-v_JJrJHZ6cy5mGCxX9z1foLw7pM4MDJlFxs,14297
|
|
93
|
-
sapiopycommons-2025.7.
|
|
94
|
-
sapiopycommons-2025.7.
|
|
95
|
-
sapiopycommons-2025.7.
|
|
96
|
-
sapiopycommons-2025.7.
|
|
93
|
+
sapiopycommons-2025.7.22a639.dist-info/METADATA,sha256=EhxAxl41sKcLAMYPPcoxCB4xgtbAZJZ1by3HAv_n5mE,3143
|
|
94
|
+
sapiopycommons-2025.7.22a639.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
|
95
|
+
sapiopycommons-2025.7.22a639.dist-info/licenses/LICENSE,sha256=HyVuytGSiAUQ6ErWBHTqt1iSGHhLmlC8fO7jTCuR8dU,16725
|
|
96
|
+
sapiopycommons-2025.7.22a639.dist-info/RECORD,,
|
|
File without changes
|
{sapiopycommons-2025.7.22a637.dist-info → sapiopycommons-2025.7.22a639.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|