Skip to content

Commit 8895270

Browse files
authored
fix: resolve ruff 0.15.0 lint violations (#178)
* fix: resolve ruff 0.15.0 lint violations * chore: add onnxruntime dependency for Python 3.10 compatibility
1 parent 2069f8d commit 8895270

5 files changed

Lines changed: 14 additions & 11 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ dependencies = [
2020
# Sentence and chunk splitting:
2121
"markdown-it-py (>=3.0.0)",
2222
"numpy (>=1.26.4,<2.0.0)",
23+
"onnxruntime (<1.24.0); python_version < '3.11'", # 1.24+ drops Python 3.10 support
2324
"scipy (>=1.11.2,!=1.15.0.*,!=1.15.1,!=1.15.2)",
2425
"wtpsplit-lite (>=0.1.0)",
2526
# Large Language Models:

src/raglite/_chainlit.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
from pathlib import Path
5+
from typing import TYPE_CHECKING
56

67
import chainlit as cl
78
from chainlit.input_widget import Switch, TextInput
@@ -16,6 +17,9 @@
1617
)
1718
from raglite._markdown import document_to_markdown
1819

20+
if TYPE_CHECKING:
21+
from raglite._database import ChunkSpan
22+
1923
async_insert_documents = cl.make_async(insert_documents)
2024
async_hybrid_search = cl.make_async(hybrid_search)
2125
async_rerank_chunks = cl.make_async(rerank_chunks)
@@ -91,12 +95,10 @@ async def handle_message(user_message: cl.Message) -> None:
9195
).strip()
9296
# Stream the LLM response.
9397
assistant_message = cl.Message(content="")
94-
chunk_spans = []
98+
chunk_spans: list[ChunkSpan] = []
9599
messages: list[dict[str, str]] = cl.chat_context.to_openai()[:-1] # type: ignore[no-untyped-call]
96100
messages.append({"role": "user", "content": user_prompt})
97-
async for token in async_rag(
98-
messages, on_retrieval=lambda x: chunk_spans.extend(x), config=config
99-
):
101+
async for token in async_rag(messages, on_retrieval=chunk_spans.extend, config=config):
100102
await assistant_message.stream_token(token)
101103
# Append RAG sources, if any.
102104
if chunk_spans:

src/raglite/_database.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def to_xml(self, index: int | None = None) -> str:
349349
xml_document = "\n".join(
350350
[
351351
f'<document{index_attribute} id="{self.document.id}">',
352-
f"<source>{self.document.url if self.document.url else self.document.filename}</source>",
352+
f"<source>{self.document.url or self.document.filename}</source>",
353353
f'<span from_chunk_id="{self.chunks[0].id}" to_chunk_id="{self.chunks[-1].id}">',
354354
f"<headings>\n{escape(self.chunks[0].headings.strip())}\n</headings>",
355355
f"<content>\n{escape(''.join(chunk.body for chunk in self.chunks).strip())}\n</content>",
@@ -372,7 +372,7 @@ def to_json(self, index: int | None = None) -> str:
372372
json_document = {
373373
**index_attribute,
374374
"id": self.document.id,
375-
"source": self.document.url if self.document.url else self.document.filename,
375+
"source": self.document.url or self.document.filename,
376376
"span": {
377377
"from_chunk_id": self.chunks[0].id,
378378
"to_chunk_id": self.chunks[-1].id,

src/raglite/_split_chunklets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def split_chunklets(
129129
if not use_optimized:
130130
# Fall back to default lambdas if only one is provided.
131131
boundary_cost = boundary_cost or (lambda p: (1.0 - p[0]) + np.sum(p[1:]))
132-
statement_cost = statement_cost or (lambda s: ((s - 3) ** 2 / np.sqrt(max(s, 1e-6)) / 2))
132+
statement_cost = statement_cost or (lambda s: (s - 3) ** 2 / np.sqrt(max(s, 1e-6)) / 2)
133133
else:
134134
prefix_boundary = np.concatenate(([0.0], np.cumsum(boundary_probas)), dtype=np.float64)
135135
prefix_statements = np.concatenate(([0.0], np.cumsum(num_statements_arr)), dtype=np.float64)

tests/test_rag.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ def test_rag_auto_with_retrieval(raglite_test_config: RAGLiteConfig) -> None:
3232
# Answer a question that requires RAG.
3333
user_prompt = "How does Einstein define 'simultaneous events' in his special relativity paper?"
3434
messages = [{"role": "user", "content": user_prompt}]
35-
chunk_spans = []
36-
stream = rag(messages, on_retrieval=lambda x: chunk_spans.extend(x), config=raglite_test_config)
35+
chunk_spans: list[ChunkSpan] = []
36+
stream = rag(messages, on_retrieval=chunk_spans.extend, config=raglite_test_config)
3737
answer = ""
3838
for update in stream:
3939
assert isinstance(update, str)
@@ -52,8 +52,8 @@ def test_rag_auto_without_retrieval(raglite_test_config: RAGLiteConfig) -> None:
5252
# Answer a question that does not require RAG.
5353
user_prompt = "Is 7 a prime number?"
5454
messages = [{"role": "user", "content": user_prompt}]
55-
chunk_spans = []
56-
stream = rag(messages, on_retrieval=lambda x: chunk_spans.extend(x), config=raglite_test_config)
55+
chunk_spans: list[ChunkSpan] = []
56+
stream = rag(messages, on_retrieval=chunk_spans.extend, config=raglite_test_config)
5757
answer = ""
5858
for update in stream:
5959
assert isinstance(update, str)

0 commit comments

Comments
 (0)