def METHOD_NAME(
    self, prompt: Union[str, List[Dict]], base_payload: Dict, kwargs_with_defaults: Dict, stream: bool
):
    """
    For more details, see [OpenAI ChatGPT API reference](https://platform.openai.com/docs/api-reference/chat).
    """
    if isinstance(prompt, str):
        messages = [{"role": "user", "content": prompt}]
    elif isinstance(prompt, list) and len(prompt) > 0 and isinstance(prompt[0], dict):
        messages = prompt
    else:
        raise ValueError(
            f"The prompt format is different than what the model expects. "
            f"The model {self.model_name_or_path} requires either a string or messages in the ChatML format. "
            f"For more details, see this [GitHub discussion](https://github.com/openai/openai-python/blob/main/chatml.md)."
        )
    extra_payload = {"messages": messages}
    payload = {**base_payload, **extra_payload}
    if not stream:
        response = openai_request(url=self.url, headers=self.headers, payload=payload)
        _check_openai_finish_reason(result=response, payload=payload)
        assistant_response = [choice["message"]["content"].strip() for choice in response["choices"]]
    else:
        response = openai_request(
            url=self.url, headers=self.headers, payload=payload, read_response=False, stream=True
        )
        handler: TokenStreamingHandler = kwargs_with_defaults.pop("stream_handler", DefaultTokenStreamingHandler())
        assistant_response = self._process_streaming_response(response=response, stream_handler=handler)
    # Although ChatGPT generates text until stop words are encountered, unfortunately it includes the stop word
    # We want to exclude it to be consistent with other invocation layers
    if "stop" in kwargs_with_defaults and kwargs_with_defaults["stop"] is not None:
        stop_words = kwargs_with_defaults["stop"]
        for idx, _ in enumerate(assistant_response):
            for stop_word in stop_words:
                assistant_response[idx] = assistant_response[idx].replace(stop_word, "").strip()
    return assistant_response