repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import os |
| #2 | import warnings |
| #3 | from typing import Optional |
| #4 | |
| #5 | from chromadb.utils.embedding_functions import OpenAIEmbeddingFunction |
| #6 | |
| #7 | from embedchain.config import BaseEmbedderConfig |
| #8 | from embedchain.embedder.base import BaseEmbedder |
| #9 | from embedchain.models import VectorDimensions |
| #10 | |
| #11 | |
| #12 | class OpenAIEmbedder(BaseEmbedder): |
| #13 | def __init__(self, config: Optional[BaseEmbedderConfig] = None): |
| #14 | super().__init__(config=config) |
| #15 | |
| #16 | if self.config.model is None: |
| #17 | self.config.model = "text-embedding-ada-002" |
| #18 | |
| #19 | api_key = self.config.api_key or os.environ["OPENAI_API_KEY"] |
| #20 | api_base = ( |
| #21 | self.config.api_base |
| #22 | or os.environ.get("OPENAI_API_BASE") |
| #23 | or os.getenv("OPENAI_BASE_URL") |
| #24 | or "https://api.openai.com/v1" |
| #25 | ) |
| #26 | if os.environ.get("OPENAI_API_BASE"): |
| #27 | warnings.warn( |
| #28 | "The environment variable 'OPENAI_API_BASE' is deprecated and will be removed in the 0.1.140. " |
| #29 | "Please use 'OPENAI_BASE_URL' instead.", |
| #30 | DeprecationWarning |
| #31 | ) |
| #32 | |
| #33 | if api_key is None and os.getenv("OPENAI_ORGANIZATION") is None: |
| #34 | raise ValueError("OPENAI_API_KEY or OPENAI_ORGANIZATION environment variables not provided") # noqa:E501 |
| #35 | embedding_fn = OpenAIEmbeddingFunction( |
| #36 | api_key=api_key, |
| #37 | api_base=api_base, |
| #38 | organization_id=os.getenv("OPENAI_ORGANIZATION"), |
| #39 | model_name=self.config.model, |
| #40 | ) |
| #41 | self.set_embedding_fn(embedding_fn=embedding_fn) |
| #42 | vector_dimension = self.config.vector_dimension or VectorDimensions.OPENAI.value |
| #43 | self.set_vector_dimension(vector_dimension=vector_dimension) |
| #44 |