Skip to content

Commit 06d27bf

Browse files
committed
fix format
1 parent b510f38 commit 06d27bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+345
-250
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ jobs:
3333
with:
3434
python-version: 3.x # Update with desired Python version
3535

36+
- uses: datadog/action-py-black-formatter@v2.1
37+
with:
38+
check_mode: "true"
39+
3640
- uses: astral-sh/ruff-action@v3
3741
with:
3842
src: >-

graphrag_sdk/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@
3737
"Relation",
3838
"Attribute",
3939
"AttributeType",
40-
]
40+
]

graphrag_sdk/agents/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from .agent import Agent
22

3-
__all__ = ['Agent']
3+
__all__ = ["Agent"]

graphrag_sdk/agents/agent.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from abc import ABC, abstractmethod
22

3+
34
class AgentResponseCode:
45
"""
56
Represents the response codes for an agent.

graphrag_sdk/agents/kg_agent.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from graphrag_sdk.kg import KnowledgeGraph
22
from .agent import Agent
33

4+
45
class KGAgent(Agent):
56
"""Represents an Agent for a FalkorDB Knowledge Graph.
67
@@ -134,7 +135,7 @@ def run(self, params: dict) -> str:
134135
135136
"""
136137
output = self.chat_session.send_message(params["prompt"])
137-
return output['response']
138+
return output["response"]
138139

139140
def __repr__(self):
140141
"""

graphrag_sdk/attribute.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ def from_string(txt: str):
4141

4242

4343
class Attribute:
44-
""" Represents an attribute of an entity or relation in the ontology.
45-
46-
Args:
47-
name (str): The name of the attribute.
48-
attr_type (AttributeType): The type of the attribute.
49-
unique (bool): Whether the attribute is unique.
50-
required (bool): Whether the attribute is required.
51-
52-
Examples:
53-
>>> attr = Attribute("name", AttributeType.STRING, True, True)
54-
>>> print(attr)
55-
name: "string!*"
44+
"""Represents an attribute of an entity or relation in the ontology.
45+
46+
Args:
47+
name (str): The name of the attribute.
48+
attr_type (AttributeType): The type of the attribute.
49+
unique (bool): Whether the attribute is unique.
50+
required (bool): Whether the attribute is required.
51+
52+
Examples:
53+
>>> attr = Attribute("name", AttributeType.STRING, True, True)
54+
>>> print(attr)
55+
name: "string!*"
5656
"""
5757

5858
def __init__(

graphrag_sdk/chat_session.py

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,17 @@ class ChatSession:
2424
>>> chat_session.send_message("What is the capital of France?")
2525
"""
2626

27-
def __init__(self, model_config: KnowledgeGraphModelConfig, ontology: Ontology, graph: Graph,
28-
cypher_system_instruction: str, qa_system_instruction: str,
29-
cypher_gen_prompt: str, qa_prompt: str, cypher_gen_prompt_history: str):
27+
def __init__(
28+
self,
29+
model_config: KnowledgeGraphModelConfig,
30+
ontology: Ontology,
31+
graph: Graph,
32+
cypher_system_instruction: str,
33+
qa_system_instruction: str,
34+
cypher_gen_prompt: str,
35+
qa_prompt: str,
36+
cypher_gen_prompt_history: str,
37+
):
3038
"""
3139
Initializes a new ChatSession object.
3240
@@ -45,21 +53,22 @@ def __init__(self, model_config: KnowledgeGraphModelConfig, ontology: Ontology,
4553
self.model_config = model_config
4654
self.graph = graph
4755
self.ontology = ontology
48-
cypher_system_instruction = cypher_system_instruction.format(ontology=str(ontology.to_json()))
56+
cypher_system_instruction = cypher_system_instruction.format(
57+
ontology=str(ontology.to_json())
58+
)
4959

50-
5160
self.cypher_prompt = cypher_gen_prompt
5261
self.qa_prompt = qa_prompt
5362
self.cypher_prompt_with_history = cypher_gen_prompt_history
54-
63+
5564
self.cypher_chat_session = (
5665
model_config.cypher_generation.with_system_instruction(
5766
cypher_system_instruction
5867
).start_chat()
5968
)
6069
self.qa_chat_session = model_config.qa.with_system_instruction(
61-
qa_system_instruction
62-
).start_chat()
70+
qa_system_instruction
71+
).start_chat()
6372
self.last_answer = None
6473

6574
def send_message(self, message: str):
@@ -71,9 +80,9 @@ def send_message(self, message: str):
7180
7281
Returns:
7382
dict: The response to the message in the following format:
74-
{"question": message,
75-
"response": answer,
76-
"context": context,
83+
{"question": message,
84+
"response": answer,
85+
"context": context,
7786
"cypher": cypher}
7887
"""
7988
cypher_step = GraphQueryGenerationStep(
@@ -82,7 +91,7 @@ def send_message(self, message: str):
8291
ontology=self.ontology,
8392
last_answer=self.last_answer,
8493
cypher_prompt=self.cypher_prompt,
85-
cypher_prompt_with_history=self.cypher_prompt_with_history
94+
cypher_prompt_with_history=self.cypher_prompt_with_history,
8695
)
8796

8897
(context, cypher) = cypher_step.run(message)
@@ -92,8 +101,8 @@ def send_message(self, message: str):
92101
"question": message,
93102
"response": "I am sorry, I could not find the answer to your question",
94103
"context": None,
95-
"cypher": None
96-
}
104+
"cypher": None,
105+
}
97106

98107
qa_step = QAStep(
99108
chat_session=self.qa_chat_session,
@@ -102,10 +111,10 @@ def send_message(self, message: str):
102111

103112
answer = qa_step.run(message, cypher, context)
104113
self.last_answer = answer
105-
114+
106115
return {
107-
"question": message,
108-
"response": answer,
109-
"context": context,
110-
"cypher": cypher
111-
}
116+
"question": message,
117+
"response": answer,
118+
"context": context,
119+
"cypher": cypher,
120+
}

graphrag_sdk/document.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class Document():
1+
class Document:
22
"""
33
Common class containing text extracted from a source
44
"""

graphrag_sdk/document_loaders/jsonl.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ def load(self) -> Iterator[Document]:
1818
num_documents = num_rows // self.rows_per_document
1919
for i in range(num_documents):
2020
content = "\n".join(
21-
rows[
22-
i
23-
* self.rows_per_document : (i + 1)
24-
* self.rows_per_document
25-
]
21+
rows[i * self.rows_per_document : (i + 1) * self.rows_per_document]
2622
)
2723
yield Document(content)
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from typing import Iterator
22
from graphrag_sdk.document import Document
33

4-
class PDFLoader():
4+
5+
class PDFLoader:
56
"""
67
Load PDF
78
"""
@@ -15,11 +16,11 @@ def __init__(self, path: str) -> None:
1516
"""
1617

1718
try:
18-
__import__('pypdf')
19+
__import__("pypdf")
1920
except ModuleNotFoundError:
2021
raise ModuleNotFoundError(
2122
"pypdf package not found, please install it with " "`pip install pypdf`"
22-
)
23+
)
2324

2425
self.path = path
2526

@@ -30,11 +31,8 @@ def load(self) -> Iterator[Document]:
3031
Returns:
3132
Iterator[Document]: document iterator
3233
"""
33-
34-
from pypdf import PdfReader # pylint: disable=import-outside-toplevel
34+
35+
from pypdf import PdfReader # pylint: disable=import-outside-toplevel
3536

3637
reader = PdfReader(self.path)
37-
yield from [
38-
Document(page.extract_text())
39-
for page in reader.pages
40-
]
38+
yield from [Document(page.extract_text()) for page in reader.pages]

0 commit comments

Comments
 (0)