Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 33 additions & 0 deletions .github/actions/setup-uv/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: 'Setup uv'
description: 'Setup uv with Python and install dependencies'
inputs:
python-version:
description: 'Python version to use'
required: false
default: '3.12'
install-dev:
description: 'Install dev dependencies'
required: false
default: 'true'

runs:
using: 'composite'
steps:
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
cache-dependency-glob: "uv.lock"

- name: Set up Python
run: uv python install ${{ inputs.python-version }}
shell: bash

- name: Install dependencies
run: |
if [ "${{ inputs.install-dev }}" = "true" ]; then
uv sync --all-extras --dev
else
uv sync --all-extras
fi
shell: bash
26 changes: 26 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Lint

on:
push:
branches: [ "*" ]
workflow_dispatch:

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup uv
uses: ./.github/actions/setup-uv
with:
python-version: '3.12'
install-dev: 'true'

- name: Run ruff check
run: uv run ruff check .

- name: Run ruff format check
run: uv run ruff format --check .
35 changes: 35 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Test

on:
pull_request:
branches: [ "main", "dev" ]
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.12']

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup uv
uses: ./.github/actions/setup-uv
with:
python-version: ${{ matrix.python-version }}
install-dev: 'true'

- name: Run tests
run: uv run pytest -v --cov=rocketrag --cov-report=term-missing

- name: Run type checking (if available)
run: |
if uv run python -c "import mypy" 2>/dev/null; then
uv run mypy rocketrag
else
echo "Type checker not available, skipping"
fi
continue-on-error: true
8 changes: 4 additions & 4 deletions rocketrag/rocketrag.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def __init__(
self.metadata,
)

self.rag = RAG(self.db, self.llm)

def prepare(self, recreate: bool = False):
if self.loader is None:
raise ValueError("Loader is not defined.")
Expand All @@ -100,13 +102,11 @@ def stream_llm(self, messages: list[dict]) -> str:
@ensure_llm_loaded
def ask(self, question: str) -> tuple[str, list[SearchResult]]:
# TODO: Should print the error on vectorizer mismach
rag = RAG(self.db, self.llm)
stream, sources = rag.run(question)
stream, sources = self.rag.run(question)
return stream, sources

@ensure_llm_loaded
def stream_ask(self, question: str) -> tuple[str, list[SearchResult]]:
# TODO: Should print the error on vectorizer mismach
rag = RAG(self.db, self.llm)
stream, sources = rag.stream(question)
stream, sources = self.rag.stream(question)
return stream, sources
3 changes: 3 additions & 0 deletions rocketrag/vectors.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os

os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
from sentence_transformers import SentenceTransformer
from .base import BaseVectorizer

Expand Down
15 changes: 11 additions & 4 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,18 @@ def test_stream_ask_question(self, integration_rocketrag):

# Ask a question using streaming
question = "What are the main topics covered?"
response, sources = integration_rocketrag.stream_ask(question)
stream, sources = integration_rocketrag.stream_ask(question)

# Consume the stream to get the complete response
full_response = ""
for output in stream:
delta = output["choices"][0]["delta"]
if "content" in delta:
full_response += delta["content"]

# Verify response (streaming should still return complete response)
assert isinstance(response, str)
assert len(response) > 0
assert isinstance(full_response, str)
assert len(full_response) > 0

# Verify sources
assert isinstance(sources, list)
Expand Down Expand Up @@ -204,7 +211,7 @@ def test_recreate_database(self, integration_rocketrag):
"""Test recreating the database."""
# Prepare the database
integration_rocketrag.prepare()
initial_count = integration_rocketrag.db.count_records()
initial_count = integration_rocketrag.db.get_total_count()
assert initial_count > 0

# Recreate the database
Expand Down
Loading