You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Add pydantic type making other Tesseracts callable (needed for HOTs) (#343)
#### Relevant issue or PR
Extracted from: pasteurlabs/AutoPhysics#31
Needed for HOTs in optimization etc.
#### Description of changes
Joint work with @zmheiko.
Enables passing references to target Tesseracts as input, which we may
then call. Example:
```
class InputSchema(BaseModel):
target: TesseractReference = Field(description="Tesseract to call.")
def apply(inputs: InputSchema) -> OutputSchema:
result = inputs.target.apply({"name": "Alice"})["greeting"]
...
```
Corresponding payload for an apply call:
```
{"inputs": {"target": {"type": "url", "url": "http://helloworld:8000"}}}
```
Instead of a URL, we may pass a `tesseract_api.py` path to a
`tesseract_api.py` file. The TesseractArg spins up the target in that
case. We'll likely deprecate this once Autophysics workflows / P4D cover
all local development purposes.
#### TODO
- [x] Is the Generic type (`TesseractArg[lazy]` vs
`TesseractArg[eager]`) desirable? Should we separate entirely into
`TesseractArg` and `TesseractReference`, where the former always
validates to a `Tesseract` and the latter is just two strings?
- [x] Is there a better way than lazy loading the Tesseract class?
Problem is: Like all custom Pydantic types, `TesseractArg` lives in
runtime. However, it validates to `Tesseract`, which is part of the SDK,
making the SDK a dependency of the runtime. In container images, we
currently only install the runtime though. The current approach requires
adding `tesseract_core` to the requirements only in cases where the
`TesseractArg` is actually used.
#### Testing done
CI end-to-end test included.
---------
Co-authored-by: Alessandro Angioi <alessandro.angioi@simulation.science>
0 commit comments