-
Notifications
You must be signed in to change notification settings - Fork 0
feat: support union and optional arguments #83
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
jpbrodrick89
wants to merge
19
commits into
main
Choose a base branch
from
jpb/support-anyOf
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 all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
79f70c0
Add failing tests
jpbrodrick89 ea7cf02
add support for union types, need to fix UI
jpbrodrick89 2c7ffac
use checkboxes for optional inputs
jpbrodrick89 4da8b53
make try_parse_number private
jpbrodrick89 3c84f27
Incorporate review feedback
jpbrodrick89 56f3ab7
Bring back array casting behavioru
jpbrodrick89 97af5f8
raise errors for unsupported types
jpbrodrick89 3925f31
Merge remote-tracking branch 'origin' into jpb/support-anyOf
jpbrodrick89 0f43227
Merge remote-tracking branch 'origin/jpb/support-anyOf' into jpb/supp…
jpbrodrick89 90b2bad
fix linting errors
jpbrodrick89 a627666
bring back the G :dog:
jpbrodrick89 f889dad
docs: docstring Google style guide updates
jacanchaplais fe319e2
refactor: make supported types explicit, add check for composite types
jacanchaplais 6fea286
refactor: use sets explicitly, replace comprehensions with one loop
jacanchaplais f8a5723
chore: reduce repetition for composite checking
jacanchaplais 41405f2
docs: add docstring to _is_composite
jacanchaplais 937c2d2
refactor: explicitly call NumberConstraints constructor
jacanchaplais ddd6b7c
fix: check is_all_numeric as a subset of numeric types, not equal sets
jacanchaplais 6507ffc
fix: create func to init NumberConstraints and comply with typing
jacanchaplais 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,6 +124,37 @@ This will open a browser window with the Streamlit UI where users can input valu | |
| | --------------------------------- | ---------------------------- | | ||
| |  |  | | ||
|
|
||
| ## 🔀 Union Type Support | ||
|
|
||
| `tesseract-streamlit` supports Pydantic union types (e.g., `int | str`, `float | None`) with automatic type inference: | ||
|
|
||
| ### Supported Union Patterns | ||
|
|
||
| * **Optional numbers**: `int | None`, `float | None` - Rendered as text inputs (not number inputs) with placeholder text "Leave blank if not needed". This allows the field to truly be empty. The input is parsed as an integer or float when provided. | ||
| * **Optional strings**: `str | None` - Rendered as text inputs with placeholder text. Leave blank to pass `None`. | ||
| * **Mixed scalar types**: `int | float`, `float | str`, `int | str | None` - Rendered as text inputs with automatic type casting. | ||
|
|
||
| ### Auto-Casting Behavior | ||
|
|
||
| Union type fields use a text input with automatic type detection: | ||
|
|
||
| 1. **Integers**: Input like `42` or `-23` is parsed as `int` | ||
| 2. **Floats**: Input like `3.14`, `-0.5`, or `1e-5` is parsed as `float` | ||
| 3. **Strings**: Any other input is treated as a string | ||
| 4. **None**: Leaving the field blank (for optional fields) passes `None` | ||
|
|
||
| **Example:** | ||
| ```python | ||
| class InputSchema(BaseModel): | ||
| threshold: float | str # Can accept 0.5 (float) or "auto" (string) | ||
| count: int | None = None # Optional integer, blank input passes None | ||
| ``` | ||
|
|
||
| ### Limitations | ||
|
|
||
| * **Collections of complex types**: Unions like `Model | list[Model]` or `float | list[float]` are not yet supported. These are deferred to a future release. | ||
| * **No specialized widgets**: Union fields always use text inputs. For example, `int | float` uses a text input instead of a number input with spinners. | ||
|
Comment on lines
+153
to
+156
Collaborator
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. Could you shift this down and merge it with the existing "Current limitations" section? |
||
|
|
||
| ## ⚠️ Current Limitations | ||
|
|
||
| While `tesseract-streamlit` supports Tesseracts with an `InputSchema` formed with arbitrary nesting of Pydantic models, it **does not yet support** nesting Pydantic models **inside native Python collection types** such as: | ||
|
|
||
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.
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.
Appreciate the attention to keeping the docs up to date! I do think this section is a bit gratuitous, though. I think a simple sentence somewhere to say that union and optional types in
InputSchemaare supported would be sufficient. The rest should just be intuitive from using the web UI with the placeholder text, etc.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.
Another solution could be changing the "Current limitations" section to something more positive like "Supported features and limitations", since that's basically what it is anyway. Then you could add a bullet or two there, as you see fit.