Initialize OpenAI-compatible API client for embeddings.
(self, api_key: Optional[str], base_url: Optional[str])
| 201 | |
| 202 | except ImportError: |
| 203 | raise ImportError("Please install sentence-transformers: pip install sentence-transformers") |
| 204 | |
| 205 | def _init_api_client(self, api_key: Optional[str], base_url: Optional[str]): |
| 206 | """Initialize OpenAI-compatible API client for embeddings.""" |
| 207 | from openai import OpenAI |
| 208 | |
| 209 | self._openai_client = OpenAI( |
| 210 | api_key=api_key or os.environ.get("OPENAI_API_KEY", "not-needed"), |
| 211 | base_url=base_url or os.environ.get("EMBEDDING_BASE_URL"), |
| 212 | timeout=60, |
| 213 | ) |
| 214 | logger.info(f"Embedding API client initialized, model={self.model_name}") |
| 215 |