sohailshk commented on code in PR #41196:
URL: https://github.com/apache/beam/pull/41196#discussion_r4588703382


##########
sdks/python/apache_beam/ml/inference/anthropic_inference.py:
##########
@@ -116,15 +116,17 @@ def message_from_string(
     inference_args: additional arguments passed to the messages.create call.
       Common args include 'max_tokens', 'system', 'temperature', 'top_p'.
   """
-  max_tokens = inference_args.pop('max_tokens', 1024)
+  # Pass the default only when the caller gave no max_tokens, without
+  # changing inference_args: RunInference reuses that dict for every batch.
+  default_args = {} if 'max_tokens' in inference_args else {'max_tokens': 1024}

Review Comment:
   Agreed, moved in 8820eeb. The comment and the per-function defaults are 
gone: `AnthropicModelHandler.__init__` now builds the handler defaults once 
(`max_tokens=1024`, plus `system`/`output_config` when set), and `request()` 
merges them under the per-call `inference_args` before calling the request 
function. The request functions just pass `inference_args` through, and the 
caller's dict is no longer modified (that also covers the old 
`system`/`output_config` writes in `request()`). Per-call values still override 
the defaults; the handler tests cover the default, the override and the 
no-mutation case.
   
   One side effect: calling `message_from_string` directly, outside the 
handler, no longer gets `max_tokens=1024`; the docstring now says the handler 
supplies it.
   



-- 
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]

Reply via email to