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

Code before:
            "seed",
            "stop_strings",
            "stop_token_ids",
            "temperature",
            "top_p",
            "guided_decoding",
        }

    @override
    def _convert_conversation_to_api_input(
        self, conversation: Conversation, generation_params: GenerationParams
    ) -> dict[str, Any]:
        """Converts a conversation to an OpenAI input.

        Documentation: https://platform.openai.com/docs/api-reference/chat/create

        Args:
            conversation: The conversation to convert.
            generation_params: Parameters for generation during inference.

        Returns:
            Dict[str, Any]: A dictionary representing the OpenAI input.
        """
        api_input = {
            "model": self._model
            if self._adapter_model is None
            else self._adapter_model,
            "messages": self._get_list_of_message_json_dicts(
                conversation.messages, group_adjacent_same_role_turns=True
            ),
            # "max_completion_tokens": generation_params.max_new_tokens,
            "temperature": generation_params.temperature,
            "top_p": generation_params.top_p,
            "frequency_penalty": generation_params.frequency_penalty,
            "presence_penalty": generation_params.presence_penalty,
            "n": 1,  # Number of completions to generate for each prompt.
            "seed": generation_params.seed,
            "logit_bias": generation_params.logit_bias,
        }

        if generation_params.guided_decoding:
            if generation_params.guided_decoding.json:
                api_input["guided_json"] = generation_params.guided_decoding.json

            elif generation_params.guided_decoding.regex is not None:
                api_input["guided_regex"] = generation_params.guided_decoding.regex

            elif generation_params.guided_decoding.choice is not None:
                api_input["guided_choice"] = generation_params.guided_decoding.choice

        if generation_params.stop_strings:

Review comment (suggestion):
Replace `if self._adapter_model is None `  with `if self._adapter_model` (we want to treat empty string as absent)

Or, alternartively: ` =  (self._adapter_model or self._model) ` . This is more compact

Code after:
            "seed",
            "stop_strings",
            "stop_token_ids",
            "temperature",
            "top_p",
            "guided_decoding",
            "max_new_tokens",
        }

    @override
    def _convert_conversation_to_api_input(
        self, conversation: Conversation, generation_params: GenerationParams
    ) -> dict[str, Any]:
        """Converts a conversation to an OpenAI input.

        Documentation: https://platform.openai.com/docs/api-reference/chat/create

        Args:
            conversation: The conversation to convert.
            generation_params: Parameters for generation during inference.

        Returns:
            Dict[str, Any]: A dictionary representing the OpenAI input.
        """
        api_input = {
            "model": (self._adapter_model if self._adapter_model else self._model),
            "messages": self._get_list_of_message_json_dicts(
                conversation.messages, group_adjacent_same_role_turns=True
            ),
            "max_tokens": generation_params.max_new_tokens,
            # "max_completion_tokens": generation_params.max_new_tokens,
            # Future transition instead of `max_tokens`. See https://github.com/vllm-project/vllm/issues/9845
            "temperature": generation_params.temperature,
            "top_p": generation_params.top_p,
            "frequency_penalty": generation_params.frequency_penalty,
            "presence_penalty": generation_params.presence_penalty,
            "n": 1,  # Number of completions to generate for each prompt.
            "seed": generation_params.seed,
            "logit_bias": generation_params.logit_bias,
        }

        if generation_params.guided_decoding:
            if generation_params.guided_decoding.json:
                api_input["guided_json"] = generation_params.guided_decoding.json

            elif generation_params.guided_decoding.regex is not None:
                api_input["guided_regex"] = generation_params.guided_decoding.regex

            elif generation_params.guided_decoding.choice is not None:
                api_input["guided_choice"] = generation_params.guided_decoding.choice