Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(embeddings): added tests for embeddings #3183

Merged
merged 1 commit into from
Sep 11, 2024
Merged
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
38 changes: 38 additions & 0 deletions backend/api/tests/settings/test_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from unittest.mock import patch, MagicMock
from quivr_api.modules.dependencies import get_embedding_client
from langchain_community.embeddings.ollama import OllamaEmbeddings
from langchain_openai import AzureOpenAIEmbeddings

def test_ollama_embedding():
with patch("quivr_api.modules.dependencies.settings") as mock_settings:
mock_settings.ollama_api_base_url = "http://ollama.example.com"
mock_settings.azure_openai_embeddings_url = None

embedding_client = get_embedding_client()

assert isinstance(embedding_client, OllamaEmbeddings)
assert embedding_client.base_url == "http://ollama.example.com"

def test_azure_embedding():
with patch("quivr_api.modules.dependencies.settings") as mock_settings:
mock_settings.ollama_api_base_url = None
mock_settings.azure_openai_embeddings_url = "https://quivr-test.openai.azure.com/openai/deployments/embedding/embeddings?api-version=2023-05-15"

embedding_client = get_embedding_client()

assert isinstance(embedding_client, AzureOpenAIEmbeddings)
assert embedding_client.azure_endpoint == "https://quivr-test.openai.azure.com"

def test_openai_embedding():
with patch("quivr_api.modules.dependencies.settings") as mock_settings, \
patch("quivr_api.modules.dependencies.OpenAIEmbeddings") as mock_openai_embeddings:
mock_settings.ollama_api_base_url = None
mock_settings.azure_openai_embeddings_url = None

# Create a mock instance for OpenAIEmbeddings
mock_openai_instance = MagicMock()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the need for MagicMock here 🤔 . As I understand we are patching the environement to check that we get the correct embedding instance ? Is the openaiembedding instance different from the other cases ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we read the env key from the env. the others are in the settings

mock_openai_embeddings.return_value = mock_openai_instance

embedding_client = get_embedding_client()

assert embedding_client == mock_openai_instance
Loading