fix(python): huggingface TEI auth, procedural-memory content handling, and proxy pip auto-install (#6947)
This commit is contained in:
@@ -72,7 +72,8 @@ def test_embed_with_custom_embedding_dims(mock_sentence_transformer):
|
||||
assert result == [1.0, 1.1, 1.2]
|
||||
|
||||
|
||||
def test_embed_with_huggingface_base_url():
|
||||
def test_embed_with_huggingface_base_url(monkeypatch):
|
||||
monkeypatch.delenv("HUGGINGFACE_API_KEY", raising=False)
|
||||
config = BaseEmbedderConfig(
|
||||
huggingface_base_url="http://localhost:8080",
|
||||
model="my-custom-model",
|
||||
@@ -81,20 +82,20 @@ def test_embed_with_huggingface_base_url():
|
||||
with patch("mem0.embeddings.huggingface.OpenAI") as mock_openai:
|
||||
mock_client = Mock()
|
||||
mock_openai.return_value = mock_client
|
||||
|
||||
|
||||
# Create a mock for the response object and its attributes
|
||||
mock_embedding_response = Mock()
|
||||
mock_embedding_response.embedding = [0.1, 0.2, 0.3]
|
||||
|
||||
|
||||
mock_create_response = Mock()
|
||||
mock_create_response.data = [mock_embedding_response]
|
||||
|
||||
|
||||
mock_client.embeddings.create.return_value = mock_create_response
|
||||
|
||||
embedder = HuggingFaceEmbedding(config)
|
||||
result = embedder.embed("Hello from custom endpoint")
|
||||
|
||||
mock_openai.assert_called_once_with(base_url="http://localhost:8080", api_key=None)
|
||||
mock_openai.assert_called_once_with(base_url="http://localhost:8080", api_key="hf")
|
||||
mock_client.embeddings.create.assert_called_once_with(
|
||||
input="Hello from custom endpoint",
|
||||
model="my-custom-model",
|
||||
@@ -115,6 +116,26 @@ def test_embed_with_huggingface_base_url_forwards_api_key():
|
||||
mock_openai.assert_called_once_with(base_url="http://localhost:8080", api_key="tei-token")
|
||||
|
||||
|
||||
def test_embed_with_huggingface_base_url_falls_back_to_env_var(monkeypatch):
|
||||
monkeypatch.setenv("HUGGINGFACE_API_KEY", "env-token")
|
||||
config = BaseEmbedderConfig(huggingface_base_url="http://localhost:8080", model="my-custom-model")
|
||||
with patch("mem0.embeddings.huggingface.OpenAI") as mock_openai:
|
||||
HuggingFaceEmbedding(config)
|
||||
|
||||
mock_openai.assert_called_once_with(base_url="http://localhost:8080", api_key="env-token")
|
||||
|
||||
|
||||
def test_embed_with_huggingface_base_url_config_key_beats_env_var(monkeypatch):
|
||||
monkeypatch.setenv("HUGGINGFACE_API_KEY", "env-token")
|
||||
config = BaseEmbedderConfig(
|
||||
huggingface_base_url="http://localhost:8080", model="my-custom-model", api_key="config-token"
|
||||
)
|
||||
with patch("mem0.embeddings.huggingface.OpenAI") as mock_openai:
|
||||
HuggingFaceEmbedding(config)
|
||||
|
||||
mock_openai.assert_called_once_with(base_url="http://localhost:8080", api_key="config-token")
|
||||
|
||||
|
||||
def test_embed_batch_sentence_transformer(mock_sentence_transformer):
|
||||
config = BaseEmbedderConfig()
|
||||
embedder = HuggingFaceEmbedding(config)
|
||||
|
||||
Reference in New Issue
Block a user