test(test_webhook): change component in webhook test to be async (#2578)

* feat: Add aiofiles package for asyncio file support

* fix: add async component in webhook test flow

* refactor: deactivate astra db test

* refactor: remove AstraDB test and related code

* feat: add component that makes an async api call

* chore: Update langsmith and sentry-sdk dependencies to latest versions
This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-07-08 13:38:22 -03:00 • committed by GitHub
commit 46b7911110
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 1015 additions and 244 deletions

File diff suppressed because one or more lines are too long

View file

@ -1,14 +1,14 @@
import os
import pytest
from integration.utils import MockEmbeddings, check_env_vars
from langchain_core.documents import Document
from langflow.components.memories.AstraDBMessageReader import AstraDBMessageReaderComponent
from langflow.components.memories.AstraDBMessageWriter import AstraDBMessageWriterComponent
# from langflow.components.memories.AstraDBMessageReader import AstraDBMessageReaderComponent
# from langflow.components.memories.AstraDBMessageWriter import AstraDBMessageWriterComponent
from langflow.components.vectorstores.AstraDB import AstraVectorStoreComponent
from langflow.schema.data import Data
from integration.utils import MockEmbeddings, check_env_vars
COLLECTION = "test_basic"
SEARCH_COLLECTION = "test_search"
MEMORY_COLLECTION = "test_memory"
@ -95,63 +95,63 @@ def test_astra_embeds_and_search(astra_fixture):
assert len(records) == 1
@pytest.mark.skipif(
not check_env_vars("ASTRA_DB_APPLICATION_TOKEN", "ASTRA_DB_API_ENDPOINT"),
reason="missing astra env vars",
)
def test_astra_memory():
application_token = os.getenv("ASTRA_DB_APPLICATION_TOKEN")
api_endpoint = os.getenv("ASTRA_DB_API_ENDPOINT")
# @pytest.mark.skipif(
# not check_env_vars("ASTRA_DB_APPLICATION_TOKEN", "ASTRA_DB_API_ENDPOINT"),
# reason="missing astra env vars",
# )
# def test_astra_memory():
# application_token = os.getenv("ASTRA_DB_APPLICATION_TOKEN")
# api_endpoint = os.getenv("ASTRA_DB_API_ENDPOINT")
writer = AstraDBMessageWriterComponent()
reader = AstraDBMessageReaderComponent()
# writer = AstraDBMessageWriterComponent()
# reader = AstraDBMessageReaderComponent()
input_value = Data.from_document(
Document(
page_content="memory1",
metadata={"session_id": 1, "sender": "human", "sender_name": "Bob"},
)
)
writer.build(
input_value=input_value,
session_id=1,
token=application_token,
api_endpoint=api_endpoint,
collection_name=MEMORY_COLLECTION,
)
# input_value = Data.from_document(
# Document(
# page_content="memory1",
# metadata={"session_id": 1, "sender": "human", "sender_name": "Bob"},
# )
# )
# writer.build(
# input_value=input_value,
# session_id=1,
# token=application_token,
# api_endpoint=api_endpoint,
# collection_name=MEMORY_COLLECTION,
# )
# verify reading w/ same session id pulls the same record
records = reader.build(
session_id=1,
token=application_token,
api_endpoint=api_endpoint,
collection_name=MEMORY_COLLECTION,
)
assert len(records) == 1
assert isinstance(records[0], Data)
content = records[0].get_text()
assert content == "memory1"
# # verify reading w/ same session id pulls the same record
# records = reader.build(
# session_id=1,
# token=application_token,
# api_endpoint=api_endpoint,
# collection_name=MEMORY_COLLECTION,
# )
# assert len(records) == 1
# assert isinstance(records[0], Data)
# content = records[0].get_text()
# assert content == "memory1"
# verify reading w/ different session id does not pull the same record
records = reader.build(
session_id=2,
token=application_token,
api_endpoint=api_endpoint,
collection_name=MEMORY_COLLECTION,
)
assert len(records) == 0
# # verify reading w/ different session id does not pull the same record
# records = reader.build(
# session_id=2,
# token=application_token,
# api_endpoint=api_endpoint,
# collection_name=MEMORY_COLLECTION,
# )
# assert len(records) == 0
# Cleanup store - doing here rather than fixture (see https://github.com/langchain-ai/langchain-datastax/pull/36)
try:
from langchain_astradb import AstraDBVectorStore
except ImportError:
raise ImportError(
"Could not import langchain Astra DB integration package. Please install it with `pip install langchain-astradb`."
)
store = AstraDBVectorStore(
collection_name=MEMORY_COLLECTION,
embedding=MockEmbeddings(),
api_endpoint=api_endpoint,
token=application_token,
)
store.delete_collection()
# # Cleanup store - doing here rather than fixture (see https://github.com/langchain-ai/langchain-datastax/pull/36)
# try:
# from langchain_astradb import AstraDBVectorStore
# except ImportError:
# raise ImportError(
# "Could not import langchain Astra DB integration package. Please install it with `pip install langchain-astradb`."
# )
# store = AstraDBVectorStore(
# collection_name=MEMORY_COLLECTION,
# embedding=MockEmbeddings(),
# api_endpoint=api_endpoint,
# token=application_token,
# )
# store.delete_collection()