mirror of
https://github.com/hwchase17/langchain
synced 2024-11-10 01:10:59 +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
61 lines
1.6 KiB
Python
61 lines
1.6 KiB
Python
from typing import Any, Dict
|
|
|
|
from langchain_core.documents import Document
|
|
from pytest_mock import MockerFixture
|
|
|
|
from langchain_community.retrievers import RemoteLangChainRetriever
|
|
|
|
|
|
class MockResponse:
|
|
def __init__(self, json_data: Dict, status_code: int):
|
|
self.json_data = json_data
|
|
self.status_code = status_code
|
|
|
|
def json(self) -> Dict:
|
|
return self.json_data
|
|
|
|
|
|
def mocked_requests_post(*args: Any, **kwargs: Any) -> MockResponse:
|
|
return MockResponse(
|
|
json_data={
|
|
"response": [
|
|
{
|
|
"page_content": "I like apples",
|
|
"metadata": {
|
|
"test": 0,
|
|
},
|
|
},
|
|
{
|
|
"page_content": "I like pineapples",
|
|
"metadata": {
|
|
"test": 1,
|
|
},
|
|
},
|
|
]
|
|
},
|
|
status_code=200,
|
|
)
|
|
|
|
|
|
def test_RemoteLangChainRetriever_get_relevant_documents(
|
|
mocker: MockerFixture,
|
|
) -> None:
|
|
mocker.patch("requests.post", side_effect=mocked_requests_post)
|
|
|
|
remote_langchain_retriever = RemoteLangChainRetriever(
|
|
url="http://localhost:8000",
|
|
)
|
|
response = remote_langchain_retriever.get_relevant_documents("I like apples")
|
|
want = [
|
|
Document(page_content="I like apples", metadata={"test": 0}),
|
|
Document(page_content="I like pineapples", metadata={"test": 1}),
|
|
]
|
|
|
|
assert len(response) == len(want)
|
|
for r, w in zip(response, want):
|
|
assert r.page_content == w.page_content
|
|
assert r.metadata == w.metadata
|
|
|
|
|
|
# TODO: _aget_relevant_documents test
|