Skip to content

Commit

Permalink
feat: URL Handling in OpenAIEmbedding to Align with OpenAIModel (#1593)
Browse files Browse the repository at this point in the history
Co-authored-by: Wendong-Fan <[email protected]>
  • Loading branch information
coolbeevip and Wendong-Fan authored Feb 12, 2025
1 parent b87dc6e commit e77aaca
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion camel/embeddings/openai_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -49,6 +51,7 @@ def __init__(
model_type: EmbeddingModelType = (
EmbeddingModelType.TEXT_EMBEDDING_3_SMALL
),
url: str | None = None,
api_key: str | None = None,
dimensions: int | NotGiven = NOT_GIVEN,
) -> None:
Expand All @@ -61,7 +64,13 @@ def __init__(
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,
Expand Down

0 comments on commit e77aaca

Please sign in to comment.