44from typing import Generator
55
66import pytest
7- from flaky import flaky # type:ignore[import-untyped]
87from langchain_core .documents import Document
98from langchain_core .language_models .chat_models import BaseChatModel
109from langchain_core .messages import AIMessage
@@ -69,7 +68,7 @@ def documents():
6968GreenTech Ltd. Leads SolarGrid Initiative
7069
7170San Francisco, CA — GreenTech Ltd. has emerged as a leader in renewable energy projects with the SolarGrid Initiative,
72- a collaboration with ACME Corporation. Jane Smith, the SolarGrid project’s Lead Manager, highlighted its ambitious goal:
71+ a collaboration with ACME Corporation. GreenTech's Jane Smith, the SolarGrid project’s Lead Manager, highlighted its ambitious goal:
7372providing affordable solar energy to underserved communities.
7473
7574GreenTech, headquartered in San Francisco, has worked closely with ACME since their partnership began in May 2021.
@@ -125,8 +124,6 @@ def graph_store(collection, entity_extraction_model, documents) -> MongoDBGraphS
125124 store = MongoDBGraphStore (
126125 collection = collection ,
127126 entity_extraction_model = entity_extraction_model ,
128- entity_prompt = entity_prompt ,
129- query_prompt = query_prompt ,
130127 )
131128 bulkwrite_results = store .add_documents (documents )
132129 assert len (bulkwrite_results ) == len (documents )
@@ -145,7 +142,6 @@ def test_add_docs_store(graph_store):
145142 assert 4 <= len (extracted_entities ) < 8
146143
147144
148- @flaky (max_runs = 3 , min_passes = 2 )
149145def test_extract_entity_names (graph_store , query_connection ):
150146 query_entity_names = graph_store .extract_entity_names (query_connection )
151147 assert set (query_entity_names ) == {"John Doe" , "Jane Smith" }
@@ -157,7 +153,6 @@ def test_extract_entities_from_empty_string_names(graph_store):
157153 assert len (no_names ) == 0
158154
159155
160- @flaky (max_runs = 3 , min_passes = 1 )
161156def test_related_entities (graph_store ):
162157 entity_names = ["John Doe" , "Jane Smith" ]
163158 related_entities = graph_store .related_entities (entity_names )
@@ -168,7 +163,6 @@ def test_related_entities(graph_store):
168163 assert len (no_entities ) == 0
169164
170165
171- @flaky (max_runs = 3 , min_passes = 1 )
172166def test_additional_entity_examples (entity_extraction_model , entity_example , documents ):
173167 # First, create one client just to drop any existing collections
174168 client = MongoClient (CONNECTION_STRING )
@@ -192,15 +186,13 @@ def test_additional_entity_examples(entity_extraction_model, entity_example, doc
192186 assert len (new_entities ) >= 2
193187
194188
195- @flaky (max_runs = 3 , min_passes = 1 )
196189def test_chat_response (graph_store , query_connection ):
197190 """Displays querying an existing Knowledge Graph Database"""
198191 answer = graph_store .chat_response (query_connection )
199192 assert isinstance (answer , AIMessage )
200193 assert "acme corporation" in answer .content .lower ()
201194
202195
203- @flaky (max_runs = 3 , min_passes = 1 )
204196def test_similarity_search (graph_store , query_connection ):
205197 docs = graph_store .similarity_search (query_connection )
206198 assert len (docs ) >= 4
@@ -209,7 +201,6 @@ def test_similarity_search(graph_store, query_connection):
209201 assert any ("attributes" in d .keys () for d in docs )
210202
211203
212- @flaky (max_runs = 3 , min_passes = 1 )
213204def test_validator (documents , entity_extraction_model ):
214205 # Case 1. No existing collection.
215206 client = MongoClient (CONNECTION_STRING )
@@ -263,7 +254,6 @@ def test_validator(documents, entity_extraction_model):
263254 client .close ()
264255
265256
266- @flaky (max_runs = 3 , min_passes = 1 )
267257def test_allowed_entity_types (documents , entity_extraction_model ):
268258 """Add allowed_entity_types. Use the validator to confirm behaviour."""
269259 allowed_entity_types = ["Person" ]
@@ -291,7 +281,6 @@ def test_allowed_entity_types(documents, entity_extraction_model):
291281 all ([len (e ["relationships" ].get ("attributes" , [])) == 0 for e in entities ])
292282
293283
294- @flaky (max_runs = 3 , min_passes = 1 )
295284def test_allowed_relationship_types (documents , entity_extraction_model ):
296285 # drop collection
297286 client = MongoClient (CONNECTION_STRING )
0 commit comments