Private helper method to prepare client configuration. Returns: tuple: (api_key, workspace_id, base_url) for client initialization Raises: ValueError: If API key is not provided
(self)
| 144 | self._api_kwargs = {} |
| 145 | |
| 146 | def _prepare_client_config(self): |
| 147 | """ |
| 148 | Private helper method to prepare client configuration. |
| 149 | |
| 150 | Returns: |
| 151 | tuple: (api_key, workspace_id, base_url) for client initialization |
| 152 | |
| 153 | Raises: |
| 154 | ValueError: If API key is not provided |
| 155 | """ |
| 156 | api_key = self._api_key or os.getenv(self._env_api_key_name) |
| 157 | workspace_id = self._workspace_id or os.getenv(self._env_workspace_id_name) |
| 158 | |
| 159 | if not api_key: |
| 160 | raise ValueError( |
| 161 | f"Environment variable {self._env_api_key_name} must be set" |
| 162 | ) |
| 163 | |
| 164 | if not workspace_id: |
| 165 | log.warning(f"Environment variable {self._env_workspace_id_name} not set. Some features may not work properly.") |
| 166 | |
| 167 | # For Dashscope, we need to include the workspace ID in the base URL if provided |
| 168 | base_url = self.base_url |
| 169 | if workspace_id: |
| 170 | # Add workspace ID to headers or URL as required by Dashscope |
| 171 | base_url = f"{self.base_url.rstrip('/')}" |
| 172 | |
| 173 | return api_key, workspace_id, base_url |
| 174 | |
| 175 | def init_sync_client(self): |
| 176 | api_key, workspace_id, base_url = self._prepare_client_config() |
no outgoing calls
no test coverage detected