Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Lint to CI (Ruff & Black) #63

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ jobs:
with:
python-version: 3.x # Update with desired Python version

- uses: astral-sh/ruff-action@v3
with:
src: >-
"./graphrag_sdk"

- name: Cache Poetry virtualenv
id: cache
uses: actions/cache@v4
Expand Down
2 changes: 0 additions & 2 deletions graphrag_sdk/agents/agent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from abc import ABC, abstractmethod
from graphrag_sdk.models.model import GenerativeModelChatSession


class AgentResponseCode:
"""
Expand Down
2 changes: 0 additions & 2 deletions graphrag_sdk/agents/kg_agent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from graphrag_sdk.kg import KnowledgeGraph
from .agent import Agent
from graphrag_sdk.models import GenerativeModelChatSession


class KGAgent(Agent):
"""Represents an Agent for a FalkorDB Knowledge Graph.
Expand Down
1 change: 0 additions & 1 deletion graphrag_sdk/attribute.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
from graphrag_sdk.fixtures.regex import *
import logging
import re

Expand Down
6 changes: 3 additions & 3 deletions graphrag_sdk/document_loaders/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def __init__(self, path: str) -> None:
"""

try:
import pypdf
except ImportError:
raise ImportError(
__import__('pypdf')
except ModuleNotFoundError:
raise ModuleNotFoundError(
"pypdf package not found, please install it with " "`pip install pypdf`"
)

Expand Down
10 changes: 5 additions & 5 deletions graphrag_sdk/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ def stringify_falkordb_response(response):
elif not isinstance(response[0], list):
data = str(response).strip()
else:
for l, _ in enumerate(response):
if not isinstance(response[l], list):
response[l] = str(response[l])
for line, _ in enumerate(response):
if not isinstance(response[line], list):
response[line] = str(response[line])
else:
for i, __ in enumerate(response[l]):
response[l][i] = str(response[l][i])
for i, __ in enumerate(response[line]):
response[line][i] = str(response[line][i])
data = str(response).strip()

return data
Expand Down
2 changes: 1 addition & 1 deletion graphrag_sdk/models/litellm.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def check_valid_key(self, model: str):
model=model, messages=messages, max_tokens=10
)
return True
except:
except: # noqa: E722
return False

def check_and_pull_model(self) -> None:
Expand Down
1 change: 0 additions & 1 deletion graphrag_sdk/orchestrator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from .orchestrator import Orchestrator
from .orchestrator_runner import OrchestratorRunner
from .execution_plan import ExecutionPlan
from .step import StepResult, PlanStep, StepBlockType

__all__ = [
'Orchestrator',
Expand Down
2 changes: 1 addition & 1 deletion graphrag_sdk/orchestrator/execution_plan.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from json import loads
from graphrag_sdk.orchestrator.step import PlanStep, StepBlockType
from graphrag_sdk.orchestrator.step import PlanStep


class ExecutionPlan:
Expand Down
1 change: 0 additions & 1 deletion graphrag_sdk/orchestrator/orchestrator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from graphrag_sdk.agents import Agent
from graphrag_sdk.models import GenerativeModel
from graphrag_sdk.models.model import OutputMethod
from .orchestrator_runner import OrchestratorRunner
from graphrag_sdk.fixtures.prompts import (
ORCHESTRATOR_SYSTEM,
Expand Down
9 changes: 5 additions & 4 deletions graphrag_sdk/orchestrator/steps/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from concurrent.futures import ThreadPoolExecutor, wait
from graphrag_sdk.orchestrator.step_result import StepResult
from graphrag_sdk.orchestrator.orchestrator_runner import OrchestratorRunner
from graphrag_sdk.orchestrator.step import PlanStep


class ParallelStepResult(StepResult):
Expand Down Expand Up @@ -34,16 +35,16 @@ def output(self) -> str:


class ParallelProperties:
steps: list["PlanStep"]
steps: list[PlanStep]

def __init__(self, steps: list["PlanStep"]):
def __init__(self, steps: list[PlanStep]):
self.steps = steps

@staticmethod
def from_json(json: dict) -> "ParallelProperties":
return ParallelProperties(
[
graphrag_sdk.orchestrator.step.PlanStep.from_json(step)
PlanStep.from_json(step)
for step in (json if isinstance(json, list) else json["steps"])
]
)
Expand All @@ -58,7 +59,7 @@ def __repr__(self) -> str:
return str(self)


class ParallelStep(graphrag_sdk.orchestrator.step.PlanStep):
class ParallelStep(PlanStep):

def __init__(self, id: str, properties: ParallelProperties):
self._id = id
Expand Down
1 change: 0 additions & 1 deletion graphrag_sdk/orchestrator/steps/summary.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import graphrag_sdk.orchestrator.step
from graphrag_sdk.orchestrator.step_result import StepResult
from concurrent.futures import ThreadPoolExecutor, wait
from graphrag_sdk.orchestrator.orchestrator_runner import OrchestratorRunner
from graphrag_sdk.fixtures.prompts import ORCHESTRATOR_SUMMARY_PROMPT

Expand Down
2 changes: 1 addition & 1 deletion graphrag_sdk/source.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Iterator
from abc import ABC, abstractmethod
from abc import ABC
from graphrag_sdk.document import Document
from graphrag_sdk.document_loaders import (
PDFLoader,
Expand Down
7 changes: 3 additions & 4 deletions graphrag_sdk/steps/create_ontology_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from threading import Lock
from typing import Optional
from graphrag_sdk.steps.Step import Step
from graphrag_sdk.document import Document
from graphrag_sdk.ontology import Ontology
from graphrag_sdk.helpers import extract_json
from ratelimit import limits, sleep_and_retry
Expand Down Expand Up @@ -138,7 +137,7 @@ def _process_source(
data = json.loads(extract_json(combined_text))
except json.decoder.JSONDecodeError as e:
logger.debug(f"Error extracting JSON: {e}")
logger.debug(f"Prompting model to fix JSON")
logger.debug("Prompting model to fix JSON")
json_fix_response = self._call_model(
self._create_chat(),
FIX_JSON_PROMPT.format(json=combined_text, error=str(e)),
Expand Down Expand Up @@ -170,7 +169,7 @@ def _process_source(
return o

def _fix_ontology(self, chat_session: GenerativeModelChatSession, o: Ontology):
logger.debug(f"Fixing ontology...")
logger.debug("Fixing ontology...")

user_message = FIX_ONTOLOGY_PROMPT.format(ontology=o)

Expand All @@ -196,7 +195,7 @@ def _fix_ontology(self, chat_session: GenerativeModelChatSession, o: Ontology):
data = json.loads(extract_json(combined_text))
except json.decoder.JSONDecodeError as e:
logger.debug(f"Error extracting JSON: {e}")
logger.debug(f"Prompting model to fix JSON")
logger.debug("Prompting model to fix JSON")
json_fix_response = self._call_model(
self._create_chat(),
FIX_JSON_PROMPT.format(json=combined_text, error=str(e)),
Expand Down
5 changes: 2 additions & 3 deletions graphrag_sdk/steps/extract_data_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from falkordb import Graph
from threading import Lock
from graphrag_sdk.steps.Step import Step
from graphrag_sdk.document import Document
from ratelimit import limits, sleep_and_retry
from graphrag_sdk.source import AbstractSource
from graphrag_sdk.models.model import OutputMethod
Expand Down Expand Up @@ -174,7 +173,7 @@ def _process_source(
data = json.loads(extract_json(last_respond))
except Exception as e:
_task_logger.debug(f"Error extracting JSON: {e}")
_task_logger.debug(f"Prompting model to fix JSON")
_task_logger.debug("Prompting model to fix JSON")
json_fix_response = self._call_model(
self._create_chat(),
FIX_JSON_PROMPT.format(json=last_respond, error=str(e)),
Expand All @@ -188,7 +187,7 @@ def _process_source(
f"Invalid data format. Missing entities or relations. {data}"
)
raise Exception(
f"Invalid data format. Missing 'entities' or 'relations' in JSON."
"Invalid data format. Missing 'entities' or 'relations' in JSON."
)
for entity in data["entities"]:
try:
Expand Down
Loading
Loading