Skip to content

Commit

Permalink
chore: ruff CI (should fail) (AnswerDotAI#42)
Browse files Browse the repository at this point in the history
chore: ruff CI (should pass)

chore: use action for format

chore: better ruff format

chore: import linting too, move ruff to pyproject
  • Loading branch information
bclavie authored Jan 13, 2024
1 parent d71bcdc commit 2e5060e
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 80 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Ruff
on: pull_request
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: "Linting & Flaking"
uses: chartboost/ruff-action@v1
- name: "Formatting"
uses: chartboost/ruff-action@v1
with:
args: format --check
52 changes: 0 additions & 52 deletions .ruff.toml

This file was deleted.

58 changes: 58 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,61 @@ ruff = "^0.1.9"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.ruff]
# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
]

# Same as Black.
line-length = 88
output-format = "grouped"

target-version = "py39"

[tool.ruff.lint]
select = [
# bugbear rules
"B",
"I",
# remove unused imports
"F401",
# bare except statements
"E722",
# unused arguments
"ARG",
]
ignore = [
"B006",
"B018",
]

unfixable = [
"T201",
"T203",
]
ignore-init-module-imports = true

[tool.ruff.lint.isort]
section-order = ["future", "standard-library", "third-party", "first-party", "local-folder"]
10 changes: 6 additions & 4 deletions ragatouille/RAGPretrainedModel.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from typing import Callable, Optional, Union, Any
from pathlib import Path
from langchain_core.retrievers import BaseRetriever
from typing import Any, Callable, Optional, Union

from langchain.retrievers.document_compressors.base import BaseDocumentCompressor
from langchain_core.retrievers import BaseRetriever

from ragatouille.data.corpus_processor import CorpusProcessor
from ragatouille.data.preprocessors import llama_index_sentence_splitter
from ragatouille.models import LateInteractionModel, ColBERT
from ragatouille.integrations import (
RAGatouilleLangChainRetriever,
RAGatouilleLangChainCompressor,
RAGatouilleLangChainRetriever,
)
from ragatouille.models import ColBERT, LateInteractionModel


class RAGPretrainedModel:
Expand Down
6 changes: 3 additions & 3 deletions ragatouille/RAGTrainer.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from pathlib import Path
from typing import Union, Literal, Optional
from typing import Literal, Optional, Union

from colbert.infra import ColBERTConfig

from ragatouille.models import LateInteractionModel, ColBERT
from ragatouille.data import TrainingDataProcessor
from ragatouille.models import ColBERT, LateInteractionModel
from ragatouille.negative_miners import HardNegativeMiner, SimpleMiner
from ragatouille.utils import seeded_shuffle
from ragatouille.data import TrainingDataProcessor


class RAGTrainer:
Expand Down
2 changes: 1 addition & 1 deletion ragatouille/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
__all__ = [
"TrainingDataProcessor",
"CorpusProcessor",
"llama_index_sentence_splitter"
"llama_index_sentence_splitter",
]
1 change: 1 addition & 0 deletions ragatouille/data/corpus_processor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Callable, Optional, Union

from ragatouille.data.preprocessors import llama_index_sentence_splitter


Expand Down
3 changes: 2 additions & 1 deletion ragatouille/data/training_data_processor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
import random
from collections import defaultdict
from pathlib import Path
from typing import Literal, Union
import random

import srsly


Expand Down
2 changes: 1 addition & 1 deletion ragatouille/integrations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ragatouille.integrations._langchain import (
RAGatouilleLangChainRetriever,
RAGatouilleLangChainCompressor,
RAGatouilleLangChainRetriever,
)

__all__ = ["RAGatouilleLangChainRetriever", "RAGatouilleLangChainCompressor"]
9 changes: 5 additions & 4 deletions ragatouille/integrations/_langchain.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import Any, Optional, List, Sequence
from typing import Any, List, Optional, Sequence

from langchain.retrievers.document_compressors.base import BaseDocumentCompressor
from langchain_core.callbacks.manager import CallbackManagerForRetrieverRun, Callbacks
from langchain_core.documents import Document
from langchain_core.retrievers import BaseRetriever
from langchain.retrievers.document_compressors.base import BaseDocumentCompressor


class RAGatouilleLangChainRetriever(BaseRetriever):
Expand All @@ -13,7 +14,7 @@ def _get_relevant_documents(
self,
query: str,
*,
run_manager: CallbackManagerForRetrieverRun,
run_manager: CallbackManagerForRetrieverRun, # noqa
) -> List[Document]:
"""Get documents relevant to a query."""
docs = self.model.search(query, **self.kwargs)
Expand All @@ -34,7 +35,7 @@ def compress_documents(
self,
documents: Sequence[Document],
query: str,
callbacks: Optional[Callbacks] = None,
callbacks: Optional[Callbacks] = None, # noqa
**kwargs,
) -> Any:
"""Rerank a list of documents relevant to a query."""
Expand Down
2 changes: 0 additions & 2 deletions ragatouille/models/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Union
from pathlib import Path
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Union
Expand Down
14 changes: 7 additions & 7 deletions ragatouille/models/colbert.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import math
from typing import Union, Optional, Literal
import os
import time
from pathlib import Path
from colbert.infra import Run, ColBERTConfig, RunConfig
from colbert import Indexer, Searcher, Trainer, IndexUpdater
from colbert.modeling.checkpoint import Checkpoint
import torch
import srsly
from typing import Literal, Optional, Union

import numpy as np
import srsly
import torch
from colbert import Indexer, IndexUpdater, Searcher, Trainer
from colbert.infra import ColBERTConfig, Run, RunConfig
from colbert.modeling.checkpoint import Checkpoint

from ragatouille.models.base import LateInteractionModel

Expand Down
2 changes: 1 addition & 1 deletion ragatouille/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from colbert.modeling.colbert import ColBERT
from huggingface_hub import HfApi
from huggingface_hub.utils import HfHubHTTPError
from transformers import BertPreTrainedModel, AutoModel
from transformers import AutoModel, BertPreTrainedModel


def seeded_shuffle(collection: list, seed: int = 42):
Expand Down
7 changes: 4 additions & 3 deletions ragatouille/negative_miners/simpleminer.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from enum import Enum
from pathlib import Path
from typing import Literal, Union, Optional
from sentence_transformers import SentenceTransformer
from typing import Literal, Optional, Union

import torch
from voyager import Index, Space, StorageDataType
from sentence_transformers import SentenceTransformer
from tqdm import tqdm
from voyager import Index, Space, StorageDataType

from .base import HardNegativeMiner

Expand Down
1 change: 1 addition & 0 deletions ragatouille/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import random

import requests


Expand Down
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# TODO
# Tests in v0.0.2
# Tests in v0.0.2

0 comments on commit 2e5060e

Please sign in to comment.