Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] FS APIs for Line item extractor #1060

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
gaya3-zipstack marked this conversation as resolved.
Show resolved Hide resolved
) -> 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,
gaya3-zipstack marked this conversation as resolved.
Show resolved Hide resolved
)
metadata = query_usage_metadata(token=platform_key, metadata=metadata)
# TODO: Handle metrics for line-item extraction
Expand Down