Repository: oumi-ai/oumi
File: src/oumi/inference/remote_inference_engine.py (Python)

Code before:

        Returns:
            Conversation: Inference output.
        """
        if inference_config is None:
            remote_params = self._remote_params
            generation_params = self._generation_params
            model_params = self._model_params
            output_path = None
        else:
            remote_params = inference_config.remote_params or self._remote_params
            generation_params = inference_config.generation or self._generation_params
            model_params = inference_config.model or self._model_params
            output_path = inference_config.output_path

        self._set_required_fields_for_inference(remote_params)
        if not remote_params.api_url:
            raise ValueError("API URL is required for remote inference.")
        if not self._get_api_key(remote_params):
            if remote_params.api_key_env_varname:
                raise ValueError(
                    "An API key is required for remote inference with the "
                    f"`{self.__class__.__name__}` inference engine. "
                    "Please set the environment variable "
                    f"`{remote_params.api_key_env_varname}` as follows: "
                    f"`os.environ['{remote_params.api_key_env_varname}'] = <value>`"
                )
        async with semaphore:
            api_input = self._convert_conversation_to_api_input(
                conversation, generation_params, model_params
            )
            headers = self._get_request_headers(remote_params)
            retries = 0
            failure_reason = None
            # Retry the request if it fails.
            for _ in range(remote_params.max_retries + 1):
                async with session.post(
                    remote_params.api_url,
                    json=api_input,
                    headers=headers,
                    timeout=remote_params.connection_timeout,
                ) as response:
                    response_json = await response.json()
                    if response.status == 200:
                        result = self._convert_api_output_to_conversation(
                            response_json, conversation
                        )
                        if output_path:
                            # Write what we have so far to our scratch directory.
                            self._save_conversation(
                                result,

Review comment (suggestion):
This is only true if they're running in a python environment. This message will not be correct if they're using the CLI.

I'd consider ending the error message after 
```
f"Please set the environment variable `{remote_params.api_key_env_varname}"
```

They should be able to figure out fairly quickly how to set an env var for their environment.

Code after:

        Returns:
            Conversation: Inference output.
        """
        if inference_config is None:
            remote_params = self._remote_params
            generation_params = self._generation_params
            model_params = self._model_params
            output_path = None
        else:
            remote_params = inference_config.remote_params or self._remote_params
            generation_params = inference_config.generation or self._generation_params
            model_params = inference_config.model or self._model_params
            output_path = inference_config.output_path

        self._set_required_fields_for_inference(remote_params)
        if not remote_params.api_url:
            raise ValueError("API URL is required for remote inference.")
        if not self._get_api_key(remote_params):
            if remote_params.api_key_env_varname:
                raise ValueError(
                    "An API key is required for remote inference with the "
                    f"`{self.__class__.__name__}` inference engine. "
                    "Please set the environment variable "
                    f"`{remote_params.api_key_env_varname}`."
                )
        async with semaphore:
            api_input = self._convert_conversation_to_api_input(
                conversation, generation_params, model_params
            )
            headers = self._get_request_headers(remote_params)
            retries = 0
            failure_reason = None
            # Retry the request if it fails.
            for _ in range(remote_params.max_retries + 1):
                async with session.post(
                    remote_params.api_url,
                    json=api_input,
                    headers=headers,
                    timeout=remote_params.connection_timeout,
                ) as response:
                    response_json = await response.json()
                    if response.status == 200:
                        result = self._convert_api_output_to_conversation(
                            response_json, conversation
                        )
                        if output_path:
                            # Write what we have so far to our scratch directory.
                            self._save_conversation(
                                result,
                                self._get_scratch_filepath(output_path),