def chat(self, messages: Sequence[ChatMessage], **kwargs) -> ChatResponse:
        """
        Generate a chat response for the given messages.

        Args:
            messages (Sequence[ChatMessage]): A sequence of chat messages.
            **kwargs: Additional keyword arguments for the API request.

        Returns:
            ChatResponse: The chat response containing a sequence of messages.

        """
        messages = chat_messages_to_list(messages)
        payload = self._build_payload(messages=messages, **kwargs)
        result = self._client.request(CHAT_API_ENDPOINT, payload)
        mo = result["choices"][-1]["message"]
        additional_kwargs = {
            "tool_calls": mo.get("tool_calls", []) or [],
        }
        return ChatResponse(
            message=ChatMessage(
                role=mo["role"],
                content=mo["content"],
                additional_kwargs=additional_kwargs,
            ),
            raw=result,
        )

        Generate a chat response for the given messages.

        Args:
            messages (Sequence[ChatMessage]): A sequence of chat messages.
            **kwargs: Additional keyword arguments for the API request.

        Returns:
            ChatResponse: The chat response containing a sequence of messages.

        
llama-index-integrations/llms/llama-index-llms-deepinfra/llama_index/llms/deepinfra/base.py