| 
														 | 
														 | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														from urllib.parse import urljoin | 
														 | 
														 | 
														from urllib.parse import urljoin | 
													
													
												
													
														 | 
														 | 
														
  | 
														 | 
														 | 
														
  | 
													
													
												
													
														 | 
														 | 
														import requests | 
														 | 
														 | 
														import requests | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														from requests.exceptions import JSONDecodeError | 
													
													
												
													
														 | 
														 | 
														from huggingface_hub import snapshot_download | 
														 | 
														 | 
														from huggingface_hub import snapshot_download | 
													
													
												
													
														 | 
														 | 
														from zhipuai import ZhipuAI | 
														 | 
														 | 
														from zhipuai import ZhipuAI | 
													
													
												
													
														 | 
														 | 
														import os | 
														 | 
														 | 
														import os | 
													
													
												
											
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														                "input": texts[i:i + batch_size], | 
														 | 
														 | 
														                "input": texts[i:i + batch_size], | 
													
													
												
													
														 | 
														 | 
														                'encoding_type': 'float' | 
														 | 
														 | 
														                'encoding_type': 'float' | 
													
													
												
													
														 | 
														 | 
														            } | 
														 | 
														 | 
														            } | 
													
													
												
													
														 | 
														 | 
														            res = requests.post(self.base_url, headers=self.headers, json=data).json() | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														            response = requests.post(self.base_url, headers=self.headers, json=data) | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														            try: | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														                res = response.json() | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														            except JSONDecodeError as e: | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														                logging.error(f"JSON decode error: {e}\nResponse content: {response.text[:2000]}") | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														                raise | 
													
													
												
													
														 | 
														 | 
														            ress.extend([d["embedding"] for d in res["data"]]) | 
														 | 
														 | 
														            ress.extend([d["embedding"] for d in res["data"]]) | 
													
													
												
													
														 | 
														 | 
														            token_count += self.total_token_count(res) | 
														 | 
														 | 
														            token_count += self.total_token_count(res) | 
													
													
												
													
														 | 
														 | 
														        return np.array(ress), token_count | 
														 | 
														 | 
														        return np.array(ress), token_count | 
													
													
												
											
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														                "encoding_format": "float", | 
														 | 
														 | 
														                "encoding_format": "float", | 
													
													
												
													
														 | 
														 | 
														                "truncate": "END", | 
														 | 
														 | 
														                "truncate": "END", | 
													
													
												
													
														 | 
														 | 
														            } | 
														 | 
														 | 
														            } | 
													
													
												
													
														 | 
														 | 
														            res = requests.post(self.base_url, headers=self.headers, json=payload).json() | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														            response = requests.post(self.base_url, headers=self.headers, json=payload) | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														            try: | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														                res = response.json() | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														            except JSONDecodeError as e: | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														                logging.error(f"JSON decode error: {e}\nResponse content: {response.text[:2000]}") | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														                raise | 
													
													
												
													
														 | 
														 | 
														            ress.extend([d["embedding"] for d in res["data"]]) | 
														 | 
														 | 
														            ress.extend([d["embedding"] for d in res["data"]]) | 
													
													
												
													
														 | 
														 | 
														            token_count += self.total_token_count(res) | 
														 | 
														 | 
														            token_count += self.total_token_count(res) | 
													
													
												
													
														 | 
														 | 
														        return np.array(ress), token_count | 
														 | 
														 | 
														        return np.array(ress), token_count | 
													
													
												
											
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														                "input": texts_batch, | 
														 | 
														 | 
														                "input": texts_batch, | 
													
													
												
													
														 | 
														 | 
														                "encoding_format": "float", | 
														 | 
														 | 
														                "encoding_format": "float", | 
													
													
												
													
														 | 
														 | 
														            } | 
														 | 
														 | 
														            } | 
													
													
												
													
														 | 
														 | 
														            res = requests.post(self.base_url, json=payload, headers=self.headers).json() | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														            response = requests.post(self.base_url, json=payload, headers=self.headers) | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														            try: | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														                res = response.json() | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														            except JSONDecodeError as e: | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														                logging.error(f"JSON decode error: {e}\nResponse content: {response.text[:2000]}") | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														                raise | 
													
													
												
													
														 | 
														 | 
														            if "data" not in res or not isinstance(res["data"], list) or len(res["data"]) != len(texts_batch): | 
														 | 
														 | 
														            if "data" not in res or not isinstance(res["data"], list) or len(res["data"]) != len(texts_batch): | 
													
													
												
													
														 | 
														 | 
														                raise ValueError(f"SILICONFLOWEmbed.encode got invalid response from {self.base_url}") | 
														 | 
														 | 
														                raise ValueError(f"SILICONFLOWEmbed.encode got invalid response from {self.base_url}") | 
													
													
												
													
														 | 
														 | 
														            ress.extend([d["embedding"] for d in res["data"]]) | 
														 | 
														 | 
														            ress.extend([d["embedding"] for d in res["data"]]) | 
													
													
												
											
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														            "input": text, | 
														 | 
														 | 
														            "input": text, | 
													
													
												
													
														 | 
														 | 
														            "encoding_format": "float", | 
														 | 
														 | 
														            "encoding_format": "float", | 
													
													
												
													
														 | 
														 | 
														        } | 
														 | 
														 | 
														        } | 
													
													
												
													
														 | 
														 | 
														        res = requests.post(self.base_url, json=payload, headers=self.headers).json() | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														        response = requests.post(self.base_url, json=payload, headers=self.headers).json() | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														        try: | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														            res = response.json() | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														        except JSONDecodeError as e: | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														            logging.error(f"JSON decode error: {e}\nResponse content: {response.text[:2000]}") | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														            raise | 
													
													
												
													
														 | 
														 | 
														        if "data" not in res or not isinstance(res["data"], list) or len(res["data"])!= 1: | 
														 | 
														 | 
														        if "data" not in res or not isinstance(res["data"], list) or len(res["data"])!= 1: | 
													
													
												
													
														 | 
														 | 
														            raise ValueError(f"SILICONFLOWEmbed.encode_queries got invalid response from {self.base_url}") | 
														 | 
														 | 
														            raise ValueError(f"SILICONFLOWEmbed.encode_queries got invalid response from {self.base_url}") | 
													
													
												
													
														 | 
														 | 
														        return np.array(res["data"][0]["embedding"]), self.total_token_count(res) | 
														 | 
														 | 
														        return np.array(res["data"][0]["embedding"]), self.total_token_count(res) |