sapiopycommons 2025.7.21a626__py3-none-any.whl → 2025.7.22a631__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/callbacks/callback_util.py +5 -2
- {sapiopycommons-2025.7.21a626.dist-info → sapiopycommons-2025.7.22a631.dist-info}/METADATA +1 -1
- {sapiopycommons-2025.7.21a626.dist-info → sapiopycommons-2025.7.22a631.dist-info}/RECORD +5 -33
- sapiopycommons/ai/__init__.py +0 -0
- sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2.py +0 -43
- sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2.pyi +0 -31
- sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2_grpc.py +0 -24
- sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2.py +0 -123
- sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2.pyi +0 -598
- sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2_grpc.py +0 -24
- sapiopycommons/ai/api/plan/proto/step_output_pb2.py +0 -45
- sapiopycommons/ai/api/plan/proto/step_output_pb2.pyi +0 -42
- sapiopycommons/ai/api/plan/proto/step_output_pb2_grpc.py +0 -24
- sapiopycommons/ai/api/plan/proto/step_pb2.py +0 -43
- sapiopycommons/ai/api/plan/proto/step_pb2.pyi +0 -43
- sapiopycommons/ai/api/plan/proto/step_pb2_grpc.py +0 -24
- sapiopycommons/ai/api/plan/script/proto/script_pb2.py +0 -55
- sapiopycommons/ai/api/plan/script/proto/script_pb2.pyi +0 -115
- sapiopycommons/ai/api/plan/script/proto/script_pb2_grpc.py +0 -153
- sapiopycommons/ai/api/plan/tool/proto/entry_pb2.py +0 -57
- sapiopycommons/ai/api/plan/tool/proto/entry_pb2.pyi +0 -96
- sapiopycommons/ai/api/plan/tool/proto/entry_pb2_grpc.py +0 -24
- sapiopycommons/ai/api/plan/tool/proto/tool_pb2.py +0 -71
- sapiopycommons/ai/api/plan/tool/proto/tool_pb2.pyi +0 -250
- sapiopycommons/ai/api/plan/tool/proto/tool_pb2_grpc.py +0 -154
- sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2.py +0 -39
- sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2.pyi +0 -32
- sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2_grpc.py +0 -24
- sapiopycommons/ai/protobuf_utils.py +0 -509
- sapiopycommons/ai/test_client.py +0 -252
- sapiopycommons/ai/tool_service_base.py +0 -902
- {sapiopycommons-2025.7.21a626.dist-info → sapiopycommons-2025.7.22a631.dist-info}/WHEEL +0 -0
- {sapiopycommons-2025.7.21a626.dist-info → sapiopycommons-2025.7.22a631.dist-info}/licenses/LICENSE +0 -0
sapiopycommons/ai/test_client.py
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
from typing import Mapping, Any
|
|
3
|
-
|
|
4
|
-
import grpc
|
|
5
|
-
|
|
6
|
-
from sapiopycommons.ai.api.fielddefinitions.proto.fields_pb2 import FieldValuePbo
|
|
7
|
-
from sapiopycommons.ai.api.plan.tool.proto.entry_pb2 import DataTypePbo, StepBinaryContainerPbo, StepCsvRowPbo, \
|
|
8
|
-
StepCsvHeaderRowPbo, StepCsvContainerPbo, StepJsonContainerPbo, StepImageContainerPbo, StepTextContainerPbo, \
|
|
9
|
-
StepItemContainerPbo, StepInputBatchPbo
|
|
10
|
-
from sapiopycommons.ai.api.plan.tool.proto.tool_pb2 import ProcessStepResponsePbo, ProcessStepRequestPbo, \
|
|
11
|
-
ToolDetailsRequestPbo, ToolDetailsResponsePbo
|
|
12
|
-
from sapiopycommons.ai.api.plan.tool.proto.tool_pb2_grpc import ToolServiceStub
|
|
13
|
-
from sapiopycommons.ai.api.session.proto.sapio_conn_info_pb2 import SapioConnectionInfoPbo, SapioUserSecretTypePbo
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
# FR-47422: Created class.
|
|
17
|
-
class ToolOutput:
|
|
18
|
-
"""
|
|
19
|
-
A class for holding the output of a TestClient that calls a ToolService. ToolOutput objects an be
|
|
20
|
-
printed to show the output of the tool in a human-readable format.
|
|
21
|
-
"""
|
|
22
|
-
tool_name: str
|
|
23
|
-
|
|
24
|
-
binary_output: list[bytes]
|
|
25
|
-
csv_output: list[dict[str, Any]]
|
|
26
|
-
json_output: list[Any]
|
|
27
|
-
image_output: list[bytes]
|
|
28
|
-
text_output: list[str]
|
|
29
|
-
|
|
30
|
-
new_records: list[Mapping[str, FieldValuePbo]]
|
|
31
|
-
|
|
32
|
-
logs: list[str]
|
|
33
|
-
|
|
34
|
-
def __init__(self, tool_name: str):
|
|
35
|
-
self.tool_name = tool_name
|
|
36
|
-
self.binary_output = []
|
|
37
|
-
self.csv_output = []
|
|
38
|
-
self.json_output = []
|
|
39
|
-
self.image_output = []
|
|
40
|
-
self.text_output = []
|
|
41
|
-
self.new_records = []
|
|
42
|
-
self.logs = []
|
|
43
|
-
|
|
44
|
-
def __str__(self):
|
|
45
|
-
ret_val: str = f"{self.tool_name} Output:\n"
|
|
46
|
-
ret_val += "-" * 25 + "\n"
|
|
47
|
-
ret_val += f"Binary Output: {len(self.binary_output)} item(s)\n"
|
|
48
|
-
for binary in self.binary_output:
|
|
49
|
-
ret_val += f"\t{len(binary)} byte(s)\n"
|
|
50
|
-
ret_val += f"\t{binary[:50]}...\n"
|
|
51
|
-
ret_val += f"CSV Output: {len(self.csv_output)} item(s)\n"
|
|
52
|
-
if self.csv_output:
|
|
53
|
-
ret_val += f"\tHeaders: {', '.join(self.csv_output[0].keys())}\n"
|
|
54
|
-
for i, csv_row in enumerate(self.csv_output):
|
|
55
|
-
ret_val += f"\t{i}: {', '.join(f'{v}' for k, v in csv_row.items())}\n"
|
|
56
|
-
ret_val += f"JSON Output: {len(self.json_output)} item(s)\n"
|
|
57
|
-
if self.json_output:
|
|
58
|
-
ret_val += f"\t{json.dumps(self.json_output, indent=2)}\n"
|
|
59
|
-
ret_val += f"Image Output: {len(self.image_output)} item(s)\n"
|
|
60
|
-
for image in self.image_output:
|
|
61
|
-
ret_val += f"\t{len(image)} bytes\n"
|
|
62
|
-
ret_val += f"\t{image[:50]}...\n"
|
|
63
|
-
ret_val += f"Text Output: {len(self.text_output)} item(s)\n"
|
|
64
|
-
for text in self.text_output:
|
|
65
|
-
ret_val += f"\t{text}...\n"
|
|
66
|
-
ret_val += f"New Records: {len(self.new_records)} item(s)\n"
|
|
67
|
-
for record in self.new_records:
|
|
68
|
-
ret_val += f"\t{json.dumps(record, indent=2)}\n"
|
|
69
|
-
ret_val += f"Logs: {len(self.logs)} item(s)\n"
|
|
70
|
-
for log in self.logs:
|
|
71
|
-
ret_val += f"\t{log}\n"
|
|
72
|
-
return ret_val
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
class TestClient:
|
|
76
|
-
"""
|
|
77
|
-
A client for testing a ToolService. This client can be used to send requests to a tool and receive
|
|
78
|
-
responses.
|
|
79
|
-
"""
|
|
80
|
-
server_url: str
|
|
81
|
-
connection: SapioConnectionInfoPbo
|
|
82
|
-
_request_inputs: list[Any]
|
|
83
|
-
_config_fields: dict[str, Any]
|
|
84
|
-
|
|
85
|
-
def __init__(self, server_url: str):
|
|
86
|
-
"""
|
|
87
|
-
:param server_url: The URL of the gRPC server to connect to.
|
|
88
|
-
"""
|
|
89
|
-
self.create_user()
|
|
90
|
-
self.server_url = server_url
|
|
91
|
-
self._request_inputs = []
|
|
92
|
-
self._config_fields = {}
|
|
93
|
-
|
|
94
|
-
def create_user(self):
|
|
95
|
-
"""
|
|
96
|
-
Create a SapioConnectionInfoPbo object with test credentials. This method can be overridden to
|
|
97
|
-
create a user with specific credentials for testing.
|
|
98
|
-
"""
|
|
99
|
-
self.connection = SapioConnectionInfoPbo()
|
|
100
|
-
self.connection.username = "Testing"
|
|
101
|
-
self.connection.webservice_url = "https://localhost:8080/webservice/api"
|
|
102
|
-
self.connection.app_guid = "1234567890"
|
|
103
|
-
self.connection.secret_type = SapioUserSecretTypePbo.PASSWORD
|
|
104
|
-
self.connection.rmi_host.append("Testing")
|
|
105
|
-
self.connection.rmi_port = 9001
|
|
106
|
-
self.connection.secret = "password"
|
|
107
|
-
|
|
108
|
-
def add_input_input(self, input_data: list[bytes]) -> None:
|
|
109
|
-
"""
|
|
110
|
-
Add a binary input to the the next request.
|
|
111
|
-
"""
|
|
112
|
-
self._add_input(DataTypePbo.BINARY, StepBinaryContainerPbo(items=input_data))
|
|
113
|
-
|
|
114
|
-
def add_csv_input(self, input_data: list[dict[str, Any]]) -> None:
|
|
115
|
-
"""
|
|
116
|
-
Add a CSV input to the next request.
|
|
117
|
-
"""
|
|
118
|
-
csv_items = []
|
|
119
|
-
for row in input_data:
|
|
120
|
-
csv_items.append(StepCsvRowPbo(cells=[str(value) for value in row.values()]))
|
|
121
|
-
header = StepCsvHeaderRowPbo(cells=list(input_data[0].keys()))
|
|
122
|
-
self._add_input(DataTypePbo.CSV, StepCsvContainerPbo(header=header, items=csv_items))
|
|
123
|
-
|
|
124
|
-
def add_json_input(self, input_data: list[dict[str, Any]]) -> None:
|
|
125
|
-
"""
|
|
126
|
-
Add a JSON input to the next request.
|
|
127
|
-
"""
|
|
128
|
-
self._add_input(DataTypePbo.JSON, StepJsonContainerPbo(items=[json.dumps(x) for x in input_data]))
|
|
129
|
-
|
|
130
|
-
def add_image_input(self, input_data: list[bytes], image_format: str = "png") -> None:
|
|
131
|
-
"""
|
|
132
|
-
Add an image input to the next request.
|
|
133
|
-
"""
|
|
134
|
-
self._add_input(DataTypePbo.IMAGE, StepImageContainerPbo(items=input_data, image_format=image_format))
|
|
135
|
-
|
|
136
|
-
def add_text_input(self, input_data: list[str]) -> None:
|
|
137
|
-
"""
|
|
138
|
-
Add a text input to the next request.
|
|
139
|
-
"""
|
|
140
|
-
self._add_input(DataTypePbo.TEXT, StepTextContainerPbo(items=input_data))
|
|
141
|
-
|
|
142
|
-
def clear_inputs(self) -> None:
|
|
143
|
-
"""
|
|
144
|
-
Clear all inputs that have been added to the next request.
|
|
145
|
-
This is useful if you want to start a new request without the previous inputs.
|
|
146
|
-
"""
|
|
147
|
-
self._request_inputs.clear()
|
|
148
|
-
|
|
149
|
-
def add_config_field(self, field_name: str, value: Any) -> None:
|
|
150
|
-
"""
|
|
151
|
-
Add a configuration field value to the next request.
|
|
152
|
-
|
|
153
|
-
:param field_name: The name of the configuration field.
|
|
154
|
-
:param value: The value to set for the configuration field.
|
|
155
|
-
"""
|
|
156
|
-
self._config_fields[field_name] = value
|
|
157
|
-
|
|
158
|
-
def add_config_fields(self, config_fields: dict[str, Any]) -> None:
|
|
159
|
-
"""
|
|
160
|
-
Add multiple configuration field values to the next request.
|
|
161
|
-
|
|
162
|
-
:param config_fields: A dictionary of configuration field names and their corresponding values.
|
|
163
|
-
"""
|
|
164
|
-
self._config_fields.update(config_fields)
|
|
165
|
-
|
|
166
|
-
def clear_configs(self) -> None:
|
|
167
|
-
"""
|
|
168
|
-
Clear all configuration field values that have been added to the next request.
|
|
169
|
-
This is useful if you want to start a new request without the previous configurations.
|
|
170
|
-
"""
|
|
171
|
-
self._config_fields.clear()
|
|
172
|
-
|
|
173
|
-
def clear_request(self) -> None:
|
|
174
|
-
"""
|
|
175
|
-
Clear all inputs and configuration fields that have been added to the next request.
|
|
176
|
-
This is useful if you want to start a new request without the previous inputs and configurations.
|
|
177
|
-
"""
|
|
178
|
-
self.clear_inputs()
|
|
179
|
-
self.clear_configs()
|
|
180
|
-
|
|
181
|
-
def _add_input(self, data_type: DataTypePbo, items: Any) -> None:
|
|
182
|
-
"""
|
|
183
|
-
Helper method for adding inputs to the next request.
|
|
184
|
-
"""
|
|
185
|
-
match data_type:
|
|
186
|
-
case DataTypePbo.BINARY:
|
|
187
|
-
container = StepItemContainerPbo(dataType=data_type, binary_container=items)
|
|
188
|
-
case DataTypePbo.CSV:
|
|
189
|
-
container = StepItemContainerPbo(dataType=data_type, csv_container=items)
|
|
190
|
-
case DataTypePbo.JSON:
|
|
191
|
-
container = StepItemContainerPbo(dataType=data_type, json_container=items)
|
|
192
|
-
case DataTypePbo.IMAGE:
|
|
193
|
-
container = StepItemContainerPbo(dataType=data_type, image_container=items)
|
|
194
|
-
case DataTypePbo.TEXT:
|
|
195
|
-
container = StepItemContainerPbo(dataType=data_type, text_container=items)
|
|
196
|
-
case _:
|
|
197
|
-
raise ValueError(f"Unsupported data type: {data_type}")
|
|
198
|
-
self._request_inputs.append(container)
|
|
199
|
-
|
|
200
|
-
def get_service_details(self) -> ToolDetailsResponsePbo:
|
|
201
|
-
"""
|
|
202
|
-
Get the details of the tools from the server.
|
|
203
|
-
|
|
204
|
-
:return: A ToolDetailsResponsePbo object containing the details of the tool service.
|
|
205
|
-
"""
|
|
206
|
-
with grpc.insecure_channel(self.server_url) as channel:
|
|
207
|
-
stub = ToolServiceStub(channel)
|
|
208
|
-
return stub.GetToolDetails(ToolDetailsRequestPbo(sapio_conn_info=self.connection))
|
|
209
|
-
|
|
210
|
-
def call_tool(self, tool_name: str) -> ToolOutput:
|
|
211
|
-
"""
|
|
212
|
-
Send the request to the tool service for a particular tool name. This will send all the inputs that have been
|
|
213
|
-
added using the add_X_input functions.
|
|
214
|
-
|
|
215
|
-
:param tool_name: The name of the tool to call on the server.
|
|
216
|
-
:return: A ToolOutput object containing the results of the tool service call.
|
|
217
|
-
"""
|
|
218
|
-
with grpc.insecure_channel(self.server_url) as channel:
|
|
219
|
-
stub = ToolServiceStub(channel)
|
|
220
|
-
|
|
221
|
-
response: ProcessStepResponsePbo = stub.ProcessData(
|
|
222
|
-
ProcessStepRequestPbo(
|
|
223
|
-
sapio_user=self.connection,
|
|
224
|
-
tool_name=tool_name,
|
|
225
|
-
config_field_values=self._config_fields,
|
|
226
|
-
input=[
|
|
227
|
-
StepInputBatchPbo(is_partial=False, item_container=item)
|
|
228
|
-
for item in self._request_inputs
|
|
229
|
-
]
|
|
230
|
-
)
|
|
231
|
-
)
|
|
232
|
-
|
|
233
|
-
results = ToolOutput(tool_name)
|
|
234
|
-
for item in response.output:
|
|
235
|
-
container = item.item_container
|
|
236
|
-
|
|
237
|
-
results.binary_output.extend(container.binary_container.items)
|
|
238
|
-
for header in container.csv_container.header.cells:
|
|
239
|
-
output_row: dict[str, Any] = {}
|
|
240
|
-
for i, row in enumerate(container.csv_container.items):
|
|
241
|
-
output_row[header] = row.cells[i]
|
|
242
|
-
results.csv_output.append(output_row)
|
|
243
|
-
results.json_output.extend([json.loads(x) for x in container.json_container.items])
|
|
244
|
-
results.image_output.extend(container.image_container.items)
|
|
245
|
-
results.text_output.extend(container.text_container.items)
|
|
246
|
-
|
|
247
|
-
for record in response.new_records:
|
|
248
|
-
results.new_records.append(record.fields)
|
|
249
|
-
|
|
250
|
-
results.logs.extend(response.log)
|
|
251
|
-
|
|
252
|
-
return results
|