-
Notifications
You must be signed in to change notification settings - Fork 165
feat: V2 parse & extract SDK support (client.v2) #105
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
Merged
Merged
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
6e12d7f
feat(v2): resolve dual V1/V2 base URLs from environment
yzld2002 d28a50f
feat(v2): add V2 response and unified Job types
yzld2002 c746dee
test: assert V2ParseResponse/V2ExtractResult retain unknown fields
yzld2002 b37cf9b
feat(v2): normalize parse/extract job envelopes into one Job shape
yzld2002 e93656c
feat(v2): accept pydantic model / dict / json string as extract schema
yzld2002 65c82cc
feat(v2): add V2 error types and 504 sync-timeout wrapper
yzld2002 ebb0695
feat(v2): add v2 sub-client container, absolute-URL mixin, and job wa…
yzld2002 123dc7a
feat(v2): add client.v2.files.upload staging on the ADE host
yzld2002 7ad9a12
feat(v2): add client.v2.parse sync parse with 206 + save_to + 504 han…
yzld2002 2a60b91
test(v2): add regression test for parse multipart sentinel filtering
yzld2002 10eae76
feat(v2): add client.v2.parse_jobs create/list/get/wait with normaliz…
yzld2002 30aba43
feat(v2): add client.v2.extract sync extract with schema coercion + i…
yzld2002 5390b55
feat(v2): add client.v2.extract_jobs create/list/get/wait
yzld2002 18cdc41
test(v2): async parity smoke tests; close extract_jobs coverage gaps
yzld2002 083e406
fix(v2): support pydantic v1 in schema coercion
yzld2002 9a5a0c9
fix(v2): deep-copy pydantic v1 schema before mutating (cache corruption)
yzld2002 0b5e195
docs(v2): document client.v2 sub-client, environments, and add examples
yzld2002 c57b6ca
docs(v2): add live smoke-test harness for the V2 endpoints
yzld2002 457335f
fix(v2): strict has_more bool + preserve created_at=0 (review)
yzld2002 d372e55
ci: re-trigger PR gates so surface-lock sees the override label
yzld2002 6e4baa5
fix(v2): treat explicit None as unset in body/query builders + doc fi…
yzld2002 29386a2
Potential fix for pull request finding
yzld2002 407bdc7
fix(v2): V2 API host is api.ade.[env] (aide.[env] is spec-only/SSO-ga…
yzld2002 df12d33
fix(v2): default Job status to pending when create envelope omits it …
yzld2002 6950460
fix(v2): correct 504 message + Job.raw default_factory (review)
yzld2002 3890816
fix(v2): tolerate unknown job status; lock Job.raw construct-path ind…
yzld2002 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 |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| #!/usr/bin/env -S rye run python | ||
| """Runnable example: extract structured data with the V2 (client.v2) sub-client, | ||
| using a pydantic model directly as the extraction schema. | ||
|
|
||
| This targets the ADE gateway host (aide.[env].landing.ai), separate from the | ||
| V1 host used by client.extract(). It is purely additive -- V1 usage elsewhere | ||
| in this SDK is unaffected. | ||
|
|
||
| Set VISION_AGENT_API_KEY (and optionally LANDINGAI_ADE_ENVIRONMENT) before running: | ||
|
|
||
| export VISION_AGENT_API_KEY="My Apikey" | ||
| export LANDINGAI_ADE_ENVIRONMENT="staging" # optional; defaults to "production" | ||
| ./examples/v2_extract.py | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pydantic import Field, BaseModel | ||
|
|
||
| from landingai_ade import LandingAIADE | ||
| from landingai_ade.types.v2 import V2ExtractResult | ||
|
|
||
|
|
||
| class Invoice(BaseModel): | ||
| total: str = Field(description="Invoice grand total") | ||
| vendor: str = Field(description="Name of the vendor issuing the invoice") | ||
|
|
||
|
|
||
| # apikey is read from VISION_AGENT_API_KEY; environment from LANDINGAI_ADE_ENVIRONMENT | ||
| # (or pass apikey=..., environment=... explicitly). | ||
| client = LandingAIADE() | ||
|
|
||
| # `schema` accepts a pydantic BaseModel subclass directly -- it's coerced to a | ||
| # JSON Schema dict for you. A dict or a JSON-encoded string also work. | ||
| result = client.v2.extract( | ||
| schema=Invoice, | ||
| markdown_url="https://example.com/invoice.md", | ||
| strict=False, # prune unsupported schema fields instead of raising a 422 | ||
| ) | ||
| print(result.extraction) | ||
|
|
||
| # Long-running extractions can instead go through the async jobs route: | ||
| job = client.v2.extract_jobs.create(schema=Invoice, markdown_url="https://example.com/invoice.md") | ||
| done = client.v2.extract_jobs.wait(job.job_id, timeout=600) | ||
| if isinstance(done.result, V2ExtractResult): | ||
| print(done.result.extraction) | ||
| else: | ||
| print(f"No result available (error={done.error})") |
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,43 @@ | ||
| #!/usr/bin/env -S rye run python | ||
| """Runnable example: parse a document with the V2 (client.v2) sub-client. | ||
|
|
||
| This targets the ADE gateway host (aide.[env].landing.ai), separate from the | ||
| V1 host used by client.parse(). It is purely additive -- V1 usage elsewhere in | ||
| this SDK is unaffected. | ||
|
|
||
| Set VISION_AGENT_API_KEY (and optionally LANDINGAI_ADE_ENVIRONMENT) before running: | ||
|
|
||
| export VISION_AGENT_API_KEY="My Apikey" | ||
| export LANDINGAI_ADE_ENVIRONMENT="staging" # optional; defaults to "production" | ||
| ./examples/v2_parse.py | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| from landingai_ade import LandingAIADE | ||
| from landingai_ade.types.v2 import V2ParseResponse | ||
|
|
||
| # apikey is read from VISION_AGENT_API_KEY; environment from LANDINGAI_ADE_ENVIRONMENT | ||
| # (or pass apikey=..., environment=... explicitly). | ||
| client = LandingAIADE() | ||
|
|
||
| document_path = Path(__file__).parent / "sample.pdf" | ||
|
|
||
| # Create an async parse job for a (potentially large) document. | ||
| job = client.v2.parse_jobs.create(document=document_path, priority="priority") | ||
| print(f"Created parse job {job.job_id} (status={job.status})") | ||
|
|
||
| # Block until the job reaches a terminal state. | ||
| done = client.v2.parse_jobs.wait(job.job_id, timeout=600) | ||
| print(f"Job finished with status={done.status}") | ||
|
|
||
| if isinstance(done.result, V2ParseResponse): | ||
| print(done.result.markdown[:200] if done.result.markdown else None) | ||
| else: | ||
| print(f"No result available (error={done.error})") | ||
|
|
||
| # For smaller documents you can skip the job/wait dance entirely: | ||
| sync_result = client.v2.parse(document=document_path) | ||
| print(sync_result.markdown[:200] if sync_result.markdown else None) |
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.
Uh oh!
There was an error while loading. Please reload this page.