From ea55fd1f3000c21e7d17a50e5c5a1edb08afe9b1 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Wed, 27 Nov 2024 16:30:38 +0000 Subject: [PATCH] use sed to change get_messages() to messages --- libs/elasticsearch/langchain_elasticsearch/_sync/cache.py | 4 ++-- libs/elasticsearch/scripts/run_unasync.py | 8 ++------ .../tests/integration_tests/_async/test_chat_history.py | 4 ++-- .../tests/integration_tests/_sync/test_chat_history.py | 4 ++-- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/libs/elasticsearch/langchain_elasticsearch/_sync/cache.py b/libs/elasticsearch/langchain_elasticsearch/_sync/cache.py index 8e52afb..9620dba 100644 --- a/libs/elasticsearch/langchain_elasticsearch/_sync/cache.py +++ b/libs/elasticsearch/langchain_elasticsearch/_sync/cache.py @@ -201,8 +201,8 @@ def clear(self, **kwargs: Any) -> None: class ElasticsearchEmbeddingsCache(ByteStore): """An Elasticsearch store for caching embeddings. - For synchronous applications, use the ``ElasticsearchEmbeddingsCache`` class. - For asyhchronous applications, use the ``AsyncElasticsearchEmbeddingsCache`` class. + For synchronous applications, use the `ElasticsearchEmbeddingsCache` class. + For asyhchronous applications, use the `AsyncElasticsearchEmbeddingsCache` class. """ def __init__( diff --git a/libs/elasticsearch/scripts/run_unasync.py b/libs/elasticsearch/scripts/run_unasync.py index d8b37d8..d708b76 100644 --- a/libs/elasticsearch/scripts/run_unasync.py +++ b/libs/elasticsearch/scripts/run_unasync.py @@ -113,15 +113,11 @@ def main(check=False): subprocess.check_call(["ruff", "format", "--target-version=py38", output_dir]) subprocess.check_call(["isort", output_dir]) for file in glob("*.py", root_dir=dir[0]): - # remove asyncio from sync files - subprocess.check_call( - ["sed", "-i.bak", "/^import asyncio$/d", f"{output_dir}{file}"] - ) subprocess.check_call( [ "sed", "-i.bak", - "s/asyncio\\.run(main())/main()/", + "s/pytest.mark.asyncio/pytest.mark.sync/", f"{output_dir}{file}", ] ) @@ -129,7 +125,7 @@ def main(check=False): [ "sed", "-i.bak", - "s/pytest.mark.asyncio/pytest.mark.sync/", + "s/get_messages()/messages/", f"{output_dir}{file}", ] ) diff --git a/libs/elasticsearch/tests/integration_tests/_async/test_chat_history.py b/libs/elasticsearch/tests/integration_tests/_async/test_chat_history.py index 5152fd3..100bb1a 100644 --- a/libs/elasticsearch/tests/integration_tests/_async/test_chat_history.py +++ b/libs/elasticsearch/tests/integration_tests/_async/test_chat_history.py @@ -60,7 +60,7 @@ async def test_memory_with_message_store( ) # get the message history from the memory store and turn it into a json - messages = await memory.chat_memory.aget_messages() # type: ignore[attr-defined] + messages = await memory.chat_memory.aget_messages() messages_json = json.dumps([message_to_dict(msg) for msg in messages]) assert "This is me, the AI" in messages_json @@ -69,4 +69,4 @@ async def test_memory_with_message_store( # remove the record from Elasticsearch, so the next test run won't pick it up await memory.chat_memory.aclear() - assert await memory.chat_memory.aget_messages() == [] # type: ignore[attr-defined] + assert await memory.chat_memory.aget_messages() == [] diff --git a/libs/elasticsearch/tests/integration_tests/_sync/test_chat_history.py b/libs/elasticsearch/tests/integration_tests/_sync/test_chat_history.py index 9603ec7..8207e1a 100644 --- a/libs/elasticsearch/tests/integration_tests/_sync/test_chat_history.py +++ b/libs/elasticsearch/tests/integration_tests/_sync/test_chat_history.py @@ -60,7 +60,7 @@ def test_memory_with_message_store( ) # get the message history from the memory store and turn it into a json - messages = memory.chat_memory.get_messages() # type: ignore[attr-defined] + messages = memory.chat_memory.messages messages_json = json.dumps([message_to_dict(msg) for msg in messages]) assert "This is me, the AI" in messages_json @@ -69,4 +69,4 @@ def test_memory_with_message_store( # remove the record from Elasticsearch, so the next test run won't pick it up memory.chat_memory.clear() - assert memory.chat_memory.get_messages() == [] # type: ignore[attr-defined] + assert memory.chat_memory.messages == []