Skip to content

Commit

Permalink
updated the tools to support sdk filestorage feature (#892)
Browse files Browse the repository at this point in the history
Signed-off-by: ali <[email protected]>
  • Loading branch information
muhammad-ali-e authored Dec 12, 2024
1 parent 1bf253f commit 6359adb
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion tools/classifier/src/config/properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"schemaVersion": "0.0.1",
"displayName": "File Classifier",
"functionName": "classify",
"toolVersion": "0.0.40",
"toolVersion": "0.0.41",
"description": "Classifies a file into a bin based on its contents",
"input": {
"description": "File to be classified"
Expand Down
4 changes: 2 additions & 2 deletions tools/classifier/src/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def copy_source_to_output_bin(
"""
try:
output_folder_bin = Path(self.output_dir) / classification
if hasattr(self.tool, "workflow_filestorage"):
if self.tool.workflow_filestorage:
output_file = output_folder_bin / source_name
self._copy_file(
source_fs=self.tool.workflow_filestorage,
Expand Down Expand Up @@ -163,7 +163,7 @@ def _extract_from_file(self, file: str) -> Optional[str]:
"""
self.tool.stream_log("Extracting text from file")
try:
if hasattr(self.tool, "workflow_filestorage"):
if self.tool.workflow_filestorage:
text = self.tool.workflow_filestorage.read(path=file, mode="rb").decode(
"utf-8"
)
Expand Down
2 changes: 1 addition & 1 deletion tools/structure/src/config/properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"schemaVersion": "0.0.1",
"displayName": "Structure Tool",
"functionName": "structure_tool",
"toolVersion": "0.0.51",
"toolVersion": "0.0.52",
"description": "This is a template tool which can answer set of input prompts designed in the Prompt Studio",
"input": {
"description": "File that needs to be indexed and parsed for answers"
Expand Down
20 changes: 10 additions & 10 deletions tools/structure/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def run(
_, file_name = os.path.split(input_file)
if summarize_as_source:
file_name = SettingsKeys.SUMMARIZE
if hasattr(self, "workflow_filestorage"):
if self.workflow_filestorage:
tool_data_dir = Path(self.get_env_or_die(ToolEnv.EXECUTION_DATA_DIR))
else:
tool_data_dir = Path(self.get_env_or_die(SettingsKeys.TOOL_DATA_DIR))
Expand Down Expand Up @@ -131,7 +131,6 @@ def run(
f"Function to higlight context is not found. {PAID_FEATURE_MSG}",
level=LogLevel.WARN,
)
workflow_filestorage = getattr(self, "workflow_filestorage", None)
if tool_settings[SettingsKeys.ENABLE_SINGLE_PASS_EXTRACTION]:
index.index(
tool_id=tool_id,
Expand All @@ -147,8 +146,8 @@ def run(
usage_kwargs=usage_kwargs,
process_text=process_text,
**(
{"fs": workflow_filestorage}
if workflow_filestorage is not None
{"fs": self.workflow_filestorage}
if self.workflow_filestorage is not None
else {}
),
)
Expand Down Expand Up @@ -256,7 +255,7 @@ def run(
self.stream_log("Writing parsed output...")
source_name = self.get_exec_metadata.get(MetadataKey.SOURCE_NAME)
output_path = Path(output_dir) / f"{Path(source_name).stem}.json"
if hasattr(self, "workflow_filestorage"):
if self.workflow_filestorage:
self.workflow_filestorage.json_dump(
path=output_path, data=structured_output_dict
)
Expand Down Expand Up @@ -303,7 +302,7 @@ def _summarize_and_index(
summarize_file_path = tool_data_dir / SettingsKeys.SUMMARIZE

summarized_context = ""
if hasattr(self, "workflow_filestorage"):
if self.workflow_filestorage:
if self.workflow_filestorage.exists(summarize_file_path):
summarized_context = self.workflow_filestorage.read(
path=summarize_file_path, mode="r"
Expand All @@ -313,7 +312,7 @@ def _summarize_and_index(
summarized_context = f.read()
if not summarized_context:
context = ""
if hasattr(self, "workflow_filestorage"):
if self.workflow_filestorage:
context = self.workflow_filestorage.read(
path=extract_file_path, mode="r"
)
Expand Down Expand Up @@ -344,7 +343,7 @@ def _summarize_and_index(
structure_output = json.loads(response[SettingsKeys.STRUCTURE_OUTPUT])
summarized_context = structure_output.get(SettingsKeys.DATA, "")
self.stream_log("Writing summarized context to a file")
if hasattr(self, "workflow_filestorage"):
if self.workflow_filestorage:
self.workflow_filestorage.write(
path=summarize_file_path, mode="w", data=summarized_context
)
Expand All @@ -356,7 +355,6 @@ def _summarize_and_index(
summarize_file_hash: str = ToolUtils.get_hash_from_file(
file_path=summarize_file_path
)
workflow_filestorage = getattr(self, "workflow_filestorage", None)
index.index(
tool_id=tool_id,
embedding_instance_id=embedding_instance_id,
Expand All @@ -368,7 +366,9 @@ def _summarize_and_index(
chunk_overlap=0,
usage_kwargs=usage_kwargs,
**(
{"fs": workflow_filestorage} if workflow_filestorage is not None else {}
{"fs": self.workflow_filestorage}
if self.workflow_filestorage is not None
else {}
),
)
return summarize_file_hash
Expand Down
2 changes: 1 addition & 1 deletion tools/text_extractor/src/config/properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"schemaVersion": "0.0.1",
"displayName": "Text Extractor",
"functionName": "text_extractor",
"toolVersion": "0.0.39",
"toolVersion": "0.0.40",
"description": "The Text Extractor is a powerful tool designed to convert documents to its text form or Extract texts from documents",
"input": {
"description": "Document"
Expand Down
2 changes: 1 addition & 1 deletion tools/text_extractor/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def run(
self.stream_log("Preparing to write the extracted text.")
if source_name:
output_path = Path(output_dir) / f"{Path(source_name).stem}.txt"
if hasattr(self, "workflow_filestorage"):
if self.workflow_filestorage:
self.workflow_filestorage.write(
path=output_path, mode="w", data=extracted_text
)
Expand Down

0 comments on commit 6359adb

Please sign in to comment.