Skip to content

Commit 1a45c4c

Browse files
committed
more tests for llminterfacev2
1 parent 053f70f commit 1a45c4c

File tree

4 files changed

+414
-23
lines changed

4 files changed

+414
-23
lines changed

src/neo4j_graphrag/generation/graphrag.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,24 @@ def _build_query(
206206
summarization_prompt = self._chat_summary_prompt(
207207
message_history=message_history
208208
)
209-
summary = self.llm.invoke(
210-
input=summarization_prompt,
209+
messages = legacy_inputs_to_messages(
210+
summarization_prompt,
211211
system_instruction=summary_system_message,
212-
).content
212+
)
213+
if isinstance(self.llm, LLMInterfaceV2) or self.llm.__module__.startswith(
214+
"langchain"
215+
):
216+
summary = self.llm.invoke(
217+
input=messages,
218+
).content
219+
elif isinstance(self.llm, LLMInterface):
220+
summary = self.llm.invoke(
221+
input=summarization_prompt,
222+
system_instruction=summary_system_message,
223+
).content
224+
else:
225+
raise ValueError(f"Type {type(self.llm)} of LLM is not supported.")
226+
213227
return self.conversation_prompt(summary=summary, current_query=query_text)
214228
return query_text
215229

tests/e2e/test_graphrag_e2e.py

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,14 @@ def test_graphrag_happy_path(
6060
)
6161

6262
llm.invoke.assert_called_once_with(
63-
"""Context:
63+
[
64+
{
65+
"role": "system",
66+
"content": "Answer the user question using the provided context.",
67+
},
68+
{
69+
"role": "user",
70+
"content": """Context:
6471
<Record node={'question': 'In 1953 Watson & Crick built a model of the molecular structure of this, the gene-carrying substance'}>
6572
<Record node={'question': 'This organ removes excess glucose from the blood & stores it as glycogen'}>
6673
@@ -72,8 +79,8 @@ def test_graphrag_happy_path(
7279
7380
Answer:
7481
""",
75-
None,
76-
system_instruction="Answer the user question using the provided context.",
82+
},
83+
]
7784
)
7885
assert isinstance(result, RagResultModel)
7986
assert result.answer == "some text"
@@ -148,13 +155,21 @@ def test_graphrag_happy_path_with_neo4j_message_history(
148155
llm.invoke.assert_has_calls(
149156
[
150157
call(
151-
input=first_invocation_input,
152-
system_instruction=first_invocation_system_instruction,
158+
[
159+
{"role": "system", "content": first_invocation_system_instruction},
160+
{"role": "user", "content": first_invocation_input},
161+
]
153162
),
154163
call(
155-
second_invocation,
156-
message_history.messages,
157-
system_instruction="Answer the user question using the provided context.",
164+
[
165+
{
166+
"role": "system",
167+
"content": "Answer the user question using the provided context.",
168+
},
169+
{"role": "user", "content": "initial question"},
170+
{"role": "assistant", "content": "answer to initial question"},
171+
{"role": "user", "content": second_invocation},
172+
]
158173
),
159174
]
160175
)
@@ -190,7 +205,14 @@ def test_graphrag_happy_path_return_context(
190205
)
191206

192207
llm.invoke.assert_called_once_with(
193-
"""Context:
208+
[
209+
{
210+
"role": "system",
211+
"content": "Answer the user question using the provided context.",
212+
},
213+
{
214+
"role": "user",
215+
"content": """Context:
194216
<Record node={'question': 'In 1953 Watson & Crick built a model of the molecular structure of this, the gene-carrying substance'}>
195217
<Record node={'question': 'This organ removes excess glucose from the blood & stores it as glycogen'}>
196218
@@ -202,8 +224,8 @@ def test_graphrag_happy_path_return_context(
202224
203225
Answer:
204226
""",
205-
None,
206-
system_instruction="Answer the user question using the provided context.",
227+
},
228+
],
207229
)
208230
assert isinstance(result, RagResultModel)
209231
assert result.answer == "some text"
@@ -236,7 +258,14 @@ def test_graphrag_happy_path_examples(
236258
)
237259

238260
llm.invoke.assert_called_once_with(
239-
"""Context:
261+
[
262+
{
263+
"role": "system",
264+
"content": "Answer the user question using the provided context.",
265+
},
266+
{
267+
"role": "user",
268+
"content": """Context:
240269
<Record node={'question': 'In 1953 Watson & Crick built a model of the molecular structure of this, the gene-carrying substance'}>
241270
<Record node={'question': 'This organ removes excess glucose from the blood & stores it as glycogen'}>
242271
@@ -248,8 +277,8 @@ def test_graphrag_happy_path_examples(
248277
249278
Answer:
250279
""",
251-
None,
252-
system_instruction="Answer the user question using the provided context.",
280+
},
281+
]
253282
)
254283
assert result.answer == "some text"
255284

0 commit comments

Comments
 (0)