-
Notifications
You must be signed in to change notification settings - Fork 5
Add ability to auto-generate context classes from function signature #170
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Nijat Khanbabayev <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## nk/local_model_context_registration #170 +/- ##
=====================================================================
Coverage 95.50% 95.51%
=====================================================================
Files 132 132
Lines 8463 8689 +226
Branches 521 534 +13
=====================================================================
+ Hits 8083 8299 +216
- Misses 262 272 +10
Partials 118 118 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
From an implementation perspective, I get why it looks like this: @Flow.call
@dynamic_context
def __call__(self, *, x: int, y: str = "default") -> GenericResult:
return GenericResult(value=f"{x}-{y}")But I feel like from a user perspective, it would be nice to have it look like this @Flow.call(dynamic_context=True)
def __call__(self, *, x: int, y: str = "default") -> GenericResult:
return GenericResult(value=f"{x}-{y}") |
|
I also wonder whether calling it |
|
why does the user have to indicate that its a dynamic context at all manually? isn't this implied by not having a single arg |
…c_context_v2 Signed-off-by: Nijat Khanbabayev <[email protected]>
1600618 to
f89ff9f
Compare
Signed-off-by: Nijat Khanbabayev <[email protected]>
I'm a bit wary of this because it feels like it can open a whole can of worms of edge cases (generics, forward reference for contexts), and might be confusing if someone makes a mistake (maybe names |
good point, I went with # Auto Context Example:
class MyModel(CallableModel):
@Flow.call(auto_context=True)
def __call__(self, *, x: int, y: str = "default") -> GenericResult:
return GenericResult(value=f"{x}-{y}")
model = MyModel()
model(x=42) # Call with kwargs directly
# With Parent Context:
class MyModel2(CallableModel):
@Flow.call(auto_context=DateContext)
def __call__(self, *, date: date, extra: int = 0) -> GenericResult:
return GenericResult(value=date.day + extra)
# The generated context inherits from DateContext, so it's compatible
# with infrastructure expecting DateContext instances. |
No description provided.