-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(api): add file_processor API skeleton #4113
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
Open
alinaryan
wants to merge
11
commits into
llamastack:main
Choose a base branch
from
alinaryan:add-file-processor-skeleton
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2664aee
feat(api): add file_processor API skeleton
alinaryan 479e627
Merge remote-tracking branch 'upstream/main' into add-file-processor-…
alinaryan 402358c
Merge remote-tracking branch 'upstream/main' into add-file-processor-…
alinaryan c2f0db9
fix: address first round of reviews
alinaryan 3f51e16
Merge remote-tracking branch 'upstream/main' into add-file-processor-…
alinaryan f7794cb
Merge remote-tracking branch 'upstream/main' into add-file-processor-…
alinaryan 377a689
fix: address second round of reviews
alinaryan adc2b07
Merge remote-tracking branch 'upstream/main' into add-file-processor-…
alinaryan cbe7ac5
Merge remote-tracking branch 'upstream/main' into add-file-processor-…
alinaryan 39b4392
Merge remote-tracking branch 'upstream/main' into add-file-processor-…
alinaryan cdf57d2
Merge branch 'main' into add-file-processor-skeleton
leseb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| sidebar_label: File Processor | ||
| title: File_Processor | ||
| --- | ||
|
|
||
| # File_Processor | ||
|
|
||
| ## Overview | ||
|
|
||
| This section contains documentation for all available providers for the **file_processor** API. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| --- | ||
| description: "Reference file processor implementation (placeholder for development)" | ||
| sidebar_label: Reference | ||
| title: inline::reference | ||
| --- | ||
|
|
||
| # inline::reference | ||
|
|
||
| ## Description | ||
|
|
||
| Reference file processor implementation (placeholder for development) | ||
|
|
||
| ## Sample Configuration | ||
|
|
||
| ```yaml | ||
| {} | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the terms described in the LICENSE file in | ||
| # the root directory of this source tree. | ||
|
|
||
| from .file_processor import * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the terms described in the LICENSE file in | ||
| # the root directory of this source tree. | ||
|
|
||
| from typing import Any, Protocol, runtime_checkable | ||
|
|
||
| from pydantic import BaseModel | ||
|
|
||
| from llama_stack.apis.common.tracing import telemetry_traceable | ||
| from llama_stack.apis.vector_io.vector_io import Chunk, VectorStoreChunkingStrategy | ||
cdoern marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| from llama_stack.apis.version import LLAMA_STACK_API_V1ALPHA | ||
| from llama_stack.schema_utils import json_schema_type, webmethod | ||
|
|
||
|
|
||
| @json_schema_type | ||
| class ProcessFileRequest(BaseModel): | ||
| """Request for processing a file into structured content.""" | ||
|
|
||
| file_data: bytes | ||
| """Raw file data to process.""" | ||
|
|
||
| filename: str | ||
| """Original filename for format detection and processing hints.""" | ||
|
|
||
| options: dict[str, Any] | None = None | ||
| """Optional processing options. Provider-specific parameters.""" | ||
|
|
||
| chunking_strategy: VectorStoreChunkingStrategy | None = None | ||
| """Optional chunking strategy for splitting content into chunks.""" | ||
|
|
||
| include_embeddings: bool = False | ||
| """Whether to generate embeddings for chunks.""" | ||
|
|
||
|
|
||
| @json_schema_type | ||
| class ProcessedContent(BaseModel): | ||
| """Result of file processing operation.""" | ||
|
|
||
| content: str | ||
| """Extracted text content from the file.""" | ||
|
|
||
| chunks: list[Chunk] | None = None | ||
| """Optional chunks if chunking strategy was provided.""" | ||
|
|
||
| embeddings: list[list[float]] | None = None | ||
| """Optional embeddings for chunks if requested.""" | ||
|
|
||
| metadata: dict[str, Any] | ||
| """Processing metadata including processor name, timing, and provider-specific data.""" | ||
|
|
||
|
|
||
| @telemetry_traceable | ||
| @runtime_checkable | ||
| class FileProcessor(Protocol): | ||
| """ | ||
| File Processor API for converting files into structured, processable content. | ||
| This API provides a flexible interface for processing various file formats | ||
| (PDFs, documents, images, etc.) into text content that can be used for | ||
| vector store ingestion, RAG applications, or standalone content extraction. | ||
| The API supports: | ||
| - Multiple file formats through extensible provider architecture | ||
| - Configurable processing options per provider | ||
| - Integration with vector store chunking strategies | ||
| - Optional embedding generation for chunks | ||
| - Rich metadata about processing results | ||
| Future providers can extend this interface to support additional formats, | ||
| processing capabilities, and optimization strategies. | ||
| """ | ||
|
|
||
| @webmethod(route="/file-processor/process", method="POST", level=LLAMA_STACK_API_V1ALPHA) | ||
alinaryan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| async def process_file( | ||
| self, | ||
| file_data: bytes, | ||
| filename: str, | ||
| options: dict[str, Any] | None = None, | ||
| chunking_strategy: VectorStoreChunkingStrategy | None = None, | ||
| include_embeddings: bool = False, | ||
| ) -> ProcessedContent: | ||
| """ | ||
| Process a file into structured content with optional chunking and embeddings. | ||
| This method processes raw file data and converts it into text content for applications such as vector store ingestion. | ||
| :param file_data: Raw bytes of the file to process. | ||
| :param filename: Original filename for format detection. | ||
| :param options: Provider-specific processing options (e.g., OCR settings, output format). | ||
| :param chunking_strategy: Optional strategy for splitting content into chunks. | ||
| :param include_embeddings: Whether to generate embeddings for chunks. | ||
| :returns: ProcessedContent with extracted text, optional chunks, and metadata. | ||
| """ | ||
| ... | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the terms described in the LICENSE file in | ||
| # the root directory of this source tree. |
15 changes: 15 additions & 0 deletions
15
src/llama_stack/providers/inline/file_processor/reference/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the terms described in the LICENSE file in | ||
| # the root directory of this source tree. | ||
|
|
||
| from .config import ReferenceFileProcessorImplConfig | ||
|
|
||
|
|
||
| async def get_provider_impl(config: ReferenceFileProcessorImplConfig, deps): | ||
| from .reference import ReferenceFileProcessorImpl | ||
|
|
||
| impl = ReferenceFileProcessorImpl(config, deps) | ||
| await impl.initialize() | ||
| return impl |
15 changes: 15 additions & 0 deletions
15
src/llama_stack/providers/inline/file_processor/reference/config.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the terms described in the LICENSE file in | ||
| # the root directory of this source tree. | ||
|
|
||
| from pydantic import BaseModel | ||
|
|
||
|
|
||
| class ReferenceFileProcessorImplConfig(BaseModel): | ||
| """Configuration for the reference file processor implementation.""" | ||
|
|
||
| @staticmethod | ||
| def sample_run_config(**kwargs): | ||
| return {} |
42 changes: 42 additions & 0 deletions
42
src/llama_stack/providers/inline/file_processor/reference/reference.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the terms described in the LICENSE file in | ||
| # the root directory of this source tree. | ||
|
|
||
| from typing import Any | ||
|
|
||
| from llama_stack.apis.file_processor import FileProcessor, ProcessedContent | ||
| from llama_stack.apis.vector_io import VectorStoreChunkingStrategy | ||
|
|
||
| from .config import ReferenceFileProcessorImplConfig | ||
|
|
||
|
|
||
| class ReferenceFileProcessorImpl(FileProcessor): | ||
| """Reference implementation of the FileProcessor API.""" | ||
|
|
||
| def __init__(self, config: ReferenceFileProcessorImplConfig, deps: dict[str, Any]): | ||
| self.config = config | ||
| self.deps = deps | ||
|
|
||
| async def initialize(self) -> None: | ||
| pass | ||
|
|
||
| async def process_file( | ||
alinaryan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
cdoern marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| self, | ||
| file_data: bytes, | ||
alinaryan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| filename: str, | ||
| options: dict[str, Any] | None = None, | ||
alinaryan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| chunking_strategy: VectorStoreChunkingStrategy | None = None, | ||
| include_embeddings: bool = False, | ||
| ) -> ProcessedContent: | ||
| """Process a file into structured content.""" | ||
| return ProcessedContent( | ||
| content="Placeholder content", | ||
| chunks=None, | ||
| embeddings=None, | ||
| metadata={ | ||
| "processor": "reference", | ||
| "filename": filename, | ||
| }, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the terms described in the LICENSE file in | ||
| # the root directory of this source tree. | ||
|
|
||
| from llama_stack.providers.datatypes import Api, InlineProviderSpec, ProviderSpec | ||
|
|
||
|
|
||
| def available_providers() -> list[ProviderSpec]: | ||
| return [ | ||
| InlineProviderSpec( | ||
| api=Api.file_processor, | ||
| provider_type="inline::reference", | ||
| pip_packages=[], | ||
| module="llama_stack.providers.inline.file_processor.reference", | ||
| config_class="llama_stack.providers.inline.file_processor.reference.config.ReferenceFileProcessorImplConfig", | ||
| description="Reference file processor implementation (placeholder for development)", | ||
| ), | ||
| ] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.