mirror of
https://github.com/hwchase17/langchain
synced 2024-11-18 09:25:54 +00:00
ed58eeb9c5
Moved the following modules to new package langchain-community in a backwards compatible fashion: ``` mv langchain/langchain/adapters community/langchain_community mv langchain/langchain/callbacks community/langchain_community/callbacks mv langchain/langchain/chat_loaders community/langchain_community mv langchain/langchain/chat_models community/langchain_community mv langchain/langchain/document_loaders community/langchain_community mv langchain/langchain/docstore community/langchain_community mv langchain/langchain/document_transformers community/langchain_community mv langchain/langchain/embeddings community/langchain_community mv langchain/langchain/graphs community/langchain_community mv langchain/langchain/llms community/langchain_community mv langchain/langchain/memory/chat_message_histories community/langchain_community mv langchain/langchain/retrievers community/langchain_community mv langchain/langchain/storage community/langchain_community mv langchain/langchain/tools community/langchain_community mv langchain/langchain/utilities community/langchain_community mv langchain/langchain/vectorstores community/langchain_community mv langchain/langchain/agents/agent_toolkits community/langchain_community mv langchain/langchain/cache.py community/langchain_community mv langchain/langchain/adapters community/langchain_community mv langchain/langchain/callbacks community/langchain_community/callbacks mv langchain/langchain/chat_loaders community/langchain_community mv langchain/langchain/chat_models community/langchain_community mv langchain/langchain/document_loaders community/langchain_community mv langchain/langchain/docstore community/langchain_community mv langchain/langchain/document_transformers community/langchain_community mv langchain/langchain/embeddings community/langchain_community mv langchain/langchain/graphs community/langchain_community mv langchain/langchain/llms community/langchain_community mv langchain/langchain/memory/chat_message_histories community/langchain_community mv langchain/langchain/retrievers community/langchain_community mv langchain/langchain/storage community/langchain_community mv langchain/langchain/tools community/langchain_community mv langchain/langchain/utilities community/langchain_community mv langchain/langchain/vectorstores community/langchain_community mv langchain/langchain/agents/agent_toolkits community/langchain_community mv langchain/langchain/cache.py community/langchain_community ``` Moved the following to core ``` mv langchain/langchain/utils/json_schema.py core/langchain_core/utils mv langchain/langchain/utils/html.py core/langchain_core/utils mv langchain/langchain/utils/strings.py core/langchain_core/utils cat langchain/langchain/utils/env.py >> core/langchain_core/utils/env.py rm langchain/langchain/utils/env.py ``` See .scripts/community_split/script_integrations.sh for all changes
47 lines
1.7 KiB
Python
47 lines
1.7 KiB
Python
# flake8: noqa
|
|
"""Test llamacpp embeddings."""
|
|
import os
|
|
from urllib.request import urlretrieve
|
|
|
|
from langchain_community.embeddings.llamacpp import LlamaCppEmbeddings
|
|
|
|
|
|
def get_model() -> str:
|
|
"""Download model.
|
|
From https://huggingface.co/Sosaka/Alpaca-native-4bit-ggml/,
|
|
convert to new ggml format and return model path.
|
|
"""
|
|
model_url = "https://huggingface.co/Sosaka/Alpaca-native-4bit-ggml/resolve/main/ggml-alpaca-7b-q4.bin"
|
|
tokenizer_url = "https://huggingface.co/decapoda-research/llama-7b-hf/resolve/main/tokenizer.model"
|
|
conversion_script = "https://github.com/ggerganov/llama.cpp/raw/master/convert-unversioned-ggml-to-ggml.py"
|
|
local_filename = model_url.split("/")[-1]
|
|
|
|
if not os.path.exists("convert-unversioned-ggml-to-ggml.py"):
|
|
urlretrieve(conversion_script, "convert-unversioned-ggml-to-ggml.py")
|
|
if not os.path.exists("tokenizer.model"):
|
|
urlretrieve(tokenizer_url, "tokenizer.model")
|
|
if not os.path.exists(local_filename):
|
|
urlretrieve(model_url, local_filename)
|
|
os.system("python convert-unversioned-ggml-to-ggml.py . tokenizer.model")
|
|
|
|
return local_filename
|
|
|
|
|
|
def test_llamacpp_embedding_documents() -> None:
|
|
"""Test llamacpp embeddings."""
|
|
documents = ["foo bar"]
|
|
model_path = get_model()
|
|
embedding = LlamaCppEmbeddings(model_path=model_path)
|
|
output = embedding.embed_documents(documents)
|
|
assert len(output) == 1
|
|
assert len(output[0]) == 512
|
|
|
|
|
|
def test_llamacpp_embedding_query() -> None:
|
|
"""Test llamacpp embeddings."""
|
|
document = "foo bar"
|
|
model_path = get_model()
|
|
embedding = LlamaCppEmbeddings(model_path=model_path)
|
|
output = embedding.embed_query(document)
|
|
assert len(output) == 512
|