-
Notifications
You must be signed in to change notification settings - Fork 4.2k
feat: Add presigned URL target models and cleanups #3486
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
Draft
cau-git
wants to merge
6
commits into
main
Choose a base branch
from
cau/service-models-presigned-batch-prep
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.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4cfab0c
Add presigned target models and regular endpoint request cleanup
cau-git eda1f6e
Rename of Regular... scheme to Batch...
cau-git 951b0d2
refactor: refactor: unify document result model and clarify response …
cau-git 0b1aa29
cleanup
cau-git a622eed
Change default to PreSignedUrlTarget from InBodyTarget
cau-git cd1203f
Revert "Change default to PreSignedUrlTarget from InBodyTarget"
cau-git 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
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
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 |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| import enum | ||
| import warnings | ||
| from datetime import datetime | ||
| from typing import Annotated, Literal, Optional | ||
|
|
||
| from docling_core.types.doc.document import DoclingDocument | ||
| from pydantic import BaseModel, Field | ||
| from pydantic import AliasChoices, AnyUrl, BaseModel, ConfigDict, Field | ||
|
|
||
| from docling.datamodel.base_models import ConversionStatus, ErrorItem | ||
| from docling.datamodel.service.tasks import TaskProcessingMeta, TaskType | ||
|
|
@@ -19,15 +20,41 @@ class ExportDocumentResponse(BaseModel): | |
| doctags_content: Optional[str] = None | ||
|
|
||
|
|
||
| class ExportResult(BaseModel): | ||
| """Container of all exported content.""" | ||
| class DocumentResultItem(BaseModel): | ||
| """Canonical document-level result with legacy ExportResult wire compatibility.""" | ||
|
|
||
| model_config = ConfigDict(populate_by_name=True, serialize_by_alias=True) | ||
|
|
||
| kind: Literal["ExportResult"] = "ExportResult" | ||
| content: ExportDocumentResponse | ||
| document: ExportDocumentResponse = Field( | ||
| validation_alias=AliasChoices("document", "content"), | ||
| serialization_alias="content", | ||
| ) | ||
| status: ConversionStatus | ||
| errors: list[ErrorItem] = [] | ||
| timings: dict[str, ProfilingItem] = {} | ||
|
|
||
| @property | ||
| def content(self) -> ExportDocumentResponse: | ||
| warnings.warn( | ||
| "DocumentResultItem.content is deprecated; use .document instead.", | ||
| DeprecationWarning, | ||
| stacklevel=2, | ||
| ) | ||
| return self.document | ||
|
|
||
| @content.setter | ||
| def content(self, value: ExportDocumentResponse) -> None: | ||
| warnings.warn( | ||
| "DocumentResultItem.content is deprecated; use .document instead.", | ||
| DeprecationWarning, | ||
| stacklevel=2, | ||
| ) | ||
| self.document = value | ||
|
|
||
|
|
||
| ExportResult = DocumentResultItem | ||
|
|
||
|
|
||
| class ZipArchiveResult(BaseModel): | ||
| """Container for a zip archive of the conversion.""" | ||
|
|
@@ -42,6 +69,27 @@ class RemoteTargetResult(BaseModel): | |
| kind: Literal["RemoteTargetResult"] = "RemoteTargetResult" | ||
|
|
||
|
|
||
| class ArtifactRef(BaseModel): | ||
| artifact_type: Literal[ | ||
| "json", "html", "markdown", "text", "doctags", "resource_bundle" | ||
| ] | ||
| mime_type: str | ||
| uri: AnyUrl | ||
| url_expires_at: datetime | None = None | ||
|
|
||
|
|
||
| class DocumentArtifactItem(BaseModel): | ||
| """Per-document result item for PresignedUrlTarget responses.""" | ||
|
|
||
| source_index: int | ||
| source_uri: str | ||
| filename: str | ||
| status: ConversionStatus | ||
| errors: list[ErrorItem] = [] | ||
| timings: dict[str, ProfilingItem] = {} | ||
| artifacts: list[ArtifactRef] = [] | ||
|
|
||
|
|
||
| class ChunkedDocumentResultItem(BaseModel): | ||
| """A single chunk of a document with its metadata and content.""" | ||
|
|
||
|
|
@@ -91,8 +139,19 @@ class ChunkedDocumentResult(BaseModel): | |
| chunking_info: Optional[dict] = None | ||
|
|
||
|
|
||
| class PresignedArtifactResult(BaseModel): | ||
| """Internal DoclingTaskResult.result union member for PresignedUrlTarget.""" | ||
|
|
||
| kind: Literal["PresignedArtifactResult"] = "PresignedArtifactResult" | ||
| documents: list[DocumentArtifactItem] | ||
|
|
||
|
|
||
| ResultType = Annotated[ | ||
| ExportResult | ZipArchiveResult | RemoteTargetResult | ChunkedDocumentResult, | ||
| ExportResult | ||
| | ZipArchiveResult | ||
| | RemoteTargetResult | ||
| | ChunkedDocumentResult | ||
| | PresignedArtifactResult, | ||
| Field(discriminator="kind"), | ||
| ] | ||
|
|
||
|
|
@@ -105,17 +164,6 @@ class DoclingTaskResult(BaseModel): | |
| num_failed: int | ||
|
|
||
|
|
||
| class ConvertDocumentResult(DoclingTaskResult): | ||
| def __init__(self, *args, **kwargs): | ||
| warnings.warn( | ||
| "ConvertDocumentResult is deprecated and will be removed in a future version. " | ||
| "Use DoclingTaskResult instead.", | ||
| DeprecationWarning, | ||
| stacklevel=2, | ||
| ) | ||
| super().__init__(*args, **kwargs) | ||
|
|
||
|
|
||
| class HealthCheckResponse(BaseModel): | ||
| status: str = "ok" | ||
|
|
||
|
|
@@ -129,14 +177,40 @@ class ClearResponse(BaseModel): | |
|
|
||
|
|
||
| class ConvertDocumentResponse(BaseModel): | ||
| """Single-document inline response with task-level timing flattened in.""" | ||
|
|
||
| document: ExportDocumentResponse | ||
| status: ConversionStatus | ||
| errors: list[ErrorItem] = [] | ||
| # Inline convert responses have no outer DoclingTaskResult envelope, so the | ||
| # task-level elapsed time is flattened onto this response model. | ||
| processing_time: float | ||
| timings: dict[str, ProfilingItem] = {} | ||
|
|
||
|
|
||
| def _to_convert_document_response( | ||
| item: DocumentResultItem, processing_time: float | ||
| ) -> "ConvertDocumentResponse": | ||
| return ConvertDocumentResponse( | ||
| document=item.document, | ||
| status=item.status, | ||
| errors=item.errors, | ||
| processing_time=processing_time, | ||
| timings=item.timings, | ||
| ) | ||
|
|
||
|
|
||
| class PresignedUrlConvertDocumentResponse(BaseModel): | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently used for S3Target and PutTarget response. How can this be deprecated? PresignedUrlConvertResponse is not going to replace it, since we said that an S3 target cannot list documents produced by default as it may be very very large, need pagination etc. |
||
| """Counts-only response model for remote targets without per-document artifacts.""" | ||
|
|
||
| processing_time: float | ||
| num_converted: int | ||
| num_succeeded: int | ||
| num_failed: int | ||
|
|
||
|
|
||
| class PresignedUrlConvertResponse(BaseModel): | ||
| documents: list[DocumentArtifactItem] | ||
| processing_time: float | ||
| num_converted: int | ||
| num_succeeded: int | ||
|
|
||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question as for ExportResult, why is ConvertDocumentResponse and DocumentResultItem both needed? Appears to have 100% overlap.
If any of this is for backward-compatibility, please explain.