-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c75a6b
commit d9e673d
Showing
7 changed files
with
73 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from typing import Any, Dict | ||
|
||
# pants: no-infer-dep | ||
from llama_index.core.embeddings.mock_embed_model import MockEmbedding | ||
from llama_index.core.embeddings.utils import resolve_embed_model | ||
from llama_index.embeddings.huggingface import ( | ||
HuggingFaceEmbedding, | ||
) # pants: no-infer-dep | ||
from llama_index.embeddings.openai import OpenAIEmbedding # pants: no-infer-dep | ||
from pytest import MonkeyPatch | ||
|
||
|
||
def mock_hf_embeddings(self: Any, *args: Any, **kwargs: Dict[str, Any]) -> Any: | ||
"""Mock HuggingFaceEmbeddings.""" | ||
super(HuggingFaceEmbedding, self).__init__( | ||
model_name="fake", | ||
tokenizer_name="fake", | ||
model="fake", | ||
tokenizer="fake", | ||
) | ||
return | ||
|
||
|
||
def mock_openai_embeddings(self: Any, *args: Any, **kwargs: Dict[str, Any]) -> Any: | ||
"""Mock OpenAIEmbedding.""" | ||
super(OpenAIEmbedding, self).__init__( | ||
api_key="fake", api_base="fake", api_version="fake" | ||
) | ||
return | ||
|
||
|
||
def test_resolve_embed_model(monkeypatch: MonkeyPatch) -> None: | ||
monkeypatch.setattr( | ||
"llama_index.embeddings.huggingface.HuggingFaceEmbedding.__init__", | ||
mock_hf_embeddings, | ||
) | ||
monkeypatch.setattr( | ||
"llama_index.embeddings.openai.OpenAIEmbedding.__init__", | ||
mock_openai_embeddings, | ||
) | ||
|
||
# Test None | ||
embed_model = resolve_embed_model(None) | ||
assert isinstance(embed_model, MockEmbedding) | ||
|
||
# Test str | ||
embed_model = resolve_embed_model("local") | ||
assert isinstance(embed_model, HuggingFaceEmbedding) | ||
|
||
# Test LCEmbeddings | ||
embed_model = resolve_embed_model(HuggingFaceEmbedding()) | ||
assert isinstance(embed_model, HuggingFaceEmbedding) | ||
|
||
# Test BaseEmbedding | ||
embed_model = resolve_embed_model(OpenAIEmbedding()) | ||
assert isinstance(embed_model, OpenAIEmbedding) |