kaxil commented on code in PR #69624:
URL: https://github.com/apache/airflow/pull/69624#discussion_r3546166323
##########
providers/anthropic/src/airflow/providers/anthropic/hooks/anthropic.py:
##########
@@ -409,17 +409,35 @@ def count_tokens(
params["system"] = system
return self.conn.messages.count_tokens(**params).input_tokens
- def create_batch(self, requests: list[dict[str, Any]]) -> MessageBatch:
+ @staticmethod
+ def _apply_default_model(request: dict[str, Any], default_model: str) ->
dict[str, Any]:
+ """
+ Fill ``params['model']`` from ``default_model`` when the request omits
it.
+
+ The input dict is never mutated, and a request that sets its own
``model`` is
+ returned unchanged, so a single batch can still mix models across
requests.
+ """
+ params = request.get("params")
+ if not isinstance(params, dict) or params.get("model"):
Review Comment:
Yeah, intentional. `params` is the `messages.create` payload, so it also
carries the required `messages`/`max_tokens`. If it's missing or `None` the
request is already invalid and the batch API rejects it either way, so filling
in `params={"model": ...}` wouldn't rescue it, it'd just swap the SDK's error
for a more confusing one. I only fill `model` when there's a real `params` dict
that omits it, and leave a malformed request untouched so the SDK raises on it.
If you'd prefer we fail faster with a clearer message, I can add an explicit
check that raises when a request has no `params` dict. Happy to do that in this
PR.
--
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]