Skip to content

Commit 299d4a0

Browse files
authored
Update dependencies (#384)
* Update deps * Update lock file after merge * mypy part 1 * Ruff * mypy part 2 * Fix tests and update example
1 parent cdeb7af commit 299d4a0

File tree

8 files changed

+882
-804
lines changed

8 files changed

+882
-804
lines changed
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
from neo4j_graphrag.llm import LLMResponse, VertexAILLM
22
from vertexai.generative_models import GenerationConfig
33

4-
generation_config = GenerationConfig(temperature=0.0)
4+
generation_config = GenerationConfig(temperature=1.0)
55
llm = VertexAILLM(
6-
model_name="gemini-1.5-flash-001",
6+
model_name="gemini-2.0-flash-001",
77
generation_config=generation_config,
88
# add here any argument that will be passed to the
99
# vertexai.generative_models.GenerativeModel client
1010
)
11-
res: LLMResponse = llm.invoke("say something")
11+
res: LLMResponse = llm.invoke(
12+
"say something",
13+
system_instruction="You are living in 3000 where AI rules the world",
14+
)
1215
print(res.content)

poetry.lock

Lines changed: 855 additions & 783 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ neo4j = "^5.17.0"
3333
pydantic = "^2.6.3"
3434
fsspec = "^2024.9.0"
3535
pypdf = "^5.1.0"
36-
json-repair = "^0.39.1"
36+
json-repair = "^0.44.1"
3737
pyyaml = "^6.0.2"
3838
types-pyyaml = "^6.0.12.20240917"
3939
# optional deps

src/neo4j_graphrag/embeddings/vertexai.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
try:
2222
import vertexai
2323
except ImportError:
24-
vertexai = None
24+
vertexai = None # type: ignore[assignment]
2525

2626

2727
class VertexAIEmbeddings(Embedder):

src/neo4j_graphrag/experimental/components/entity_relation_extractor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import enum
1919
import json
2020
import logging
21-
from typing import Any, List, Optional, Union, cast
21+
from typing import Any, List, Optional, Union
2222

2323
import json_repair
2424
from pydantic import ValidationError, validate_call
@@ -102,7 +102,7 @@ def balance_curly_braces(json_string: str) -> str:
102102

103103
def fix_invalid_json(raw_json: str) -> str:
104104
repaired_json = json_repair.repair_json(raw_json)
105-
repaired_json = cast(str, repaired_json).strip()
105+
repaired_json = repaired_json.strip()
106106

107107
if repaired_json == '""':
108108
raise InvalidJSONError("JSON repair resulted in an empty or invalid JSON.")

src/neo4j_graphrag/llm/vertexai_llm.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
ToolConfig,
4949
)
5050
except ImportError:
51-
GenerativeModel = None
52-
ResponseValidationError = None
51+
GenerativeModel = None # type: ignore[misc, assignment]
52+
ResponseValidationError = None # type: ignore[misc, assignment]
5353

5454

5555
class VertexAILLM(LLMInterface):
@@ -114,13 +114,15 @@ def get_messages(
114114
if message.get("role") == "user":
115115
messages.append(
116116
Content(
117-
role="user", parts=[Part.from_text(message.get("content"))]
117+
role="user",
118+
parts=[Part.from_text(message.get("content", ""))],
118119
)
119120
)
120121
elif message.get("role") == "assistant":
121122
messages.append(
122123
Content(
123-
role="model", parts=[Part.from_text(message.get("content"))]
124+
role="model",
125+
parts=[Part.from_text(message.get("content", ""))],
124126
)
125127
)
126128

@@ -211,10 +213,10 @@ def _get_model(
211213
self,
212214
system_instruction: Optional[str] = None,
213215
) -> GenerativeModel:
214-
system_message = [system_instruction] if system_instruction is not None else []
216+
# system_message = [system_instruction] if system_instruction is not None else []
215217
model = GenerativeModel(
216218
model_name=self.model_name,
217-
system_instruction=system_message,
219+
system_instruction=system_instruction,
218220
)
219221
return model
220222

@@ -253,7 +255,7 @@ async def _acall_llm(
253255
model = self._get_model(system_instruction=system_instruction)
254256
options = self._get_call_params(input, message_history, tools)
255257
response = await model.generate_content_async(**options)
256-
return response
258+
return response # type: ignore[no-any-return]
257259

258260
def _call_llm(
259261
self,
@@ -265,7 +267,7 @@ def _call_llm(
265267
model = self._get_model(system_instruction=system_instruction)
266268
options = self._get_call_params(input, message_history, tools)
267269
response = model.generate_content(**options)
268-
return response
270+
return response # type: ignore[no-any-return]
269271

270272
def _to_tool_call(self, function_call: FunctionCall) -> ToolCall:
271273
return ToolCall(

tests/unit/experimental/components/test_kg_writer.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# limitations under the License.
1515
from __future__ import annotations
1616

17+
from typing import Any
1718
from unittest import mock
1819
from unittest.mock import MagicMock, Mock
1920

@@ -235,7 +236,7 @@ async def test_run(_: Mock, driver: MagicMock) -> None:
235236
},
236237
database_=None,
237238
)
238-
parameters_ = {
239+
parameters_: dict[str, Any] = {
239240
"rows": [
240241
{
241242
"type": "RELATIONSHIP",
@@ -293,7 +294,7 @@ async def test_run_is_version_below_5_23(_: Mock) -> None:
293294
},
294295
database_=None,
295296
)
296-
parameters_ = {
297+
parameters_: dict[str, Any] = {
297298
"rows": [
298299
{
299300
"type": "RELATIONSHIP",
@@ -352,7 +353,7 @@ async def test_run_is_version_5_23_or_above(_: Mock) -> None:
352353
},
353354
database_=None,
354355
)
355-
parameters_ = {
356+
parameters_: dict[str, Any] = {
356357
"rows": [
357358
{
358359
"type": "RELATIONSHIP",

tests/unit/llm/test_vertexai_llm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_vertexai_invoke_happy_path(GenerativeModelMock: MagicMock) -> None:
5050
assert response.content == "Return text"
5151
GenerativeModelMock.assert_called_once_with(
5252
model_name=model_name,
53-
system_instruction=[],
53+
system_instruction=None,
5454
)
5555
last_call = mock_model.generate_content.call_args_list[0]
5656
content = last_call.kwargs["contents"]
@@ -82,7 +82,7 @@ def test_vertexai_invoke_with_system_instruction(
8282
assert response.content == "Return text"
8383
GenerativeModelMock.assert_called_once_with(
8484
model_name=model_name,
85-
system_instruction=[system_instruction],
85+
system_instruction=system_instruction,
8686
)
8787
mock_model.generate_content.assert_called_once_with(
8888
contents=[{"text": "some text"}]
@@ -116,7 +116,7 @@ def test_vertexai_invoke_with_message_history_and_system_instruction(
116116
assert response.content == "Return text"
117117
GenerativeModelMock.assert_called_once_with(
118118
model_name=model_name,
119-
system_instruction=[system_instruction],
119+
system_instruction=system_instruction,
120120
)
121121
last_call = mock_model.generate_content.call_args_list[0]
122122
content = last_call.kwargs["contents"]

0 commit comments

Comments
 (0)