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
30 changes: 30 additions & 0 deletions .github/workflows/ruff-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Ruff
on: pull_request

jobs:
ruff_check:
name: Ruff check
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- name: Repo checkout
uses: actions/checkout@v7

- name: Install uv
uses: astral-sh/setup-uv@v10.2.0
with:
version: "0.12.21"
enable-cache: true

- name: Install Python
run: uv python install

- name: Install development dependencies
run: uv sync --locked --only-dev

- name: Check lint
run: uv run --locked --only-dev ruff check --output-format github .

- name: Check formatting
run: uv run --locked --only-dev ruff format --check .
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
minimum_pre_commit_version: "4.4.0"

repos:
- repo: local
hooks:
- id: ruff-check
name: Ruff lint check
entry: uv run --locked --only-dev ruff check --no-fix --force-exclude
language: unsupported
types_or: [python, pyi]
require_serial: true

- id: ruff-format
name: Ruff format check
entry: uv run --locked --only-dev ruff format --check --force-exclude
language: unsupported
types_or: [python, pyi]
require_serial: true
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ The current flow is:
7. Answer with a Hugging Face chat model.

## Setup
After cloning, run these commands.

```bash
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
uv sync --locked
uv run pre-commit install
cp .env.example .env
```

Expand All @@ -32,31 +32,31 @@ Make calls to Inference Providers
Download notes a public git repo (specified in `NOTES_REPO_CONTENTS_URL`):

```bash
python main.py sync-notes
uv run main.py sync-notes
```

Download and rebuild the vector index:

```bash
python main.py sync-notes --index
uv run main.py sync-notes --index
```

You can also index whatever markdown files are already in `notes/`:

```bash
python main.py index --reset
uv run main.py index --reset
```

## Ask From The CLI

```bash
python main.py ask "What is an Ansible inventory?" --k 3
uv run main.py ask "What is an Ansible inventory?" --k 3
```

## Run The Streamlit App

```bash
streamlit run app.py
uv run streamlit run app.py
```

The app includes:
Expand All @@ -70,7 +70,7 @@ The app includes:
## Run The FastAPI App

```bash
uvicorn api:app --reload --port 8000
uv run uvicorn api:app --reload --port 8000
```

Ask a question:
Expand Down
36 changes: 21 additions & 15 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

from rag import (
DEFAULT_NOTES_DIR,
index_notes,
sync_notes_from_github,
answer_question,
create_embeddings,
load_vector_store,
create_llm,
answer_question,
index_notes,
load_vector_store,
sync_notes_from_github,
)

AVATARS = {
Expand All @@ -34,7 +34,9 @@ def get_rag_resources():
return vector_store, llm


enable_sidebar_controls = os.getenv("ENABLE_SIDEBAR_CONTROLS", "false").lower() == "true"
enable_sidebar_controls = (
os.getenv("ENABLE_SIDEBAR_CONTROLS", "false").lower() == "true"
)
k = int(os.getenv("DEFAULT_RETRIEVAL_K", "3"))

if enable_sidebar_controls:
Expand Down Expand Up @@ -112,10 +114,12 @@ def select_suggested_question(suggested_question):

if question:
chat_history = st.session_state.messages.copy()
st.session_state.messages.append({
"role": "user",
"content": question,
})
st.session_state.messages.append(
{
"role": "user",
"content": question,
}
)

with st.chat_message("user", avatar=AVATARS["user"]):
st.markdown(question)
Expand All @@ -142,9 +146,11 @@ def select_suggested_question(suggested_question):
st.text(f"Search query: {retrieval_query}")
st.markdown(doc.page_content)

st.session_state.messages.append({
"role": "assistant",
"content": answer,
"sources": docs,
"retrieval_query": retrieval_query,
})
st.session_state.messages.append(
{
"role": "assistant",
"content": answer,
"sources": docs,
"retrieval_query": retrieval_query,
}
)
3 changes: 1 addition & 2 deletions deploy/huggingface/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import tempfile
from pathlib import Path


SCRIPT_DIR = Path(__file__).resolve().parent
REPO_ROOT = SCRIPT_DIR.parents[1]

Expand Down Expand Up @@ -54,7 +53,7 @@ def git_auth_env(target_dir):
askpass_path = target_dir / ".git" / "hf-askpass.sh"
askpass_path.write_text(
"#!/bin/sh\n"
"case \"$1\" in\n"
'case "$1" in\n'
"*Username*) printf '%s\\n' \"$HF_DEPLOY_USERNAME\" ;;\n"
"*) printf '%s\\n' \"$HF_DEPLOY_TOKEN\" ;;\n"
"esac\n",
Expand Down
20 changes: 13 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
import argparse

from rag import (
index_notes,
sync_notes_from_github,
answer_question,
create_embeddings,
load_vector_store,
create_llm,
answer_question,
index_notes,
load_vector_store,
sync_notes_from_github,
)

if __name__ == "__main__":
Expand All @@ -27,11 +27,17 @@

index_parser = subparsers.add_parser("index")
index_parser.add_argument("--notes-dir", default="notes")
index_parser.add_argument("--reset", action="store_true", help="Reset the index by deleting existing vector store for the collection")
index_parser.add_argument(
"--reset",
action="store_true",
help="Reset the index by deleting existing vector store for the collection",
)

sync_parser = subparsers.add_parser("sync-notes")
sync_parser.add_argument("--notes-dir", default="notes")
sync_parser.add_argument("--index", action="store_true", help="Rebuild the index after syncing notes")
sync_parser.add_argument(
"--index", action="store_true", help="Rebuild the index after syncing notes"
)

ask_parser = subparsers.add_parser("ask")
ask_parser.add_argument("question")
Expand Down Expand Up @@ -66,4 +72,4 @@
start = doc.metadata.get("start", "?")
end = doc.metadata.get("end", "?")
print(f"[{i}] {source} chunk {chunk_id}")
print(f"Content:\n{doc.page_content[:200]}\n{'-'*40}")
print(f"Content:\n{doc.page_content[:200]}\n{'-' * 40}")
37 changes: 37 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[project]
name = "notes-chat"
version = "0.1.0"
description = "Notes Chat: Chat with your notes"
readme = "README.md"
authors = [
{ name = "Diaa J", email = "ditek@users.noreply.github.com" }
]
requires-python = ">=3.10"
dependencies = [
"chromadb>=0.5",
"fastapi>=0.115",
"huggingface-hub>=0.27",
"langchain>=0.3",
"langchain-chroma>=0.2",
"langchain-huggingface>=0.2",
"langchain-text-splitters>=0.3",
"python-dotenv>=1.0",
"requests>=2.32",
"streamlit>=1.64.0",
"uvicorn[standard]>=0.30",
]

[dependency-groups]
dev = [
"pre-commit>=4.4",
"ruff>=0.16.10",
]

[tool.ruff]
target-version = "py310"
line-length = 88
extend-exclude = ["*.ipynb"]

[tool.ruff.lint]
select = ["E4", "E7", "E9", "F", "I"]

Loading
Loading