data = response.get("data")
            for m in data.get("messages"):
                chunk = _convert_delta_to_message_chunk(m, default_chunk_class)
                default_chunk_class = chunk.__class__
                yield ChatGenerationChunk(message=chunk)
                if run_manager:
                    run_manager.on_llm_new_token(chunk.content)
    def _chat(self, messages: List[BaseMessage], **kwargs: Any) -> requests.Response:
        if self.baichuan_secret_key is None:
            raise ValueError("Baichuan secret key is not set.")
        parameters = {**self._default_params, **kwargs}
        model = parameters.pop("model")
        headers = parameters.pop("headers", {})
        payload = {
            "model": model,
            "messages": [_convert_message_to_dict(m) for m in messages],
            "parameters": parameters,
        }
        timestamp = int(time.time())
        url = self.baichuan_api_base
        if self.streaming:
            url = f"{url}/stream"
        url = f"{url}/chat"
        api_key = ""
        if self.baichuan_api_key:
            api_key = self.baichuan_api_key.get_secret_value()
        res = requests.post(
            url=url,
            timeout=self.request_timeout,
            headers={
                "Content-Type": "application/json",
                "Authorization": f"Bearer {api_key}",
                "X-BC-Timestamp": str(timestamp),
                "X-BC-Signature": _signature(
                    secret_key=self.baichuan_secret_key,
                    payload=payload,
                    timestamp=timestamp,
                ),
                "X-BC-Sign-Algo": "MD5",
                **headers,
            },
            json=payload,
            stream=self.streaming,