-
Notifications
You must be signed in to change notification settings - Fork 641
Support UnionTypes in Optional check #2224
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
Conversation
* Use UnionType as well to confirm presence of an Optional type
aron
left a comment
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.
This is close, we still have an issue with the cog predict command and the validation.
Given this predictor:
from cog import BasePredictor, Input
class Predictor(BasePredictor):
def setup(self):
self.prefix = "hello"
def predict(
self,
text: str | None = Input(
description="Text to prefix with 'hello '", default=None
),
) -> str:
return self.prefix + " " + textRunning cog predict gives:
Starting Docker image cog-hello-world-base and running setup()...
Error while loading predictor:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/cog/server/http.py", line 159, in create_app
InputType, OutputType, is_async = cog_config.get_predictor_types(
File "/usr/local/lib/python3.8/site-packages/cog/config.py", line 171, in get_predictor_types
predictor = self._load_predictor_for_types(
File "/usr/local/lib/python3.8/site-packages/cog/config.py", line 147, in _load_predictor_for_types
module = load_full_predictor_from_file(module_path, module_name)
File "/usr/local/lib/python3.8/site-packages/cog/predictor.py", line 151, in load_full_predictor_from_file
spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 843, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "predict.py", line 4, in <module>
class Predictor(BasePredictor):
File "predict.py", line 10, in Predictor
text: str | None = Input(
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'
ⅹ Model setup failed
Co-authored-by: Aron Carroll <[email protected]> Signed-off-by: Will Sackfield <[email protected]>
Can you provide the |
|
I just changed the cog-examples hello world version. The above issue was python 3.8 which makes sense because unions wern't supported. With 3.10 I get: |
aron
left a comment
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.
Just checked this out again locally, it works! 👍
str | Nonein inputsOptional, solved by extending theUniondetection toUnionType