Skip to content

Commit

Permalink
[FEAT] FS APIs for Line item extractor (#1060)
Browse files Browse the repository at this point in the history
* FS APIs for Line item extractor

* Optimizing if-else branch
  • Loading branch information
harini-venkataraman authored Jan 10, 2025
1 parent 3a63144 commit e5e9d1e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
32 changes: 26 additions & 6 deletions prompt-service/src/unstract/prompt_service/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ def extract_line_item(
llm: LLM,
file_path: str,
metadata: Optional[dict[str, str]],
execution_source: str,
) -> dict[str, Any]:
line_item_extraction_plugin: dict[str, Any] = plugins.get(
"line-item-extraction", {}
Expand All @@ -425,13 +426,32 @@ def extract_line_item(
)

# Read file content into context
if not os.path.exists(extract_file_path):
raise FileNotFoundError(
f"The file at path '{extract_file_path}' does not exist."
)
if check_feature_flag_status(FeatureFlag.REMOTE_FILE_STORAGE):
fs_instance: FileStorage = FileStorage(FileStorageProvider.LOCAL)
if execution_source == ExecutionSource.IDE.value:
fs_instance = EnvHelper.get_storage(
storage_type=StorageType.PERMANENT,
env_name=FileStorageKeys.PERMANENT_REMOTE_STORAGE,
)
if execution_source == ExecutionSource.TOOL.value:
fs_instance = EnvHelper.get_storage(
storage_type=StorageType.TEMPORARY,
env_name=FileStorageKeys.TEMPORARY_REMOTE_STORAGE,
)

if not fs_instance.exists(extract_file_path):
raise FileNotFoundError(
f"The file at path '{extract_file_path}' does not exist."
)
context = fs_instance.read(path=extract_file_path, encoding="utf-8", mode="rb")
else:
if not os.path.exists(extract_file_path):
raise FileNotFoundError(
f"The file at path '{extract_file_path}' does not exist."
)

with open(extract_file_path, encoding="utf-8") as file:
context = file.read()
with open(extract_file_path, encoding="utf-8") as file:
context = file.read()

prompt = construct_prompt(
preamble=tool_settings.get(PSKeys.PREAMBLE, ""),
Expand Down
1 change: 1 addition & 0 deletions prompt-service/src/unstract/prompt_service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ def prompt_processor() -> Any:
llm=llm,
file_path=file_path,
metadata=metadata,
execution_source=execution_source,
)
metadata = query_usage_metadata(token=platform_key, metadata=metadata)
# TODO: Handle metrics for line-item extraction
Expand Down

0 comments on commit e5e9d1e

Please sign in to comment.