kaxil commented on code in PR #71462:
URL: https://github.com/apache/airflow/pull/71462#discussion_r3765824776
##########
providers/anthropic/src/airflow/providers/anthropic/hooks/anthropic.py:
##########
@@ -123,6 +126,49 @@ def is_terminal(cls, status: str) -> bool:
#: ``session.status_idle`` stop reason emitted when a session stops against
its budget.
BUDGET_REACHED = "budget_reached"
+#: What a caller may pass as a session budget: an amount in USD, or the raw
API payload.
+BudgetSpec = str | int | float | Decimal | Mapping[str, Any]
+
+
+def build_budget(budget: BudgetSpec) -> dict[str, Any]:
Review Comment:
Done -- and better than a local one, because the SDK already publishes this
shape at the version this provider floors on.
`build_budget` now returns `BetaManagedAgentsBudgetLimitParam` (`{"type":
Literal["limit"], "max_list_cost": BetaMonetaryAmountParam}`), imported under
`TYPE_CHECKING`. That also gets `currency` typed as the SDK's `BetaCurrency`
literal rather than a bare `str`, which a hand-rolled TypedDict here would have
lost.
Worth noting for anyone checking: the type is new in `anthropic` 0.121.0,
the same release that added `sessions.create(budget=...)`. On 0.120.2 neither
exists, so introspecting the previous release makes it look as though the
payload is untyped. 0.121.0 is this provider's declared floor, so the published
type is available.
The raw-mapping branch casts rather than validates. Accepting a raw payload
exists precisely so a caller can reach a field the provider does not model yet,
so checking its shape there would defeat the purpose.
##########
providers/anthropic/src/airflow/providers/anthropic/hooks/anthropic.py:
##########
@@ -123,6 +126,49 @@ def is_terminal(cls, status: str) -> bool:
#: ``session.status_idle`` stop reason emitted when a session stops against
its budget.
BUDGET_REACHED = "budget_reached"
+#: What a caller may pass as a session budget: an amount in USD, or the raw
API payload.
Review Comment:
Fair point, and the counts back it up: `#:` appears 24 times across all of
`providers/`, 0 in `airflow-core/src`, and 3 in `task-sdk/src` -- and most of
the provider hits are a single Amazon hook. It is not a convention this
codebase actually uses.
Switched the line this PR adds to a plain `#`. The other 13 in this file
predate the PR, so I left them rather than widen the diff -- happy to sweep
them in a follow-up if you would rather the file be consistent.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]