Skip to content

Commit ad6cd8f

Browse files
committed
chore: formats cognee starter kit with ruff
1 parent ef90a99 commit ad6cd8f

File tree

4 files changed

+36
-38
lines changed

4 files changed

+36
-38
lines changed

cognee-starter-kit/src/pipelines/custom-model.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,24 @@
22
import asyncio
33
import pathlib
44
from cognee import config, add, cognify, search, SearchType, prune, visualize_graph
5+
56
# from cognee.shared.utils import render_graph
67
from cognee.low_level import DataPoint
78

9+
810
async def main():
911
data_directory_path = str(
10-
pathlib.Path(
11-
os.path.join(pathlib.Path(__file__).parent, ".data_storage")
12-
).resolve()
12+
pathlib.Path(os.path.join(pathlib.Path(__file__).parent, ".data_storage")).resolve()
1313
)
1414
# Set up the data directory. Cognee will store files here.
1515
config.data_root_directory(data_directory_path)
1616

1717
cognee_directory_path = str(
18-
pathlib.Path(
19-
os.path.join(pathlib.Path(__file__).parent, ".cognee_system")
20-
).resolve()
18+
pathlib.Path(os.path.join(pathlib.Path(__file__).parent, ".cognee_system")).resolve()
2119
)
2220
# Set up the Cognee system directory. Cognee will store system files and databases here.
2321
config.system_root_directory(cognee_directory_path)
24-
22+
2523
# Prune data and system metadata before running, only if we want "fresh" state.
2624
await prune.prune_data()
2725
await prune.prune_system(metadata=True)
@@ -31,7 +29,6 @@ async def main():
3129
# Add the text data to Cognee.
3230
await add(text)
3331

34-
3532
# Define a custom graph model for programming languages.
3633
class FieldType(DataPoint):
3734
name: str = "Field"
@@ -50,7 +47,6 @@ class ProgrammingLanguage(DataPoint):
5047
is_type: ProgrammingLanguageType
5148
metadata: dict = {"index_fields": ["name"]}
5249

53-
5450
# Cognify the text data.
5551
await cognify(graph_model=ProgrammingLanguage)
5652

@@ -67,12 +63,16 @@ class ProgrammingLanguage(DataPoint):
6763
await visualize_graph(graph_file_path)
6864

6965
# Completion query that uses graph data to form context.
70-
graph_completion = await search(query_text="What is python?", query_type=SearchType.GRAPH_COMPLETION)
66+
graph_completion = await search(
67+
query_text="What is python?", query_type=SearchType.GRAPH_COMPLETION
68+
)
7169
print("Graph completion result is:")
7270
print(graph_completion)
7371

7472
# Completion query that uses document chunks to form context.
75-
rag_completion = await search(query_text="What is Python?", query_type=SearchType.RAG_COMPLETION)
73+
rag_completion = await search(
74+
query_text="What is Python?", query_type=SearchType.RAG_COMPLETION
75+
)
7676
print("Completion result is:")
7777
print(rag_completion)
7878

cognee-starter-kit/src/pipelines/default.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@
44
from cognee import config, add, cognify, search, SearchType, prune, visualize_graph
55
# from cognee.shared.utils import render_graph
66

7+
78
async def main():
89
data_directory_path = str(
9-
pathlib.Path(
10-
os.path.join(pathlib.Path(__file__).parent, ".data_storage")
11-
).resolve()
10+
pathlib.Path(os.path.join(pathlib.Path(__file__).parent, ".data_storage")).resolve()
1211
)
1312
# Set up the data directory. Cognee will store files here.
1413
config.data_root_directory(data_directory_path)
1514

1615
cognee_directory_path = str(
17-
pathlib.Path(
18-
os.path.join(pathlib.Path(__file__).parent, ".cognee_system")
19-
).resolve()
16+
pathlib.Path(os.path.join(pathlib.Path(__file__).parent, ".cognee_system")).resolve()
2017
)
2118
# Set up the Cognee system directory. Cognee will store system files and databases here.
2219
config.system_root_directory(cognee_directory_path)
@@ -46,12 +43,16 @@ async def main():
4643
await visualize_graph(graph_file_path)
4744

4845
# Completion query that uses graph data to form context.
49-
graph_completion = await search(query_text="What is python?", query_type=SearchType.GRAPH_COMPLETION)
46+
graph_completion = await search(
47+
query_text="What is python?", query_type=SearchType.GRAPH_COMPLETION
48+
)
5049
print("Graph completion result is:")
5150
print(graph_completion)
5251

5352
# Completion query that uses document chunks to form context.
54-
rag_completion = await search(query_text="What is Python?", query_type=SearchType.RAG_COMPLETION)
53+
rag_completion = await search(
54+
query_text="What is Python?", query_type=SearchType.RAG_COMPLETION
55+
)
5556
print("Completion result is:")
5657
print(rag_completion)
5758

cognee-starter-kit/src/pipelines/low_level.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from cognee.tasks.storage.index_graph_edges import index_graph_edges
1111
from cognee.modules.users.methods import get_default_user
1212

13+
1314
class Person(DataPoint):
1415
name: str
1516
metadata: dict = {"index_fields": ["name"]}
@@ -85,7 +86,6 @@ async def main():
8586

8687
await setup()
8788

88-
8989
# Generate a random dataset_id
9090
dataset_id = uuid.uuid4()
9191
user = await get_default_user()
@@ -98,7 +98,7 @@ async def main():
9898
dataset_id,
9999
None,
100100
user,
101-
"demo_pipeline"
101+
"demo_pipeline",
102102
)
103103

104104
async for status in pipeline:

cognee/tests/test_starter_pipelines.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,11 @@ class TestPipelines(unittest.TestCase):
99

1010
def setUp(self):
1111
# Ensure we're in the correct directory
12-
self.project_root = os.path.abspath(os.path.join(
13-
os.path.dirname(__file__), '../..'
14-
))
15-
self.pipelines_dir = os.path.join(self.project_root, 'src', 'pipelines')
12+
self.project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
13+
self.pipelines_dir = os.path.join(self.project_root, "src", "pipelines")
1614

1715
# Required environment variables
18-
self.required_env_vars = [
19-
'LLM_API_KEY',
20-
'EMBEDDING_API_KEY'
21-
]
16+
self.required_env_vars = ["LLM_API_KEY", "EMBEDDING_API_KEY"]
2217

2318
# Check if required environment variables are set
2419
missing_vars = [var for var in self.required_env_vars if not os.environ.get(var)]
@@ -30,7 +25,7 @@ def _run_pipeline(self, script_name):
3025
script_path = os.path.join(self.pipelines_dir, script_name)
3126

3227
# Use the Python executable from the virtual environment
33-
python_exe = os.path.join(self.project_root, '.venv', 'bin', 'python')
28+
python_exe = os.path.join(self.project_root, ".venv", "bin", "python")
3429
if not os.path.exists(python_exe):
3530
python_exe = sys.executable
3631

@@ -40,30 +35,32 @@ def _run_pipeline(self, script_name):
4035
check=True,
4136
capture_output=True,
4237
text=True,
43-
timeout=300 # 5 minute timeout
38+
timeout=300, # 5 minute timeout
4439
)
4540
return result
4641
except subprocess.CalledProcessError as e:
47-
self.fail(f"Pipeline {script_name} failed with code {e.returncode}. "
48-
f"Stdout: {e.stdout}, Stderr: {e.stderr}")
42+
self.fail(
43+
f"Pipeline {script_name} failed with code {e.returncode}. "
44+
f"Stdout: {e.stdout}, Stderr: {e.stderr}"
45+
)
4946
except subprocess.TimeoutExpired:
5047
self.fail(f"Pipeline {script_name} timed out after 300 seconds")
5148

5249
def test_default_pipeline(self):
5350
"""Test that the default pipeline runs successfully."""
54-
result = self._run_pipeline('default.py')
51+
result = self._run_pipeline("default.py")
5552
self.assertEqual(result.returncode, 0)
5653

5754
def test_low_level_pipeline(self):
5855
"""Test that the low-level pipeline runs successfully."""
59-
result = self._run_pipeline('low_level.py')
56+
result = self._run_pipeline("low_level.py")
6057
self.assertEqual(result.returncode, 0)
6158

6259
def test_custom_model_pipeline(self):
6360
"""Test that the custom model pipeline runs successfully."""
64-
result = self._run_pipeline('custom-model.py')
61+
result = self._run_pipeline("custom-model.py")
6562
self.assertEqual(result.returncode, 0)
6663

6764

68-
if __name__ == '__main__':
69-
unittest.main()
65+
if __name__ == "__main__":
66+
unittest.main()

0 commit comments

Comments
 (0)