def _chat(
        self,
        message: str,
        stream: bool = False,
        chat_history: Optional[List[ChatMessage]] = None,
        **kwargs,
    ) -> Union[AgentChatResponse, StreamingAgentChatResponse]:
        """
        Call app completion service.

        Args:
            message (str): Message for chatting with LLM.
            chat_history (List[ChatMessage], `optional`): The user provided chat history. Defaults to None.

            **kwargs:
                session_id(str, `optional`): Session if for multiple rounds call.
                biz_params(dict, `optional`): The extra parameters for flow or plugin.

        Raises:
            ValueError: The request failed with http code and message.

        Returns:
            Union[AgentChatResponse, StreamingAgentChatResponse]

        """
        if stream:
            kwargs["stream"] = True

        if self.chat_session:
            kwargs["session_id"] = self._session_id

        response = Application.call(
            app_id=self.app_id,
            prompt=message,
            history=None,
            workspace=self.workspace,
            api_key=self.api_key,
            **kwargs,
        )

        if stream:
            return StreamingAgentChatResponse(
                chat_stream=(self.from_dashscope_response(rsp) for rsp in response)
            )
        else:
            if response.status_code != HTTPStatus.OK:
                raise ValueError(
                    f"Chat failed with status: {response.status_code}, request id: {response.request_id}, "
                    f"code: {response.code}, message: {response.message}"
                )

            if self._verbose:
                print("Got chat response: %s" % response)
            self._session_id = response.output.session_id

            return AgentChatResponse(response=response.output.text)

        Call app completion service.

        Args:
            message (str): Message for chatting with LLM.
            chat_history (List[ChatMessage], `optional`): The user provided chat history. Defaults to None.

            **kwargs:
                session_id(str, `optional`): Session if for multiple rounds call.
                biz_params(dict, `optional`): The extra parameters for flow or plugin.

        Raises:
            ValueError: The request failed with http code and message.

        Returns:
            Union[AgentChatResponse, StreamingAgentChatResponse]

        
llama-index-integrations/agent/llama-index-agent-dashscope/llama_index/agent/dashscope/base.py