sapiopycommons 2025.8.14a703__py3-none-any.whl → 2025.8.15a704__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.

Files changed (46) hide show
  1. sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2.py +43 -0
  2. sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2.pyi +31 -0
  3. sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2_grpc.py +24 -0
  4. sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2.py +123 -0
  5. sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2.pyi +598 -0
  6. sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2_grpc.py +24 -0
  7. sapiopycommons/ai/api/plan/converter/proto/converter_pb2.py +50 -0
  8. sapiopycommons/ai/api/plan/converter/proto/converter_pb2.pyi +61 -0
  9. sapiopycommons/ai/api/plan/converter/proto/converter_pb2_grpc.py +149 -0
  10. sapiopycommons/ai/api/plan/item/proto/item_container_pb2.py +55 -0
  11. sapiopycommons/ai/api/plan/item/proto/item_container_pb2.pyi +88 -0
  12. sapiopycommons/ai/api/plan/item/proto/item_container_pb2_grpc.py +24 -0
  13. sapiopycommons/ai/api/plan/proto/step_output_pb2.py +45 -0
  14. sapiopycommons/ai/api/plan/proto/step_output_pb2.pyi +42 -0
  15. sapiopycommons/ai/api/plan/proto/step_output_pb2_grpc.py +24 -0
  16. sapiopycommons/ai/api/plan/proto/step_pb2.py +43 -0
  17. sapiopycommons/ai/api/plan/proto/step_pb2.pyi +43 -0
  18. sapiopycommons/ai/api/plan/proto/step_pb2_grpc.py +24 -0
  19. sapiopycommons/ai/api/plan/script/proto/script_pb2.py +59 -0
  20. sapiopycommons/ai/api/plan/script/proto/script_pb2.pyi +102 -0
  21. sapiopycommons/ai/api/plan/script/proto/script_pb2_grpc.py +153 -0
  22. sapiopycommons/ai/api/plan/tool/proto/entry_pb2.py +41 -0
  23. sapiopycommons/ai/api/plan/tool/proto/entry_pb2.pyi +35 -0
  24. sapiopycommons/ai/api/plan/tool/proto/entry_pb2_grpc.py +24 -0
  25. sapiopycommons/ai/api/plan/tool/proto/tool_pb2.py +75 -0
  26. sapiopycommons/ai/api/plan/tool/proto/tool_pb2.pyi +237 -0
  27. sapiopycommons/ai/api/plan/tool/proto/tool_pb2_grpc.py +154 -0
  28. sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2.py +39 -0
  29. sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2.pyi +32 -0
  30. sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2_grpc.py +24 -0
  31. sapiopycommons/ai/converter_service_base.py +116 -0
  32. sapiopycommons/ai/protobuf_utils.py +504 -0
  33. sapiopycommons/ai/test_client.py +334 -0
  34. sapiopycommons/ai/tool_service_base.py +917 -0
  35. sapiopycommons/callbacks/callback_util.py +16 -26
  36. sapiopycommons/flowcyto/flow_cyto.py +24 -2
  37. sapiopycommons/general/accession_service.py +28 -2
  38. sapiopycommons/multimodal/multimodal.py +24 -2
  39. sapiopycommons/webhook/webservice_handlers.py +1 -1
  40. {sapiopycommons-2025.8.14a703.dist-info → sapiopycommons-2025.8.15a704.dist-info}/METADATA +2 -2
  41. {sapiopycommons-2025.8.14a703.dist-info → sapiopycommons-2025.8.15a704.dist-info}/RECORD +43 -12
  42. sapiopycommons/ai/tool_of_tools.py +0 -917
  43. sapiopycommons/files/assay_plate_reader.py +0 -93
  44. sapiopycommons/files/file_text_converter.py +0 -207
  45. {sapiopycommons-2025.8.14a703.dist-info → sapiopycommons-2025.8.15a704.dist-info}/WHEEL +0 -0
  46. {sapiopycommons-2025.8.14a703.dist-info → sapiopycommons-2025.8.15a704.dist-info}/licenses/LICENSE +0 -0
@@ -1,93 +0,0 @@
1
- import base64
2
- import dataclasses
3
- from typing import Any
4
-
5
- from databind.core.dataclasses import dataclass
6
- from databind.json import loads
7
- from sapiopylib.rest.utils.singletons import SapioContextManager
8
-
9
-
10
- @dataclasses.dataclass
11
- class ProcessAssayPlateRequest:
12
- """
13
- A request to process the results of assay plate reader with a configuration set in Sapio.
14
-
15
- Attributes:
16
- num_rows (int): The number of rows in the plate.
17
- num_columns (int): The number of columns in the plate.
18
- plate_ids_in_context (list[str]): List of plate IDs that are in context for this request.
19
- filename (str): The name of the file containing the assay data.
20
- file_data (bytes): The binary content of the file.
21
- plate_reader_config_name (str): The name of the plate reader configuration to use.
22
- """
23
- num_rows: int
24
- num_columns: int
25
- plate_ids_in_context: list[str] | None
26
- filename: str
27
- file_data: bytes
28
- plate_reader_config_name: str
29
-
30
- def to_json(self) -> dict[str, Any]:
31
- return {
32
- "numRows": self.num_rows,
33
- "numCols": self.num_columns,
34
- "plateIdsInContext": self.plate_ids_in_context,
35
- "fileName": self.filename,
36
- "fileDataBase64": base64.b64encode(self.file_data).decode('utf-8'),
37
- "plateReaderName": self.plate_reader_config_name
38
- }
39
-
40
-
41
- @dataclass
42
- class AssayPlateResultIdent:
43
- plateId: str
44
- channelIdOrBlock: str
45
- kineticAssaySeconds: float | None
46
-
47
-
48
- @dataclass
49
- class AssayResultDatum:
50
- """
51
- Describes the data received from an assay plate reader.
52
- Most of the time, the data is a single value, but sometimes it can be multiple values, especially for kinetic data.
53
- """
54
- DEFAULT_PROPERTY_NAME: str = "read"
55
- rowPosition: str
56
- columnPosition: str
57
- valueByPropertyName: dict[str, float]
58
- textValueByPropertyName: dict[str, str]
59
-
60
-
61
- @dataclass
62
- class AssayPlateResult:
63
- """
64
- Assay plate load result for a single plate in a file. A file can have more than one of this result if it has multiple plate of data in a single file.
65
- """
66
- resultIdent: AssayPlateResultIdent
67
- numRows: int
68
- numColumns: int
69
- resultDatum: list[AssayResultDatum]
70
-
71
-
72
- @dataclass
73
- class AssayFileLoadResult:
74
- """
75
- The entire top-level file loading result for an assay plate reader file.
76
- """
77
- filename: str
78
- plateResultList: list[AssayPlateResult]
79
-
80
-
81
- class AssayPlateReader(SapioContextManager):
82
- """
83
- This class contains services for Sapio Assay Plate Reader.
84
- """
85
-
86
- def process_plate_reader_data(self, request: ProcessAssayPlateRequest) -> AssayFileLoadResult:
87
- """
88
- Processes the assay plate reader data using provided request into a structured result using configuration defined in Sapio.
89
- """
90
- payload = request.to_json()
91
- response = self.user.plugin_post("assayplatereader/process", payload=payload)
92
- self.user.raise_for_status(response)
93
- return loads(response.text, AssayFileLoadResult)
@@ -1,207 +0,0 @@
1
- import io
2
- import os
3
- import tempfile
4
- from enum import Enum, auto
5
-
6
- class FileType(Enum):
7
- """Supported file types for conversion."""
8
- TXT = auto()
9
- MD = auto()
10
- CSV = auto()
11
- DOC = auto()
12
- DOCX = auto()
13
- XLS = auto()
14
- XLSX = auto()
15
- PPT = auto()
16
- PPTX = auto()
17
- PDF = auto()
18
- UNKNOWN = auto()
19
-
20
-
21
- class FileToTextConverter:
22
- """
23
- A class for converting various file types to raw text.
24
- """
25
- @staticmethod
26
- def mime_type_to_enum(mime_type: str) -> FileType:
27
- """
28
- Converts a MIME type to a FileType enum.
29
-
30
- :param mime_type: The MIME type string to convert.
31
- :return: The corresponding FileType enum, or UNKNOWN if not recognized.
32
- """
33
- if not mime_type or not mime_type.strip():
34
- return FileType.UNKNOWN
35
-
36
- mime_map = {
37
- "text/plain": FileType.TXT,
38
- "text/markdown": FileType.MD,
39
- "text/csv": FileType.CSV,
40
- "application/msword": FileType.DOC,
41
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document": FileType.DOCX,
42
- "application/vnd.ms-excel": FileType.XLS,
43
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": FileType.XLSX,
44
- "application/vnd.ms-powerpoint": FileType.PPT,
45
- "application/vnd.openxmlformats-officedocument.presentationml.presentation": FileType.PPTX,
46
- "application/pdf": FileType.PDF,
47
- }
48
- return mime_map.get(mime_type, FileType.UNKNOWN)
49
-
50
- @staticmethod
51
- def file_extension_to_enum(file_path: str) -> FileType:
52
- """
53
- Converts a file path or extension to a FileType enum.
54
-
55
- :param file_path: The file path or extension to convert.
56
- :return: The corresponding FileType enum, or UNKNOWN if not recognized.
57
- """
58
- if not file_path or not file_path.strip():
59
- return FileType.UNKNOWN
60
-
61
- # Extract the file extension, removing the leading dot and making it lowercase
62
- file_extension = os.path.splitext(file_path)[1].lstrip('.').lower()
63
-
64
- ext_map = {
65
- "txt": FileType.TXT,
66
- "md": FileType.MD,
67
- "csv": FileType.CSV,
68
- "doc": FileType.DOC,
69
- "docx": FileType.DOCX,
70
- "xls": FileType.XLS,
71
- "xlsx": FileType.XLSX,
72
- "ppt": FileType.PPT,
73
- "pptx": FileType.PPTX,
74
- "pdf": FileType.PDF,
75
- }
76
- return ext_map.get(file_extension, FileType.UNKNOWN)
77
-
78
- @classmethod
79
- def parse_file(cls, file_type: FileType, file_bytes: bytes) -> str | None:
80
- """
81
- Parses file bytes based on the FileType and returns the text content.
82
-
83
- :param file_type: The type of the file to parse.
84
- :param file_bytes: The raw bytes of the file to parse.
85
- :return: The text content of the file, or None if the file type is not supported or parsing fails.
86
- """
87
- if file_type is None or file_bytes is None:
88
- return None
89
- if not file_bytes:
90
- return ""
91
-
92
- # Dispatch to the correct parser method
93
- parser_map = {
94
- FileType.TXT: cls._parse_plain_text,
95
- FileType.MD: cls._parse_plain_text,
96
- FileType.CSV: cls._parse_plain_text,
97
- FileType.DOC: cls._parse_doc,
98
- FileType.DOCX: cls._parse_docx,
99
- FileType.XLS: cls._parse_xls,
100
- FileType.XLSX: cls._parse_xlsx,
101
- FileType.PPT: cls._parse_ppt,
102
- FileType.PPTX: cls._parse_pptx,
103
- FileType.PDF: cls._parse_pdf,
104
- }
105
-
106
- parser_func = parser_map.get(file_type)
107
-
108
- if parser_func:
109
- return parser_func(file_bytes)
110
-
111
- return None
112
-
113
- @staticmethod
114
- def _parse_plain_text(file_bytes: bytes) -> str:
115
- return file_bytes.decode('utf-8')
116
-
117
- @staticmethod
118
- def _run_textract(file_bytes: bytes, extension: str) -> str:
119
- """
120
- Helper to run textract on in-memory bytes by writing to a temp file.
121
- Note: textract may require external system dependencies.
122
- """
123
- import textract
124
- with tempfile.NamedTemporaryFile(suffix=f".{extension}", delete=True) as temp_file:
125
- temp_file.write(file_bytes)
126
- temp_file.flush() # Ensure all bytes are written to disk
127
- text = textract.process(temp_file.name).decode('utf-8')
128
- return text
129
-
130
- @classmethod
131
- def _parse_doc(cls, file_bytes: bytes) -> str:
132
- return cls._run_textract(file_bytes, 'doc')
133
-
134
- @staticmethod
135
- def _parse_docx(file_bytes: bytes) -> str:
136
- import docx
137
- with io.BytesIO(file_bytes) as stream:
138
- document = docx.Document(stream)
139
- return "\n".join(para.text for para in document.paragraphs if para.text.strip())
140
-
141
- @staticmethod
142
- def _parse_xls(file_bytes: bytes) -> str:
143
- import xlrd
144
- workbook = xlrd.open_workbook(file_contents=file_bytes)
145
- text_parts = []
146
- for sheet in workbook.sheets():
147
- text_parts.append(f"Sheet: {sheet.name}\n")
148
- for row_idx in range(sheet.nrows):
149
- row_cells = []
150
- for col_idx in range(sheet.ncols):
151
- cell_text = str(sheet.cell_value(row_idx, col_idx))
152
- if cell_text.strip():
153
- row_cells.append(cell_text + "\t")
154
- if row_cells:
155
- text_parts.append("".join(row_cells))
156
- text_parts.append("\n")
157
- text_parts.append("\n")
158
- return "".join(text_parts)
159
-
160
- @staticmethod
161
- def _parse_xlsx(file_bytes: bytes) -> str:
162
- import openpyxl
163
- with io.BytesIO(file_bytes) as stream:
164
- workbook = openpyxl.load_workbook(stream, read_only=True)
165
- text_parts = []
166
- for sheet in workbook.worksheets:
167
- text_parts.append(f"Sheet: {sheet.title}\n")
168
- for row in sheet.iter_rows():
169
- row_cells = []
170
- for cell in row:
171
- cell_text = str(cell.value) if cell.value is not None else ""
172
- if cell_text.strip():
173
- row_cells.append(cell_text + "\t")
174
- if row_cells:
175
- text_parts.append("".join(row_cells))
176
- text_parts.append("\n")
177
- text_parts.append("\n")
178
- return "".join(text_parts)
179
-
180
- @classmethod
181
- def _parse_ppt(cls, file_bytes: bytes) -> str:
182
- return cls._run_textract(file_bytes, 'ppt')
183
-
184
- @staticmethod
185
- def _parse_pptx(file_bytes: bytes) -> str:
186
- import pptx
187
- with io.BytesIO(file_bytes) as stream:
188
- presentation = pptx.Presentation(stream)
189
- text_parts = []
190
- for slide in presentation.slides:
191
- for shape in slide.shapes:
192
- if shape.has_text_frame:
193
- text = shape.text_frame.text
194
- if text and text.strip():
195
- text_parts.append(text)
196
- return "\n".join(text_parts)
197
-
198
- @staticmethod
199
- def _parse_pdf(file_bytes: bytes) -> str:
200
- """Parses a PDF file's bytes and extracts text using PyMuPDF."""
201
- import pymupdf
202
- text_parts = []
203
- with io.BytesIO(file_bytes) as stream:
204
- with pymupdf.open(stream=stream) as doc:
205
- for page in doc:
206
- text_parts.append(page.get_text())
207
- return "\n".join(text_parts)