sapiopycommons 2025.4.24a495__py3-none-any.whl → 2025.4.25a497__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/tool_service_base.py +164 -2
- {sapiopycommons-2025.4.24a495.dist-info → sapiopycommons-2025.4.25a497.dist-info}/METADATA +1 -1
- {sapiopycommons-2025.4.24a495.dist-info → sapiopycommons-2025.4.25a497.dist-info}/RECORD +5 -5
- {sapiopycommons-2025.4.24a495.dist-info → sapiopycommons-2025.4.25a497.dist-info}/WHEEL +0 -0
- {sapiopycommons-2025.4.24a495.dist-info → sapiopycommons-2025.4.25a497.dist-info}/licenses/LICENSE +0 -0
|
@@ -7,7 +7,8 @@ from typing import Any
|
|
|
7
7
|
|
|
8
8
|
from grpc import ServicerContext
|
|
9
9
|
|
|
10
|
-
from sapiopycommons.ai.api.fielddefinitions.proto.velox_field_def_pb2 import VeloxFieldDefProto
|
|
10
|
+
from sapiopycommons.ai.api.fielddefinitions.proto.velox_field_def_pb2 import VeloxFieldDefProto, FieldTypeProto, \
|
|
11
|
+
IntegerProperties, DoubleProperties, SelectionProperties, BooleanProperties
|
|
11
12
|
from sapiopycommons.general.aliases import FieldMap
|
|
12
13
|
from sapiopylib.rest.User import SapioUser
|
|
13
14
|
|
|
@@ -359,6 +360,110 @@ class ToolBase(ABC):
|
|
|
359
360
|
"""
|
|
360
361
|
self.configs.append(field)
|
|
361
362
|
|
|
363
|
+
def add_integer_config_field(self, field_name: str, display_name: str, description: str,
|
|
364
|
+
default_value: int, min_value: int = -2**31, max_value: int = 2**31-1) -> None:
|
|
365
|
+
"""
|
|
366
|
+
Add an integer configuration field to the tool. This field will be used to configure the tool in the plan
|
|
367
|
+
manager.
|
|
368
|
+
|
|
369
|
+
:param field_name: The name of the field.
|
|
370
|
+
:param display_name: The display name of the field.
|
|
371
|
+
:param description: The description of the field.
|
|
372
|
+
:param default_value: The default value of the field.
|
|
373
|
+
:param min_value: The minimum value of the field.
|
|
374
|
+
:param max_value: The maximum value of the field.
|
|
375
|
+
"""
|
|
376
|
+
self.configs.append(VeloxFieldDefProto(
|
|
377
|
+
data_field_type=FieldTypeProto.INTEGER,
|
|
378
|
+
data_field_name=field_name,
|
|
379
|
+
display_name=display_name,
|
|
380
|
+
description=description,
|
|
381
|
+
required=True,
|
|
382
|
+
editable=True,
|
|
383
|
+
integer_properties=IntegerProperties(
|
|
384
|
+
default_value=default_value,
|
|
385
|
+
min_value=min_value,
|
|
386
|
+
max_value=max_value
|
|
387
|
+
)
|
|
388
|
+
))
|
|
389
|
+
|
|
390
|
+
def add_double_config_field(self, field_name: str, display_name: str, description: str, default_value: float,
|
|
391
|
+
min_value: float = -10.**120, max_value: float = 10.**120, precision: int = 2) -> None:
|
|
392
|
+
"""
|
|
393
|
+
Add a double configuration field to the tool. This field will be used to configure the tool in the plan
|
|
394
|
+
manager.
|
|
395
|
+
|
|
396
|
+
:param field_name: The name of the field.
|
|
397
|
+
:param display_name: The display name of the field.
|
|
398
|
+
:param description: The description of the field.
|
|
399
|
+
:param default_value: The default value of the field.
|
|
400
|
+
:param min_value: The minimum value of the field.
|
|
401
|
+
:param max_value: The maximum value of the field.
|
|
402
|
+
:param precision: The precision of the field.
|
|
403
|
+
"""
|
|
404
|
+
self.configs.append(VeloxFieldDefProto(
|
|
405
|
+
data_field_type=FieldTypeProto.DOUBLE,
|
|
406
|
+
data_field_name=field_name,
|
|
407
|
+
display_name=display_name,
|
|
408
|
+
description=description,
|
|
409
|
+
required=True,
|
|
410
|
+
editable=True,
|
|
411
|
+
double_properties=DoubleProperties(
|
|
412
|
+
default_value=default_value,
|
|
413
|
+
min_value=min_value,
|
|
414
|
+
max_value=max_value,
|
|
415
|
+
precision=precision
|
|
416
|
+
)
|
|
417
|
+
))
|
|
418
|
+
|
|
419
|
+
def add_list_config_field(self, field_name: str, display_name: str, description: str, default_value: str,
|
|
420
|
+
allowed_values: list[str]) -> None:
|
|
421
|
+
"""
|
|
422
|
+
Add a list configuration field to the tool. This field will be used to configure the tool in the plan
|
|
423
|
+
manager.
|
|
424
|
+
|
|
425
|
+
:param field_name: The name of the field.
|
|
426
|
+
:param display_name: The display name of the field.
|
|
427
|
+
:param description: The description of the field.
|
|
428
|
+
:param default_value: The default value of the field.
|
|
429
|
+
:param allowed_values: The list of allowed values for the field.
|
|
430
|
+
"""
|
|
431
|
+
self.configs.append(VeloxFieldDefProto(
|
|
432
|
+
data_field_type=FieldTypeProto.SELECTION,
|
|
433
|
+
data_field_name=field_name,
|
|
434
|
+
display_name=display_name,
|
|
435
|
+
description=description,
|
|
436
|
+
required=True,
|
|
437
|
+
editable=True,
|
|
438
|
+
selection_properties=SelectionProperties(
|
|
439
|
+
default_value=default_value,
|
|
440
|
+
static_list_values=allowed_values,
|
|
441
|
+
)
|
|
442
|
+
))
|
|
443
|
+
|
|
444
|
+
def add_boolean_config_field(self, field_name: str, display_name: str, description: str, default_value: bool) \
|
|
445
|
+
-> None:
|
|
446
|
+
"""
|
|
447
|
+
Add a boolean configuration field to the tool. This field will be used to configure the tool in the plan
|
|
448
|
+
manager.
|
|
449
|
+
|
|
450
|
+
:param field_name: The name of the field.
|
|
451
|
+
:param display_name: The display name of the field.
|
|
452
|
+
:param description: The description of the field.
|
|
453
|
+
:param default_value: The default value of the field.
|
|
454
|
+
"""
|
|
455
|
+
self.configs.append(VeloxFieldDefProto(
|
|
456
|
+
data_field_type=FieldTypeProto.BOOLEAN,
|
|
457
|
+
data_field_name=field_name,
|
|
458
|
+
display_name=display_name,
|
|
459
|
+
description=description,
|
|
460
|
+
required=True,
|
|
461
|
+
editable=True,
|
|
462
|
+
boolean_properties=BooleanProperties(
|
|
463
|
+
default_value=default_value
|
|
464
|
+
)
|
|
465
|
+
))
|
|
466
|
+
|
|
362
467
|
def to_proto(self) -> ToolDetails:
|
|
363
468
|
"""
|
|
364
469
|
:return: The ToolDetails proto object representing this tool.
|
|
@@ -378,7 +483,7 @@ class ToolBase(ABC):
|
|
|
378
483
|
|
|
379
484
|
:param message: The message to log.
|
|
380
485
|
"""
|
|
381
|
-
self.logs.append(message)
|
|
486
|
+
self.logs.append(f"{self.name}: {message}")
|
|
382
487
|
|
|
383
488
|
@abstractmethod
|
|
384
489
|
def run(self, user: SapioUser, request: ProcessStepRequest, context: ServicerContext) -> list[SapioToolResult]:
|
|
@@ -392,3 +497,60 @@ class ToolBase(ABC):
|
|
|
392
497
|
:return: A SapioToolResults object containing the response data.
|
|
393
498
|
"""
|
|
394
499
|
pass
|
|
500
|
+
|
|
501
|
+
@staticmethod
|
|
502
|
+
def get_request_json(request: ProcessStepRequest, index: int = 0) -> list[Any]:
|
|
503
|
+
"""
|
|
504
|
+
Parse the JSON data from the request object.
|
|
505
|
+
|
|
506
|
+
:param request: The request object containing the input data.
|
|
507
|
+
:param index: The index of the input to parse. Defaults to 0.
|
|
508
|
+
:return: A list of parsed JSON objects. Each entry in the list represents a separate JSON entry from the input.
|
|
509
|
+
"""
|
|
510
|
+
entry_data = request.entry_data
|
|
511
|
+
input_data: list[Any] = [json.loads(x) for x in entry_data[index].entry_data.json_data.entries]
|
|
512
|
+
return input_data
|
|
513
|
+
|
|
514
|
+
@staticmethod
|
|
515
|
+
def read_from_json(json_data: list[dict[str, Any]], key: str) -> list[Any]:
|
|
516
|
+
"""
|
|
517
|
+
From a list of dictionaries, return a list of values for the given key from each dictionary. Skips null values.
|
|
518
|
+
|
|
519
|
+
:param json_data: The JSON data to read from.
|
|
520
|
+
:param key: The key to read the values from.
|
|
521
|
+
:return: A list of values corresponding to the given key in the JSON data.
|
|
522
|
+
"""
|
|
523
|
+
ret_val: list[Any] = []
|
|
524
|
+
for entry in json_data:
|
|
525
|
+
if key in entry:
|
|
526
|
+
value = entry[key]
|
|
527
|
+
if isinstance(value, list):
|
|
528
|
+
ret_val.extend(value)
|
|
529
|
+
elif value is not None:
|
|
530
|
+
ret_val.append(value)
|
|
531
|
+
return ret_val
|
|
532
|
+
|
|
533
|
+
def get_config_fields(self, request: ProcessStepRequest) -> dict[str, Any]:
|
|
534
|
+
"""
|
|
535
|
+
Get the configuration fields from the request object.
|
|
536
|
+
|
|
537
|
+
:param request: The request object containing the input data.
|
|
538
|
+
:return: A dictionary of configuration field names and their values.
|
|
539
|
+
"""
|
|
540
|
+
config_fields: dict[str, Any] = {}
|
|
541
|
+
# noinspection PyUnresolvedReferences,PyTypeChecker
|
|
542
|
+
field_defs: dict[str, VeloxFieldDefProto] = {x.data_field_name: x for x in self.to_proto().config_fields}
|
|
543
|
+
for field, value in request.config_field_values.items():
|
|
544
|
+
if field not in field_defs:
|
|
545
|
+
continue
|
|
546
|
+
field_type: FieldTypeProto = field_defs[field].data_field_type
|
|
547
|
+
if field_type == FieldTypeProto.BOOLEAN:
|
|
548
|
+
value = value.bool_value
|
|
549
|
+
elif field_type == FieldTypeProto.DOUBLE:
|
|
550
|
+
value = value.double_value
|
|
551
|
+
elif field_type in [FieldTypeProto.INTEGER, FieldTypeProto.SHORT, FieldTypeProto.LONG, FieldTypeProto.ENUM]:
|
|
552
|
+
value = value.int_value
|
|
553
|
+
else:
|
|
554
|
+
value = value.string_value
|
|
555
|
+
config_fields[field] = value
|
|
556
|
+
return config_fields
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: sapiopycommons
|
|
3
|
-
Version: 2025.4.
|
|
3
|
+
Version: 2025.4.25a497
|
|
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,7 +1,7 @@
|
|
|
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/tool_of_tools.py,sha256=zYmQ4rNX-qYQnc-vNDnYZjtv9JgmQAmVVuHfVOdBF3w,46984
|
|
4
|
-
sapiopycommons/ai/tool_service_base.py,sha256=
|
|
4
|
+
sapiopycommons/ai/tool_service_base.py,sha256=cjsIOP__P4rxE2sxacnpkMLjevj3kbcueibrLy_03p0,22429
|
|
5
5
|
sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2.py,sha256=qPkyQsREtTLMliV9JB6tC5-NhmdWVWHJr70XNfcAfDI,20605
|
|
6
6
|
sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2.pyi,sha256=gVXRsuscx9XavKsTcepzXWf0LDAAyQ_J5ZjFK6kPYuo,34028
|
|
7
7
|
sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2_grpc.py,sha256=4vD4jWanaJ4uclSkFmS7JIz_lwYXDWBE3DomuPjUyII,941
|
|
@@ -82,7 +82,7 @@ sapiopycommons/webhook/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3
|
|
|
82
82
|
sapiopycommons/webhook/webhook_context.py,sha256=D793uLsb1691SalaPnBUk3rOSxn_hYLhdvkaIxjNXss,1909
|
|
83
83
|
sapiopycommons/webhook/webhook_handlers.py,sha256=L0HetSm43NvA5KyW3xbLpGFh2DbAaeZJVtXIEl2fvV8,39689
|
|
84
84
|
sapiopycommons/webhook/webservice_handlers.py,sha256=Y5dHx_UFWFuSqaoPL6Re-fsKYRuxvCWZ8bj6KSZ3jfM,14285
|
|
85
|
-
sapiopycommons-2025.4.
|
|
86
|
-
sapiopycommons-2025.4.
|
|
87
|
-
sapiopycommons-2025.4.
|
|
88
|
-
sapiopycommons-2025.4.
|
|
85
|
+
sapiopycommons-2025.4.25a497.dist-info/METADATA,sha256=4XZ3Yv1xvJqHu2CpKTQDjfki9Du6aFq5xuPcyMih3xo,3143
|
|
86
|
+
sapiopycommons-2025.4.25a497.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
|
87
|
+
sapiopycommons-2025.4.25a497.dist-info/licenses/LICENSE,sha256=HyVuytGSiAUQ6ErWBHTqt1iSGHhLmlC8fO7jTCuR8dU,16725
|
|
88
|
+
sapiopycommons-2025.4.25a497.dist-info/RECORD,,
|
|
File without changes
|
{sapiopycommons-2025.4.24a495.dist-info → sapiopycommons-2025.4.25a497.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|