karthik-0306 opened a new issue, #41712:
URL: https://github.com/apache/beam/issues/41712
### What happened?
Passing `env_vars` to any of the four remote model handlers fails in the
constructor:
```python
from apache_beam.ml.inference.openai_inference import OpenAIModelHandler
from apache_beam.ml.inference.openai_inference import
chat_completion_from_string
OpenAIModelHandler(
model_name='gpt-4o-mini',
request_fn=chat_completion_from_string,
api_key='key',
env_vars={'HTTPS_PROXY': 'http://proxy:8080'})
```
```
TypeError: RemoteModelHandler.__init__() got an unexpected keyword argument
'env_vars'
```
`AnthropicModelHandler`, `GeminiModelHandler` and `VertexAIModelHandlerJSON`
raise the same error.
Each handler reads the argument with `self._env_vars =
kwargs.get('env_vars', {})`, which leaves it in `kwargs`, and then passes
`**kwargs` to `RemoteModelHandler.__init__`, which doesn't accept it:
- `openai_inference.py`, line 320
- `anthropic_inference.py`, line 239
- `gemini_inference.py`, line 226
- `vertex_ai_inference.py`, line 135
For `VertexAIModelHandlerJSON` this is a regression: it extended
`ModelHandler` and accepted `env_vars` until it moved to `RemoteModelHandler`
in #34578 (first released in 2.65.0).
Expected: the handler is created, and the variables are set on the worker
before the client is created, as with other model handlers. The rest of that
path already works: if `_env_vars` is set on the handler after construction,
`RunInference` applies it and `request_fn` sees the value.
I'm working on a fix and will open a PR. The plan is to take `env_vars` out
of `kwargs` (`kwargs.pop`) in the four handlers and add a test for each.
Version: master at 0c549fa6c8 (2.79.0.dev)
### Issue Priority
Priority: 2 (default / most bugs should be filed as P2)
### Issue Components
- [x] Component: Python SDK
- [ ] Component: Java SDK
- [ ] Component: Go SDK
- [ ] Component: Typescript SDK
- [ ] Component: IO connector
- [ ] Component: Beam YAML
- [ ] Component: Beam examples
- [ ] Component: Beam playground
- [ ] Component: Beam katas
- [ ] Component: Website
- [ ] Component: Infrastructure
- [ ] Component: Spark Runner
- [ ] Component: Flink Runner
- [ ] Component: Prism Runner
- [ ] Component: Hazelcast Jet Runner
- [ ] Component: Google Cloud Dataflow Runner
--
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]