sapiopycommons 2025.4.24a493__py3-none-any.whl → 2025.4.24a494__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 +102 -2
- {sapiopycommons-2025.4.24a493.dist-info → sapiopycommons-2025.4.24a494.dist-info}/METADATA +1 -1
- {sapiopycommons-2025.4.24a493.dist-info → sapiopycommons-2025.4.24a494.dist-info}/RECORD +5 -5
- {sapiopycommons-2025.4.24a493.dist-info → sapiopycommons-2025.4.24a494.dist-info}/WHEEL +0 -0
- {sapiopycommons-2025.4.24a493.dist-info → sapiopycommons-2025.4.24a494.dist-info}/licenses/LICENSE +0 -0
|
@@ -6,13 +6,15 @@ from abc import abstractmethod, ABC
|
|
|
6
6
|
from typing import Any
|
|
7
7
|
|
|
8
8
|
from grpc import ServicerContext
|
|
9
|
+
|
|
10
|
+
from sapiopycommons.ai.api.fielddefinitions.proto.velox_field_def_pb2 import VeloxFieldDefProto
|
|
9
11
|
from sapiopycommons.general.aliases import FieldMap
|
|
10
12
|
from sapiopylib.rest.User import SapioUser
|
|
11
13
|
|
|
12
14
|
from sapiopycommons.ai.api.plan.tool.proto.entry_pb2 import StepEntryOutputData, StepEntryData, StepJsonData, DataType, \
|
|
13
15
|
StepImageData, StepTextData, StepCsvData, StepBinaryData, StepCsvHeaderRow, StepCsvRow
|
|
14
16
|
from sapiopycommons.ai.api.plan.tool.proto.tool_pb2 import ProcessStepRequest, ToolDetailsRequest, ToolDetailsResponse, \
|
|
15
|
-
ProcessStepResponse, ToolDetails, StepRecord, StepRecordFieldValue
|
|
17
|
+
ProcessStepResponse, ToolDetails, StepRecord, StepRecordFieldValue, ToolInputDetails, ToolOutputDetails
|
|
16
18
|
from sapiopycommons.ai.api.plan.tool.proto.tool_pb2_grpc import ToolServiceServicer
|
|
17
19
|
from sapiopycommons.ai.api.session.proto.sapio_conn_info_pb2 import SapioConnectionInfo, SapioUserSecretType
|
|
18
20
|
|
|
@@ -185,6 +187,8 @@ class ToolServiceBase(ToolServiceServicer, ABC):
|
|
|
185
187
|
|
|
186
188
|
Subclasses must implement the get_details and run methods to provide specific functionality for the tool.
|
|
187
189
|
"""
|
|
190
|
+
tools: list[ToolBase]
|
|
191
|
+
|
|
188
192
|
def GetToolDetails(self, request: ToolDetailsRequest, context: ServicerContext) -> ToolDetailsResponse:
|
|
189
193
|
try:
|
|
190
194
|
# Convert the SapioConnectionInfo proto object to a SapioUser object.
|
|
@@ -212,9 +216,12 @@ class ToolServiceBase(ToolServiceServicer, ABC):
|
|
|
212
216
|
else:
|
|
213
217
|
new_records.extend(data)
|
|
214
218
|
# Return a ProcessStepResponse proto object containing the output data and new records to the caller.
|
|
219
|
+
# TODO: Return an is_success = true value.
|
|
220
|
+
# TODO: Allow logging in the tools?
|
|
215
221
|
return ProcessStepResponse(entry_data=entry_data, new_records=new_records)
|
|
216
222
|
except Exception as e:
|
|
217
223
|
# TODO: Do something other than dump the full stack trace into the logs?
|
|
224
|
+
# TODO: Eventually we'll return an is_success = false value.
|
|
218
225
|
return ProcessStepResponse(log=[traceback.format_exc()])
|
|
219
226
|
|
|
220
227
|
@staticmethod
|
|
@@ -244,6 +251,25 @@ class ToolServiceBase(ToolServiceServicer, ABC):
|
|
|
244
251
|
"""
|
|
245
252
|
return 1
|
|
246
253
|
|
|
254
|
+
def _get_tools(self) -> list[ToolBase]:
|
|
255
|
+
"""
|
|
256
|
+
Get the tools registered with this service.
|
|
257
|
+
"""
|
|
258
|
+
# If the tools have not been registered, call the register_tools method to do so.
|
|
259
|
+
if not hasattr(self, "tools"):
|
|
260
|
+
self.tools = self.register_tools()
|
|
261
|
+
# If the tools are still not registered, raise an exception.
|
|
262
|
+
if not self.tools:
|
|
263
|
+
raise Exception("No tools registered with this service.")
|
|
264
|
+
return self.tools
|
|
265
|
+
|
|
266
|
+
@abstractmethod
|
|
267
|
+
def register_tools(self) -> list[ToolBase]:
|
|
268
|
+
"""
|
|
269
|
+
Register the tools with this service.
|
|
270
|
+
"""
|
|
271
|
+
pass
|
|
272
|
+
|
|
247
273
|
@abstractmethod
|
|
248
274
|
def get_details(self, user: SapioUser, request: ToolDetailsRequest, context: ServicerContext) -> list[ToolDetails]:
|
|
249
275
|
"""
|
|
@@ -255,7 +281,81 @@ class ToolServiceBase(ToolServiceServicer, ABC):
|
|
|
255
281
|
:param context: The gRPC context.
|
|
256
282
|
:return: A ToolDetailsResponse object containing the tool details.
|
|
257
283
|
"""
|
|
258
|
-
|
|
284
|
+
tool_details: list[ToolDetails] = []
|
|
285
|
+
for tool in self._get_tools():
|
|
286
|
+
tool_details.append(tool.to_proto())
|
|
287
|
+
return tool_details
|
|
288
|
+
|
|
289
|
+
@abstractmethod
|
|
290
|
+
def run(self, user: SapioUser, request: ProcessStepRequest, context: ServicerContext) -> list[SapioToolResult]:
|
|
291
|
+
"""
|
|
292
|
+
Execute a tool from this service.
|
|
293
|
+
|
|
294
|
+
:param user: A user object that can be used to initialize manager classes using DataMgmtServer to query the
|
|
295
|
+
system.
|
|
296
|
+
:param request: The request object containing the input data.
|
|
297
|
+
:param context: The gRPC context.
|
|
298
|
+
:return: A SapioToolResults object containing the response data.
|
|
299
|
+
"""
|
|
300
|
+
for tool in self._get_tools():
|
|
301
|
+
if request.tool_name == tool.name:
|
|
302
|
+
return tool.run(user, request, context)
|
|
303
|
+
raise Exception(f"Tool {request.tool_name} not found in registered tools.")
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
class ToolBase(ABC):
|
|
307
|
+
name: str
|
|
308
|
+
description: str
|
|
309
|
+
data_type_name: str | None
|
|
310
|
+
inputs: list[ToolInputDetails]
|
|
311
|
+
outputs: list[ToolOutputDetails]
|
|
312
|
+
configs: list[VeloxFieldDefProto]
|
|
313
|
+
|
|
314
|
+
def __init__(self, name: str, description: str, data_type_name: str | None = None):
|
|
315
|
+
self.name = name
|
|
316
|
+
self.description = description
|
|
317
|
+
self.data_type_name = data_type_name
|
|
318
|
+
self.inputs = []
|
|
319
|
+
self.outputs = []
|
|
320
|
+
|
|
321
|
+
def add_input(self, details: ToolInputDetails) -> None:
|
|
322
|
+
"""
|
|
323
|
+
Add an input configuration to the tool.
|
|
324
|
+
|
|
325
|
+
:param details: The input configuration details.
|
|
326
|
+
"""
|
|
327
|
+
self.inputs.append(details)
|
|
328
|
+
|
|
329
|
+
def add_output(self, details: ToolOutputDetails) -> None:
|
|
330
|
+
"""
|
|
331
|
+
Add an output configuration to the tool.
|
|
332
|
+
|
|
333
|
+
:param details: The output configuration details.
|
|
334
|
+
"""
|
|
335
|
+
self.outputs.append(details)
|
|
336
|
+
|
|
337
|
+
def add_config_field(self, field: VeloxFieldDefProto) -> None:
|
|
338
|
+
"""
|
|
339
|
+
Add a configuration field to the tool.
|
|
340
|
+
|
|
341
|
+
:param field: The configuration field details.
|
|
342
|
+
"""
|
|
343
|
+
self.configs.append(field)
|
|
344
|
+
|
|
345
|
+
def to_proto(self) -> ToolDetails:
|
|
346
|
+
"""
|
|
347
|
+
Convert this tool to a ToolDetails proto object.
|
|
348
|
+
|
|
349
|
+
:return: The ToolDetails proto object.
|
|
350
|
+
"""
|
|
351
|
+
return ToolDetails(
|
|
352
|
+
name=self.name,
|
|
353
|
+
description=self.description,
|
|
354
|
+
input_configs=self.inputs,
|
|
355
|
+
output_configs=self.outputs,
|
|
356
|
+
output_data_type_name=self.data_type_name,
|
|
357
|
+
config_fields=self.configs
|
|
358
|
+
)
|
|
259
359
|
|
|
260
360
|
@abstractmethod
|
|
261
361
|
def run(self, user: SapioUser, request: ProcessStepRequest, context: ServicerContext) -> list[SapioToolResult]:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: sapiopycommons
|
|
3
|
-
Version: 2025.4.
|
|
3
|
+
Version: 2025.4.24a494
|
|
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=tftW0TFatccbx47QtfiKcsZaPpOHoOlEfDlrU_IQVUU,14376
|
|
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.24a494.dist-info/METADATA,sha256=sLGtVufAGHGHXHpjTPI4TYwjcG1ya14ACJRNVWkLPHw,3143
|
|
86
|
+
sapiopycommons-2025.4.24a494.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
|
87
|
+
sapiopycommons-2025.4.24a494.dist-info/licenses/LICENSE,sha256=HyVuytGSiAUQ6ErWBHTqt1iSGHhLmlC8fO7jTCuR8dU,16725
|
|
88
|
+
sapiopycommons-2025.4.24a494.dist-info/RECORD,,
|
|
File without changes
|
{sapiopycommons-2025.4.24a493.dist-info → sapiopycommons-2025.4.24a494.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|