Skip to content

Commit 5a81f87

Browse files
More ruff formatting
1 parent fbbd2c4 commit 5a81f87

File tree

6 files changed

+49
-16
lines changed

6 files changed

+49
-16
lines changed

examples/customize/build_graph/pipeline/kg_builder_from_pdf.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
logging.basicConfig(level=logging.INFO)
4040

4141

42-
async def define_and_run_pipeline(neo4j_driver: neo4j.Driver, llm: LLMInterface) -> PipelineResult:
42+
async def define_and_run_pipeline(
43+
neo4j_driver: neo4j.Driver, llm: LLMInterface
44+
) -> PipelineResult:
4345
from neo4j_graphrag.experimental.pipeline import Pipeline
4446

4547
# Instantiate Entity and Relation objects
@@ -56,7 +58,9 @@ async def define_and_run_pipeline(neo4j_driver: neo4j.Driver, llm: LLMInterface)
5658
),
5759
]
5860
relations = [
59-
SchemaRelation(label="SITUATED_AT", description="Indicates the location of a person."),
61+
SchemaRelation(
62+
label="SITUATED_AT", description="Indicates the location of a person."
63+
),
6064
SchemaRelation(
6165
label="LED_BY",
6266
description="Indicates the leader of an organization.",
@@ -65,7 +69,9 @@ async def define_and_run_pipeline(neo4j_driver: neo4j.Driver, llm: LLMInterface)
6569
label="OWNS",
6670
description="Indicates the ownership of an item such as a Horcrux.",
6771
),
68-
SchemaRelation(label="INTERACTS", description="The interaction between two people."),
72+
SchemaRelation(
73+
label="INTERACTS", description="The interaction between two people."
74+
),
6975
]
7076
potential_schema = [
7177
("PERSON", "SITUATED_AT", "LOCATION"),
@@ -78,7 +84,8 @@ async def define_and_run_pipeline(neo4j_driver: neo4j.Driver, llm: LLMInterface)
7884
pipe = Pipeline()
7985
pipe.add_component(PdfLoader(), "pdf_loader")
8086
pipe.add_component(
81-
FixedSizeSplitter(chunk_size=4000, chunk_overlap=200, approximate=False), "splitter"
87+
FixedSizeSplitter(chunk_size=4000, chunk_overlap=200, approximate=False),
88+
"splitter",
8289
)
8390
pipe.add_component(SchemaBuilder(), "schema")
8491
pipe.add_component(
@@ -126,7 +133,9 @@ async def main() -> PipelineResult:
126133
"response_format": {"type": "json_object"},
127134
},
128135
)
129-
driver = neo4j.GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "password"))
136+
driver = neo4j.GraphDatabase.driver(
137+
"bolt://localhost:7687", auth=("neo4j", "password")
138+
)
130139
res = await define_and_run_pipeline(driver, llm)
131140
driver.close()
132141
await llm.async_client.close()

examples/customize/build_graph/pipeline/kg_builder_from_text.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
import neo4j
4040

4141

42-
async def define_and_run_pipeline(neo4j_driver: neo4j.Driver, llm: LLMInterface) -> PipelineResult:
42+
async def define_and_run_pipeline(
43+
neo4j_driver: neo4j.Driver, llm: LLMInterface
44+
) -> PipelineResult:
4345
"""This is where we define and run the KG builder pipeline, instantiating a few
4446
components:
4547
- Text Splitter: in this example we use the fixed size text splitter
@@ -74,7 +76,9 @@ async def define_and_run_pipeline(neo4j_driver: neo4j.Driver, llm: LLMInterface)
7476
# and how the output of previous components must be used
7577
pipe.connect("splitter", "chunk_embedder", input_config={"text_chunks": "splitter"})
7678
pipe.connect("schema", "extractor", input_config={"schema": "schema"})
77-
pipe.connect("chunk_embedder", "extractor", input_config={"chunks": "chunk_embedder"})
79+
pipe.connect(
80+
"chunk_embedder", "extractor", input_config={"chunks": "chunk_embedder"}
81+
)
7882
pipe.connect(
7983
"extractor",
8084
"writer",
@@ -145,7 +149,9 @@ async def main() -> PipelineResult:
145149
"response_format": {"type": "json_object"},
146150
},
147151
)
148-
driver = neo4j.GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "password"))
152+
driver = neo4j.GraphDatabase.driver(
153+
"bolt://localhost:7687", auth=("neo4j", "password")
154+
)
149155
res = await define_and_run_pipeline(driver, llm)
150156
driver.close()
151157
await llm.async_client.close()

examples/customize/build_graph/pipeline/lexical_graph_builder_from_text.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,7 @@ async def main(neo4j_driver: neo4j.Driver) -> PipelineResult:
7979

8080

8181
if __name__ == "__main__":
82-
with neo4j.GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "password")) as driver:
82+
with neo4j.GraphDatabase.driver(
83+
"bolt://localhost:7687", auth=("neo4j", "password")
84+
) as driver:
8385
print(asyncio.run(main(driver)))

examples/customize/build_graph/pipeline/text_to_lexical_graph_to_entity_graph_single_pipeline.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ async def define_and_run_pipeline(
9393
)
9494
# define the execution order of component
9595
# and how the output of previous components must be used
96-
pipe.connect("chunk_embedder", "extractor", input_config={"chunks": "chunk_embedder"})
96+
pipe.connect(
97+
"chunk_embedder", "extractor", input_config={"chunks": "chunk_embedder"}
98+
)
9799
pipe.connect("schema", "extractor", input_config={"schema": "schema"})
98100
pipe.connect(
99101
"extractor",
@@ -188,5 +190,7 @@ async def main(driver: neo4j.Driver) -> PipelineResult:
188190

189191

190192
if __name__ == "__main__":
191-
with neo4j.GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "password")) as driver:
193+
with neo4j.GraphDatabase.driver(
194+
"bolt://localhost:7687", auth=("neo4j", "password")
195+
) as driver:
192196
print(asyncio.run(main(driver)))

examples/customize/build_graph/pipeline/text_to_lexical_graph_to_entity_graph_two_pipelines.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,15 @@ async def main(driver: neo4j.Driver) -> PipelineResult:
201201
},
202202
)
203203
await build_lexical_graph(driver, lexical_graph_config, text=text)
204-
res = await read_chunk_and_perform_entity_extraction(driver, llm, lexical_graph_config)
204+
res = await read_chunk_and_perform_entity_extraction(
205+
driver, llm, lexical_graph_config
206+
)
205207
await llm.async_client.close()
206208
return res
207209

208210

209211
if __name__ == "__main__":
210-
with neo4j.GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "password")) as driver:
212+
with neo4j.GraphDatabase.driver(
213+
"bolt://localhost:7687", auth=("neo4j", "password")
214+
) as driver:
211215
print(asyncio.run(main(driver)))

tests/unit/experimental/components/text_splitters/test_fixed_size_splitter.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ def test_invalid_chunk_size() -> None:
103103
("Hello World", 0, 0),
104104
],
105105
)
106-
def test_adjust_chunk_start(text: str, approximate_start: int, expected_start: int) -> None:
106+
def test_adjust_chunk_start(
107+
text: str, approximate_start: int, expected_start: int
108+
) -> None:
107109
"""
108110
Test that the _adjust_chunk_start function correctly shifts
109111
the start index to avoid breaking words, unless no whitespace is found.
@@ -127,7 +129,9 @@ def test_adjust_chunk_start(text: str, approximate_start: int, expected_start: i
127129
("Hello World", 6, 15, 15),
128130
],
129131
)
130-
def test_adjust_chunk_end(text: str, start: int, approximate_end: int, expected_end: int) -> None:
132+
def test_adjust_chunk_end(
133+
text: str, start: int, approximate_end: int, expected_end: int
134+
) -> None:
131135
"""
132136
Test that the _adjust_chunk_end function correctly shifts
133137
the end index to avoid breaking words, unless no whitespace is found.
@@ -183,7 +187,11 @@ def test_adjust_chunk_end(text: str, start: int, approximate_end: int, expected_
183187
],
184188
)
185189
async def test_fixed_size_splitter_run(
186-
text: str, chunk_size: int, chunk_overlap: int, approximate: bool, expected_chunks: list[str]
190+
text: str,
191+
chunk_size: int,
192+
chunk_overlap: int,
193+
approximate: bool,
194+
expected_chunks: list[str],
187195
) -> None:
188196
"""
189197
Test that 'FixedSizeSplitter.run' returns the expected chunks

0 commit comments

Comments
 (0)