Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

feat: URL Handling in OpenAIEmbedding to Align with OpenAIModel (#1593)

Lei Zhange77aaca6379a
diff --git a/camel/embeddings/openai_embedding.py b/camel/embeddings/openai_embedding.py
index 94da48d7f..a708d78a9 100644
--- a/camel/embeddings/openai_embedding.py
+++ b/camel/embeddings/openai_embedding.py
@@ -30,6 +30,8 @@ class OpenAIEmbedding(BaseEmbedding[str]):
model_type (EmbeddingModelType, optional): The model type to be
used for text embeddings.
(default: :obj:`TEXT_EMBEDDING_3_SMALL`)
+ url (Optional[str], optional): The url to the OpenAI service.
+ (default: :obj:`None`)
api_key (str, optional): The API key for authenticating with the
OpenAI service. (default: :obj:`None`)
dimensions (int, optional): The text embedding output dimensions.
@@ -49,6 +51,7 @@ class OpenAIEmbedding(BaseEmbedding[str]):
model_type: EmbeddingModelType = (
EmbeddingModelType.TEXT_EMBEDDING_3_SMALL
),
+ url: str | None = None,
api_key: str | None = None,
dimensions: int | NotGiven = NOT_GIVEN,
) -> None:
@@ -61,7 +64,13 @@ class OpenAIEmbedding(BaseEmbedding[str]):
assert isinstance(dimensions, int)
self.output_dim = dimensions
self._api_key = api_key or os.environ.get("OPENAI_API_KEY")
- self.client = OpenAI(timeout=180, max_retries=3, api_key=self._api_key)
+ self._url = url or os.environ.get("OPENAI_API_BASE_URL")
+ self.client = OpenAI(
+ timeout=180,
+ max_retries=3,
+ base_url=self._url,
+ api_key=self._api_key,
+ )
def embed_list(
self,