Skip to content

Commit ff2ed5f

Browse files
committed
chore: lint
1 parent 8e2626a commit ff2ed5f

File tree

6 files changed

+16
-19
lines changed

6 files changed

+16
-19
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
format:
2-
poetry run black --target-version py39 .
2+
poetry run black --target-version py39 -l 88 .
33
poetry run ruff --select I --fix .
44

55
PYTHON_FILES=.
66
lint: PYTHON_FILES=.
77
lint_diff: PYTHON_FILES=$(shell git diff --name-only --diff-filter=d main | grep -E '\.py$$')
88

99
lint lint_diff:
10-
poetry run black --target-version py39 $(PYTHON_FILES) --check
10+
poetry run black --target-version py39 -l 88 $(PYTHON_FILES) --check
1111
poetry run ruff .
1212
poetry run mypy $(PYTHON_FILES)
1313

semantic_router/splitters/base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Optional
1+
from typing import List
22

33
from colorama import Fore, Style
44
from pydantic.v1 import BaseModel, Extra
@@ -10,7 +10,6 @@
1010
class BaseSplitter(BaseModel):
1111
name: str
1212
encoder: BaseEncoder
13-
score_threshold: Optional[float]
1413

1514
class Config:
1615
extra = Extra.allow

semantic_router/splitters/consecutive_sim.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ def __init__(
1919
name: str = "consecutive_similarity_splitter",
2020
score_threshold: float = 0.45,
2121
):
22-
super().__init__(name=name, score_threshold=score_threshold, encoder=encoder)
22+
super().__init__(name=name, encoder=encoder)
2323
encoder.score_threshold = score_threshold
24+
self.score_threshold = score_threshold
2425

2526
def __call__(self, docs: List[Any]):
2627
# Check if there's only a single document

semantic_router/splitters/cumulative_sim.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99

1010
class CumulativeSimSplitter(BaseSplitter):
11-
1211
"""
13-
Called "cumulative sim" because we check the similarities of the embeddings of cumulative concatenated documents with the next document.
12+
Called "cumulative sim" because we check the similarities of the
13+
embeddings of cumulative concatenated documents with the next document.
1414
"""
1515

1616
def __init__(
@@ -19,26 +19,30 @@ def __init__(
1919
name: str = "cumulative_similarity_splitter",
2020
score_threshold: float = 0.45,
2121
):
22-
super().__init__(name=name, score_threshold=score_threshold, encoder=encoder)
22+
super().__init__(name=name, encoder=encoder)
2323
encoder.score_threshold = score_threshold
24+
self.score_threshold = score_threshold
2425

2526
def __call__(self, docs: List[str]):
2627
total_docs = len(docs)
2728
# Check if there's only a single document
2829
if total_docs == 1:
2930
raise ValueError(
30-
"There is only one document provided; at least two are required to determine topics based on similarity."
31+
"There is only one document provided; at least two are required "
32+
"to determine topics based on similarity."
3133
)
3234
splits = []
3335
curr_split_start_idx = 0
3436

3537
for idx in range(0, total_docs):
3638
if idx + 1 < total_docs: # Ensure there is a next document to compare with.
3739
if idx == 0:
38-
# On the first iteration, compare the first document directly to the second.
40+
# On the first iteration, compare the
41+
# first document directly to the second.
3942
curr_split_docs = docs[idx]
4043
else:
41-
# For subsequent iterations, compare cumulative documents up to the current one with the next.
44+
# For subsequent iterations, compare cumulative
45+
# documents up to the current one with the next.
4246
curr_split_docs = "\n".join(docs[curr_split_start_idx : idx + 1])
4347
next_doc = docs[idx + 1]
4448

semantic_router/splitters/rolling_window.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from semantic_router.utils.logger import logger
1010

1111

12-
1312
class RollingWindowSplitter(BaseSplitter):
1413
def __init__(
1514
self,
@@ -20,7 +19,7 @@ def __init__(
2019
max_split_tokens=300,
2120
split_tokens_tolerance=10,
2221
plot_splits=False,
23-
name = "rolling_window_splitter",
22+
name="rolling_window_splitter",
2423
):
2524
super().__init__(name=name, encoder=encoder)
2625
self.calculated_threshold: float

semantic_router/splitters/utils.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
from typing import List
2-
31
import regex
42
import tiktoken
5-
from colorama import Fore, Style
6-
7-
from semantic_router.schema import DocumentSplit
83

94

105
def split_to_sentences(text: str) -> list[str]:
@@ -66,4 +61,3 @@ def tiktoken_length(text: str) -> int:
6661
tokenizer = tiktoken.get_encoding("cl100k_base")
6762
tokens = tokenizer.encode(text, disallowed_special=())
6863
return len(tokens)
69-

0 commit comments

Comments
 (0)