Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions chromadb/test/ef/test_openai_ef.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from chromadb.utils.embedding_functions.openai_embedding_function import (
OpenAIEmbeddingFunction,
)
from chromadb.errors import InvalidArgumentError


def test_with_embedding_dimensions() -> None:
Expand Down Expand Up @@ -36,3 +37,42 @@ def test_with_incorrect_api_key() -> None:
ef = OpenAIEmbeddingFunction(api_key="incorrect_api_key", dimensions=64)
with pytest.raises(Exception, match="Incorrect API key provided"):
ef(["hello world"])


def test_azure_requires_deployment_id() -> None:
"""Azure OpenAI should require deployment_id parameter."""
pytest.importorskip("openai", reason="openai not installed")
with pytest.raises(InvalidArgumentError, match="deployment_id must be specified"):
OpenAIEmbeddingFunction(
api_key="test_key",
api_type="azure",
api_base="https://example.openai.azure.com",
api_version="2023-05-15",
# Missing deployment_id should raise
)


def test_azure_requires_api_version() -> None:
"""Azure OpenAI should require api_version parameter."""
pytest.importorskip("openai", reason="openai not installed")
with pytest.raises(InvalidArgumentError, match="api_version must be specified"):
OpenAIEmbeddingFunction(
api_key="test_key",
api_type="azure",
api_base="https://example.openai.azure.com",
deployment_id="my-deployment",
# Missing api_version should raise
)


def test_azure_requires_api_base() -> None:
"""Azure OpenAI should require api_base parameter."""
pytest.importorskip("openai", reason="openai not installed")
with pytest.raises(InvalidArgumentError, match="api_base must be specified"):
OpenAIEmbeddingFunction(
api_key="test_key",
api_type="azure",
api_version="2023-05-15",
deployment_id="my-deployment",
# Missing api_base should raise
)